mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-05 06:13:55 +01:00
Allow leaving groups
This commit is contained in:
parent
eb7e2c6db9
commit
256fcb149f
4 changed files with 39 additions and 2 deletions
|
@ -6,13 +6,17 @@
|
|||
|
||||
{% block content %}
|
||||
<h1>{{ party.name }}</h1>
|
||||
<p>MJ : {{ party.game_master.get_full_name|default:party.game_master.username }}</p>
|
||||
<p>Personnages :</p>
|
||||
<ul>
|
||||
{% for character in party.characters.all %}
|
||||
<li>
|
||||
<a href="{% url "character:view" pk=character.pk %}">
|
||||
{{ character.name }}
|
||||
</a>
|
||||
{{ character.name }}</a>
|
||||
{% if character.player == user %}
|
||||
(<a href="{% url "party:leave" pk=party.pk character_pk=character.pk %}">
|
||||
Quitter</a>)
|
||||
{% endif %}
|
||||
</li>
|
||||
{% empty %}
|
||||
<li>Aucun...</li>
|
||||
|
|
17
src/party/templates/party/party_leave.html
Normal file
17
src/party/templates/party/party_leave.html
Normal file
|
@ -0,0 +1,17 @@
|
|||
{% extends "common/base.html" %}
|
||||
{% load character_extras %}
|
||||
|
||||
{% block title %}Quitter le groupe {{ party.name }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Quitter le groupe {{ party.name }}</h1>
|
||||
<form action="{% url "party:leave" pk=party.pk character_pk=character.pk %}" method=post>
|
||||
{% csrf_token %}
|
||||
<p>
|
||||
Êtes-vous certain de vouloir faire quitter le groupe {{ party.name }} à {{ character.name }} ?
|
||||
</p>
|
||||
<button class="btn btn-danger" type="submit">
|
||||
<i class="fa-solid fa-person-walking-arrow-right"></i> Quitter le groupe
|
||||
</button>
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -8,4 +8,5 @@ urlpatterns = [
|
|||
path("create/", views.party_create, name="create"),
|
||||
path("<int:pk>/", views.party_details, name="details"),
|
||||
path("<int:pk>/delete/", views.party_delete, name="delete"),
|
||||
path("<int:pk>/leave/<int:character_pk>/", views.party_leave, name="leave"),
|
||||
]
|
||||
|
|
|
@ -2,6 +2,7 @@ from django.contrib import messages
|
|||
from django.contrib.auth.decorators import login_required
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
|
||||
from character.models import Character
|
||||
from party.forms import PartyForm
|
||||
from party.models import Party
|
||||
|
||||
|
@ -48,3 +49,17 @@ def party_delete(request, pk):
|
|||
messages.success(request, f"Le groupe {name} a été supprimé.")
|
||||
return redirect("party:list")
|
||||
return render(request, "party/party_delete.html", context)
|
||||
|
||||
|
||||
@login_required
|
||||
def party_leave(request, pk, character_pk):
|
||||
party = get_object_or_404(Party.objects.managed_by(request.user), pk=pk)
|
||||
character = get_object_or_404(
|
||||
Character.objects.owned_by(request.user), pk=character_pk
|
||||
)
|
||||
context = {"party": party, "character": character}
|
||||
if request.method == "POST":
|
||||
character.parties.remove(party)
|
||||
messages.success(request, f"{character} a quitté le groupe {party}.")
|
||||
return redirect("party:list")
|
||||
return render(request, "party/party_leave.html", context)
|
||||
|
|
Loading…
Reference in a new issue