mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-05 06:13:55 +01:00
Allow deleting groups
This commit is contained in:
parent
4e37472964
commit
eb7e2c6db9
5 changed files with 62 additions and 3 deletions
|
@ -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>
|
||||
|
|
|
@ -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 %}
|
||||
|
|
18
src/party/templates/party/party_delete.html
Normal file
18
src/party/templates/party/party_delete.html
Normal 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 %}
|
|
@ -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"),
|
||||
]
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue