Allow deleting groups

This commit is contained in:
Gabriel Augendre 2022-11-06 14:07:16 +01:00
parent 4e37472964
commit eb7e2c6db9
5 changed files with 62 additions and 3 deletions

View file

@ -1,4 +1,4 @@
{% load static django_htmx %}
{% load static django_htmx django_bootstrap5 %}
<!DOCTYPE html>
<html lang="en">
@ -22,6 +22,7 @@
<body>
{% include "common/navbar.html" %}
<div class="container">
{% bootstrap_messages %}
{% block content %}
{% endblock %}
</div>

View file

@ -11,7 +11,21 @@
<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">
{% for party in managed_parties %}
{% include "party/snippets/party_card.html" %}
<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>
<a href="{% url "party:delete" pk=party.pk %}" class="btn btn-sm btn-danger">
<i class="fa-solid fa-users-slash"></i> Supprimer
</a>
</div>
</div>
</div>
{% empty %}
<div class="col">Aucun</div>
{% endfor %}
@ -19,7 +33,19 @@
<h2 class="mt-3">Groupes dont vous êtes membre</h2>
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4 g-4">
{% for party in played_parties %}
{% include "party/snippets/party_card.html" %}
<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>
{% empty %}
<div class="col">Aucun</div>
{% endfor %}

View file

@ -0,0 +1,18 @@
{% extends "common/base.html" %}
{% load character_extras %}
{% block title %}Suppression groupe {{ party.name }}{% endblock %}
{% block content %}
<h1>Suppression groupe {{ party.name }}</h1>
<form action="{% url "party:delete" pk=party.pk %}" method=post>
{% csrf_token %}
<p>
Êtes-vous certain de vouloir supprimer le groupe {{ party.name }} ?<br>
Cette action est irréversible.
</p>
<button class="btn btn-danger" type="submit">
<i class="fa-solid fa-users-slash"></i> Supprimer le groupe
</button>
</form>
{% endblock %}

View file

@ -7,4 +7,5 @@ urlpatterns = [
path("", views.parties_list, name="list"),
path("create/", views.party_create, name="create"),
path("<int:pk>/", views.party_details, name="details"),
path("<int:pk>/delete/", views.party_delete, name="delete"),
]

View file

@ -1,3 +1,4 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.shortcuts import get_object_or_404, redirect, render
@ -35,3 +36,15 @@ def party_details(request, pk):
party = get_object_or_404(Party.objects.related_to(request.user), pk=pk)
context = {"party": party}
return render(request, "party/party_details.html", context)
@login_required
def party_delete(request, pk):
party = get_object_or_404(Party.objects.managed_by(request.user), pk=pk)
context = {"party": party}
if request.method == "POST":
name = party.name
party.delete()
messages.success(request, f"Le groupe {name} a été supprimé.")
return redirect("party:list")
return render(request, "party/party_delete.html", context)