From 3272737780fd237ca6dab5e98efd3b4d37aab270 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 6 Nov 2022 14:30:17 +0100 Subject: [PATCH] Allow editing a group --- src/party/templates/party/parties_list.html | 20 ++++++++++++------- src/party/templates/party/party_details.html | 3 +-- .../{party_create.html => party_form.html} | 8 ++++---- .../templates/party/snippets/party_card.html | 12 ----------- src/party/urls.py | 1 + src/party/views.py | 20 +++++++++++++++++-- 6 files changed, 37 insertions(+), 27 deletions(-) rename src/party/templates/party/{party_create.html => party_form.html} (50%) delete mode 100644 src/party/templates/party/snippets/party_card.html diff --git a/src/party/templates/party/parties_list.html b/src/party/templates/party/parties_list.html index 6a47463..e542be9 100644 --- a/src/party/templates/party/parties_list.html +++ b/src/party/templates/party/parties_list.html @@ -9,7 +9,7 @@ Nouveau groupe

Groupes que vous gérez

-
+
{% for party in managed_parties %}
@@ -17,12 +17,18 @@
{{ party.name }}
- - Accéder - - - Supprimer - + +
diff --git a/src/party/templates/party/party_details.html b/src/party/templates/party/party_details.html index 7a02a1e..137a610 100644 --- a/src/party/templates/party/party_details.html +++ b/src/party/templates/party/party_details.html @@ -14,8 +14,7 @@ {{ character.name }} {% if character.player == user %} - ( - Quitter) + (Quitter) {% endif %} {% empty %} diff --git a/src/party/templates/party/party_create.html b/src/party/templates/party/party_form.html similarity index 50% rename from src/party/templates/party/party_create.html rename to src/party/templates/party/party_form.html index 280ff4a..bf0e5d4 100644 --- a/src/party/templates/party/party_create.html +++ b/src/party/templates/party/party_form.html @@ -2,13 +2,13 @@ {% load django_bootstrap5 %} {% load character_extras %} -{% block title %}Créer groupe{% endblock %} +{% block title %}Gérer un groupe{% endblock %} {% block content %} -

Créer un groupe

-
+

Gérer un groupe

+ {% csrf_token %} {% bootstrap_form form %} - {% bootstrap_button type="submit" content="Créer" %} + {% bootstrap_button type="submit" content="Enregistrer" %}
{% endblock %} diff --git a/src/party/templates/party/snippets/party_card.html b/src/party/templates/party/snippets/party_card.html deleted file mode 100644 index 5db2b25..0000000 --- a/src/party/templates/party/snippets/party_card.html +++ /dev/null @@ -1,12 +0,0 @@ -
-
-
-
- {{ party.name }} -
- - Accéder - -
-
-
diff --git a/src/party/urls.py b/src/party/urls.py index a8e46aa..0247677 100644 --- a/src/party/urls.py +++ b/src/party/urls.py @@ -7,6 +7,7 @@ urlpatterns = [ path("", views.parties_list, name="list"), path("create/", views.party_create, name="create"), path("/", views.party_details, name="details"), + path("/change/", views.party_change, name="change"), path("/delete/", views.party_delete, name="delete"), path("/leave//", views.party_leave, name="leave"), ] diff --git a/src/party/views.py b/src/party/views.py index f36c462..5f05e2e 100644 --- a/src/party/views.py +++ b/src/party/views.py @@ -11,7 +11,7 @@ from party.models import Party def parties_list(request): context = { "managed_parties": Party.objects.managed_by(request.user), - "played_parties": Party.objects.played_by(request.user), + "played_parties": Party.objects.played_by(request.user).distinct(), } return render(request, "party/parties_list.html", context) @@ -29,7 +29,7 @@ def party_create(request): form.save_m2m() return redirect("party:list") context = {"form": form} - return render(request, "party/party_create.html", context) + return render(request, "party/party_form.html", context) @login_required @@ -51,6 +51,22 @@ def party_delete(request, pk): return render(request, "party/party_delete.html", context) +@login_required +def party_change(request, pk): + party = get_object_or_404(Party.objects.managed_by(request.user), pk=pk) + context = {"party": party} + if request.method == "GET": + form = PartyForm(instance=party) + else: + form = PartyForm(request.POST or None, instance=party) + if form.is_valid(): + form.save() + messages.success(request, "Groupe modifié.") + return redirect("party:list") + context["form"] = form + return render(request, "party/party_form.html", context) + + @login_required def party_leave(request, pk, character_pk): party = get_object_or_404(Party.objects.managed_by(request.user), pk=pk)