From 46c1c7194395995e8a3d90cad7e4ab22b393988c Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Sat, 9 Dec 2023 18:11:49 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20boutons=20d'acc=C3=A8s=20rapide=20?= =?UTF-8?q?=C3=A0=20des=20pages=20d'=C3=A9dition,=20et=20on=20interdit=20l?= =?UTF-8?q?a=20suppression=20si=20l'=C3=A9v=C3=A9nement=20n'est=20pas=20en?= =?UTF-8?q?core=20en=20status=20trash=20-=20Fix=20#16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/agenda_culturel/static/style.scss | 8 ++++ .../agenda_culturel/edit-buttons-inc.html | 19 ++++++++ .../event_confirm_change_status.html | 43 +++++++++++++++++++ .../single-event/event-in-flat-list-inc.html | 6 +++ .../event-in-list-by-day-inc.html | 3 +- .../single-event/event-in-list-inc.html | 3 +- .../single-event/event-single-inc.html | 3 +- .../templatetags/event_extra.py | 2 +- src/agenda_culturel/urls.py | 1 + src/agenda_culturel/views.py | 17 ++++++++ 10 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 src/agenda_culturel/templates/agenda_culturel/edit-buttons-inc.html create mode 100644 src/agenda_culturel/templates/agenda_culturel/event_confirm_change_status.html diff --git a/src/agenda_culturel/static/style.scss b/src/agenda_culturel/static/style.scss index 868595d..8302b59 100644 --- a/src/agenda_culturel/static/style.scss +++ b/src/agenda_culturel/static/style.scss @@ -590,4 +590,12 @@ nav .badge { padding: 0.2em .8em; border-radius: 40%; +} + +form [role="button"] { + margin: 0 0 var(--spacing) 0; +} + +.large { + margin: 2em auto; } \ No newline at end of file diff --git a/src/agenda_culturel/templates/agenda_culturel/edit-buttons-inc.html b/src/agenda_culturel/templates/agenda_culturel/edit-buttons-inc.html new file mode 100644 index 0000000..a2d0b5d --- /dev/null +++ b/src/agenda_culturel/templates/agenda_culturel/edit-buttons-inc.html @@ -0,0 +1,19 @@ + +{% load utils_extra %} +éditer + +{% if event.status != "published" %} +publier {% picto_from_name "eye" %} +{% endif %} + +{% if event.status != "draft" %} +brouillon {% picto_from_name "eye-off" %} +{% endif %} + +{% if event.status != "trash" %} +corbeille {% picto_from_name "trash-2" %} +{% endif %} + +{% if event.status == "trash" %} +supprimer définitivement {% picto_from_name "x-circle" %} +{% endif %} diff --git a/src/agenda_culturel/templates/agenda_culturel/event_confirm_change_status.html b/src/agenda_culturel/templates/agenda_culturel/event_confirm_change_status.html new file mode 100644 index 0000000..59abb76 --- /dev/null +++ b/src/agenda_culturel/templates/agenda_culturel/event_confirm_change_status.html @@ -0,0 +1,43 @@ +{% extends "agenda_culturel/page.html" %} + +{% block title %} +{% if status == "published" %} +Publier l'événement {{ event.title }} +{% elif status == "draft" %} +Déplacer l'événement {{ event.title }} dans les brouillons +{% elif status == "trash" %} +Mettre l'événement {{ event.title }} à la corbeille +{% endif %} +{% endblock %} + + +{% block content %} + +

+ {% if status == "published" %} + Publier l'événement {{ event.title }} + {% elif status == "draft" %} + Déplacer l'événement {{ event.title }} dans les brouillons + {% elif status == "trash" %} + Mettre l'événement {{ event.title }} à la corbeille + {% endif %} +

+
+
{% csrf_token %} +

Êtes-vous sûr·e de vouloir + {% if status == "published" %} + publier l'événement « {{ event }} » du {{ event.start_day }} ? + {% elif status == "draft" %} + déplacer en brouillon l'événement « {{ event }} » du {{ event.start_day }} ? + {% elif status == "trash" %} + mettre à la corbeille l'événement « {{ event }} » du {{ event.start_day }} ? + {% endif %} +

+ {{ form }} +
+ Annuler + +
+
+
+{% endblock %} \ No newline at end of file diff --git a/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-flat-list-inc.html b/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-flat-list-inc.html index e00de6f..5f50a12 100644 --- a/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-flat-list-inc.html +++ b/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-flat-list-inc.html @@ -20,4 +20,10 @@

{% if event.description_hl %}{{ event.description_hl | safe }}{% else %}{% if event.description %}{{ event.description |truncatewords:60 }}{% else %}pas de description{% endif %}{% endif %} + + {% if user.is_authenticated %} +
+ {% include "agenda_culturel/edit-buttons-inc.html" with event=event %} +
+ {% endif %}
diff --git a/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-list-by-day-inc.html b/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-list-by-day-inc.html index 03bfe72..c755ae5 100644 --- a/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-list-by-day-inc.html +++ b/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-list-by-day-inc.html @@ -65,8 +65,7 @@ {% if user.is_authenticated %}
- éditer - supprimer + {% include "agenda_culturel/edit-buttons-inc.html" with event=event %} Voir l'événement diff --git a/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-list-inc.html b/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-list-inc.html index bb20d80..c811fa4 100644 --- a/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-list-inc.html +++ b/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-list-inc.html @@ -58,8 +58,7 @@
{% if user.is_authenticated %}
- éditer - supprimer + {% include "agenda_culturel/edit-buttons-inc.html" with event=event %} Voir l'événement diff --git a/src/agenda_culturel/templates/agenda_culturel/single-event/event-single-inc.html b/src/agenda_culturel/templates/agenda_culturel/single-event/event-single-inc.html index 39038f9..35b7c24 100644 --- a/src/agenda_culturel/templates/agenda_culturel/single-event/event-single-inc.html +++ b/src/agenda_culturel/templates/agenda_culturel/single-event/event-single-inc.html @@ -52,8 +52,7 @@
{% if user.is_authenticated %}
- éditer - supprimer + {% include "agenda_culturel/edit-buttons-inc.html" with event=event %}
{% endif %} diff --git a/src/agenda_culturel/templatetags/event_extra.py b/src/agenda_culturel/templatetags/event_extra.py index 375baff..66cb0d9 100644 --- a/src/agenda_culturel/templatetags/event_extra.py +++ b/src/agenda_culturel/templatetags/event_extra.py @@ -33,7 +33,7 @@ def picto_status(event): if event.is_draft(): return picto_from_name("eye-off", "Brouillon") elif event.is_trash(): - return picto_from_name("trash", "À la poubelle") + return picto_from_name("trash-2", "À la corbeille") else: return "" diff --git a/src/agenda_culturel/urls.py b/src/agenda_culturel/urls.py index 4af3082..d766a7a 100644 --- a/src/agenda_culturel/urls.py +++ b/src/agenda_culturel/urls.py @@ -20,6 +20,7 @@ urlpatterns = [ path("events/", event_list, name='view_all_events'), path("event/-", EventDetailView.as_view(), name="view_event"), path("event//edit", EventUpdateView.as_view(), name="edit_event"), + path("event//change-status/", change_status_event, name="change_status_event"), path("event//delete", EventDeleteView.as_view(), name="delete_event"), path("importer", import_from_url, name="event_import_form"), path("ajouter", EventCreateView.as_view(), name="add_event"), diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index ca1f367..f588b5b 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -235,6 +235,23 @@ class EventDetailView(UserPassesTestMixin, DetailView): def test_func(self): return self.request.user.is_authenticated or self.get_object().status != Event.STATUS.PUBLISHED +@login_required(login_url="/accounts/login/") +def change_status_event(request, pk, status): + event = get_object_or_404(Event, pk=pk) + + if request.method == 'POST': + event.status = Event.STATUS(status) + event.save(update_fields=["status"]) + + if self.request.user.is_authenticated: + return event.get_absolute_url() + else: + return reverse_lazy("home") + else: + cancel_url = request.META.get('HTTP_REFERER', '') + if cancel_url == "": + cancel_url = reverse_lazy("home") + return render(request, 'agenda_culturel/event_confirm_change_status.html', {"status": status, "event": event, "cancel_url": cancel_url}) def import_from_url(request):