Ajout de boutons d'accès rapide à des pages d'édition, et on interdit la suppression si l'événement n'est pas encore en status trash

- Fix #16
This commit is contained in:
Jean-Marie Favreau 2023-12-09 18:11:49 +01:00
parent fbbae450ca
commit 46c1c71943
10 changed files with 98 additions and 7 deletions

View File

@ -591,3 +591,11 @@ nav .badge {
border-radius: 40%;
}
form [role="button"] {
margin: 0 0 var(--spacing) 0;
}
.large {
margin: 2em auto;
}

View File

@ -0,0 +1,19 @@
{% load utils_extra %}
<a href="{% url 'edit_event' event.id %}" role="button">éditer</a>
{% if event.status != "published" %}
<a href="{% url 'change_status_event' event.id 'published' %}" role="button">publier {% picto_from_name "eye" %}</a>
{% endif %}
{% if event.status != "draft" %}
<a href="{% url 'change_status_event' event.id 'draft' %}" role="button">brouillon {% picto_from_name "eye-off" %}</a>
{% endif %}
{% if event.status != "trash" %}
<a href="{% url 'change_status_event' event.id 'trash' %}" role="button">corbeille {% picto_from_name "trash-2" %}</a>
{% endif %}
{% if event.status == "trash" %}
<a href="{% url 'delete_event' event.id %}" role="button">supprimer définitivement {% picto_from_name "x-circle" %}</a>
{% endif %}

View File

@ -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 %}
<h1>
{% 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 %}
</h1>
<article>
<form method="post">{% csrf_token %}
<p class="large">Êtes-vous sûr·e de vouloir
{% if status == "published" %}
<strong>publier</strong> l'événement «&nbsp;{{ event }}&nbsp;» du {{ event.start_day }}&nbsp;?
{% elif status == "draft" %}
déplacer <strong>en brouillon</strong> l'événement «&nbsp;{{ event }}&nbsp;» du {{ event.start_day }}&nbsp;?
{% elif status == "trash" %}
mettre <strong>à la corbeille</strong> l'événement «&nbsp;{{ event }}&nbsp;» du {{ event.start_day }}&nbsp;?
{% endif %}
</p>
{{ form }}
<div class="grid">
<a href="{{ cancel_url }}" role="button" class="secondary">Annuler</a>
<input type="submit" value="Confirmer">
</div>
</form>
</article>
{% endblock %}

View File

@ -20,4 +20,10 @@
</p>
<div class="description">
{% if event.description_hl %}{{ event.description_hl | safe }}{% else %}{% if event.description %}{{ event.description |truncatewords:60 }}{% else %}<em>pas de description</em>{% endif %}{% endif %}
{% if user.is_authenticated %}
<div class="buttons">
{% include "agenda_culturel/edit-buttons-inc.html" with event=event %}
</div>
{% endif %}
</div>

View File

@ -65,8 +65,7 @@
</div>
{% if user.is_authenticated %}
<div class="buttons">
<a href="{% url 'edit_event' event.id %}" role="button">éditer</a>
<a href="{% url 'delete_event' event.id %}" role="button">supprimer</a>
{% include "agenda_culturel/edit-buttons-inc.html" with event=event %}
<a href="{{ event.get_absolute_url }}" role="button">Voir l'événement <svg width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<use href="{% static 'images/feather-sprite.svg' %}#chevron-right" />
</svg></a>

View File

@ -58,8 +58,7 @@
</div>
{% if user.is_authenticated %}
<div class="buttons">
<a href="{% url 'edit_event' event.id %}" role="button">éditer</a>
<a href="{% url 'delete_event' event.id %}" role="button">supprimer</a>
{% include "agenda_culturel/edit-buttons-inc.html" with event=event %}
<a href="{{ event.get_absolute_url }}" role="button">Voir l'événement <svg width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<use href="{% static 'images/feather-sprite.svg' %}#chevron-right" />
</svg></a>

View File

@ -52,8 +52,7 @@
</div>
{% if user.is_authenticated %}
<div class="buttons">
<a href="{% url 'edit_event' event.id %}" role="button">éditer</a>
<a href="{% url 'delete_event' event.id %}" role="button">supprimer</a>
{% include "agenda_culturel/edit-buttons-inc.html" with event=event %}
</div>
{% endif %}
</footer>

View File

@ -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 ""

View File

@ -20,6 +20,7 @@ urlpatterns = [
path("events/", event_list, name='view_all_events'),
path("event/<int:pk>-<extra>", EventDetailView.as_view(), name="view_event"),
path("event/<int:pk>/edit", EventUpdateView.as_view(), name="edit_event"),
path("event/<int:pk>/change-status/<status>", change_status_event, name="change_status_event"),
path("event/<int:pk>/delete", EventDeleteView.as_view(), name="delete_event"),
path("importer", import_from_url, name="event_import_form"),
path("ajouter", EventCreateView.as_view(), name="add_event"),

View File

@ -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):