Allow editing a group

This commit is contained in:
Gabriel Augendre 2022-11-06 14:30:17 +01:00
parent 256fcb149f
commit 3272737780
6 changed files with 37 additions and 27 deletions

View file

@ -9,7 +9,7 @@
<i class="fa-solid fa-user-plus"></i> Nouveau groupe <i class="fa-solid fa-user-plus"></i> Nouveau groupe
</a> </a>
<h2>Groupes que vous gérez</h2> <h2>Groupes que vous gérez</h2>
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4 g-4"> <div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-4">
{% for party in managed_parties %} {% for party in managed_parties %}
<div class="col"> <div class="col">
<div class="card"> <div class="card">
@ -17,13 +17,19 @@
<h5 class="card-title"> <h5 class="card-title">
{{ party.name }} {{ party.name }}
</h5> </h5>
<a href="{% url "party:details" pk=party.pk %}" class="btn btn-sm btn-success"> <div class="btn-group btn-group-sm">
<a href="{% url "party:details" pk=party.pk %}" class="btn btn-success">
<i class="fa-solid fa-users"></i> Accéder <i class="fa-solid fa-users"></i> Accéder
</a> </a>
<a href="{% url "party:delete" pk=party.pk %}" class="btn btn-sm btn-danger"> <a href="{% url "party:change" pk=party.pk %}" class="btn btn-secondary">
<i class="fa-solid fa-gear"></i> Modifier
</a>
<a href="{% url "party:delete" pk=party.pk %}" class="btn btn-danger">
<i class="fa-solid fa-users-slash"></i> Supprimer <i class="fa-solid fa-users-slash"></i> Supprimer
</a> </a>
</div> </div>
</div>
</div> </div>
</div> </div>
{% empty %} {% empty %}

View file

@ -14,8 +14,7 @@
<a href="{% url "character:view" pk=character.pk %}"> <a href="{% url "character:view" pk=character.pk %}">
{{ character.name }}</a> {{ character.name }}</a>
{% if character.player == user %} {% if character.player == user %}
(<a href="{% url "party:leave" pk=party.pk character_pk=character.pk %}"> (<a href="{% url "party:leave" pk=party.pk character_pk=character.pk %}">Quitter</a>)
Quitter</a>)
{% endif %} {% endif %}
</li> </li>
{% empty %} {% empty %}

View file

@ -2,13 +2,13 @@
{% load django_bootstrap5 %} {% load django_bootstrap5 %}
{% load character_extras %} {% load character_extras %}
{% block title %}Créer groupe{% endblock %} {% block title %}Gérer un groupe{% endblock %}
{% block content %} {% block content %}
<h1>Créer un groupe</h1> <h1>Gérer un groupe</h1>
<form action="{% url "party:create" %}" method="post"> <form action="" method="post">
{% csrf_token %} {% csrf_token %}
{% bootstrap_form form %} {% bootstrap_form form %}
{% bootstrap_button type="submit" content="Créer" %} {% bootstrap_button type="submit" content="Enregistrer" %}
</form> </form>
{% endblock %} {% endblock %}

View file

@ -1,12 +0,0 @@
<div class="col">
<div class="card">
<div class="card-body">
<h5 class="card-title">
{{ party.name }}
</h5>
<a href="{% url "party:details" pk=party.pk %}" class="btn btn-sm btn-success">
<i class="fa-solid fa-users"></i> Accéder
</a>
</div>
</div>
</div>

View file

@ -7,6 +7,7 @@ urlpatterns = [
path("", views.parties_list, name="list"), path("", views.parties_list, name="list"),
path("create/", views.party_create, name="create"), path("create/", views.party_create, name="create"),
path("<int:pk>/", views.party_details, name="details"), path("<int:pk>/", views.party_details, name="details"),
path("<int:pk>/change/", views.party_change, name="change"),
path("<int:pk>/delete/", views.party_delete, name="delete"), path("<int:pk>/delete/", views.party_delete, name="delete"),
path("<int:pk>/leave/<int:character_pk>/", views.party_leave, name="leave"), path("<int:pk>/leave/<int:character_pk>/", views.party_leave, name="leave"),
] ]

View file

@ -11,7 +11,7 @@ from party.models import Party
def parties_list(request): def parties_list(request):
context = { context = {
"managed_parties": Party.objects.managed_by(request.user), "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) return render(request, "party/parties_list.html", context)
@ -29,7 +29,7 @@ def party_create(request):
form.save_m2m() form.save_m2m()
return redirect("party:list") return redirect("party:list")
context = {"form": form} context = {"form": form}
return render(request, "party/party_create.html", context) return render(request, "party/party_form.html", context)
@login_required @login_required
@ -51,6 +51,22 @@ def party_delete(request, pk):
return render(request, "party/party_delete.html", context) 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 @login_required
def party_leave(request, pk, character_pk): def party_leave(request, pk, character_pk):
party = get_object_or_404(Party.objects.managed_by(request.user), pk=pk) party = get_object_or_404(Party.objects.managed_by(request.user), pk=pk)