Amélioration du mécanisme de modération

Fix #236
This commit is contained in:
Jean-Marie Favreau 2024-12-05 20:52:50 +01:00
parent 37ed7c45db
commit 5a7cc080c7
6 changed files with 80 additions and 47 deletions

View File

@ -367,6 +367,9 @@ class EventModerateForm(ModelForm):
"exact_location",
"tags"
]
widgets = {
"status": RadioSelect
}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

View File

@ -1465,6 +1465,11 @@ form.messages div, form.moderation-events {
overflow-y: auto;
}
#moderate-form #id_status {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
label.required::after {
content: ' *';
color: red;

View File

@ -33,27 +33,35 @@
</p>
</header>
<form method="post" enctype="multipart/form-data">{% csrf_token %}
<form method="post" enctype="multipart/form-data" id="moderate-form">{% csrf_token %}
<div class="grid moderate-preview">
{% include "agenda_culturel/single-event/event-single-inc.html" with event=event noedit=1 %}
<div>
{% include "agenda_culturel/single-event/event-single-inc.html" with event=event onlyedit=1 %}
{% with event.get_concurrent_events as concurrent_events %}
{% if concurrent_events %}
<article>
<header>
<h2>En même temps</h2>
<p class="remarque">{% if concurrent_events|length > 1 %}Plusieurs événements se déroulent en même temps.{% else %}Un autre événement se déroule en même temps.{% endif %}</p>
</header>
<ul>
{% for e in concurrent_events %}
<li>
{{ e.category|circle_cat }} {% if e.start_time %}{{ e.start_time }}{% else %}<em>toute la journée</em>{% endif %} <a href="{{ e.get_absolute_url }}">{{ e.title }}</a>
</li>
{% endfor %}
</ul>
</article>
{% endif %}
{% endwith %}
</div>
<article>
<header>
<div class="slide-buttons">
{% with event.get_local_version as local %}
{% if local %}
{% if event != local %}
<input type="submit" value="Enregistrer et éditer la version locale" name="save_and_edit_local">
{% else %}
<input type="submit" value="Enregistrer et éditer" name="save_and_edit">
{% endif %}
{% else %}
<input type="submit" value="Enregistrer et créer une version locale" name="save_and_create_local">
{% endif %}
{% endwith %}
</div>
<h2>Modification des méta-informations</h2>
{% if event.moderated_date %}
@ -69,23 +77,13 @@
</div>
<div class="grid buttons">
{% if pred %}
<a href="{% url 'moderate_event' pred %}" role="button">🠄 Revenir au précédent</a>
<a href="{% url 'moderate_event' pred %}" class="secondary" role="button">&lt; Revenir au précédent</a>
{% else %}
<a href="{% if request.META.HTTP_REFERER %}{{ request.META.HTTP_REFERER }}{% else %}{{ object.get_absolute_url }}{% endif %}" role="button" class="secondary">Annuler</a>
{% endif %}
<input type="submit" value="Enregistrer" name="save">
{% with event.get_local_version as local %}
{% if local %}
{% if local == event %}
<input type="submit" value="Enregistrer et éditer la version locale" name="save_and_edit_local">
{% else %}
<input type="submit" value="Enregistrer et éditer" name="save_and_edit">
{% endif %}
{% else %}
<input type="submit" value="Enregistrer et créer une version locale" name="save_and_create_local">
{% endif %}
{% endwith %}
<input type="submit" value="Enregistrer et passer au suivant 🠆" name="save_and_next">
<input type="submit" value="Enregistrer et passer au suivant &gt;" name="save_and_next">
<a href="{% url 'moderate_event_next' event.pk %}" class="secondary" role="button">Passer au suivant sans enregistrer &gt;</a>
</div>
</form>
</article>

View File

@ -134,9 +134,24 @@
{% include "agenda_culturel/event-date-info-inc.html" %}
</div>
<div class="buttons">
<a href="{% url 'export_event_ical' event.start_day.year event.start_day.month event.start_day.day event.id %}" role="button">Exporter ical {% picto_from_name "calendar" %}</a>
{% if perms.agenda_culturel.change_event and not noedit %}
{% include "agenda_culturel/edit-buttons-inc.html" with event=event with_clone=1 %}
{% if onlyedit %}
{% if event.pure_import %}
{% with event.get_local_version as local %}
{% if local %}
<a href="{{ local.get_absolute_url }}" role="button">voir la version locale {% picto_from_name "eye" %}</a>
{% else %}
<a href="{% url 'clone_edit' event.id %}" role="button">créer une copie locale {% picto_from_name "plus-circle" %}</a>
{% endif %}
{% endwith %}
{% else %}
<a href="{% url 'edit_event' event.id %}" role="button">modifier {% picto_from_name "edit-3" %}</a>
{% endif %}
{% else %}
<a href="{% url 'export_event_ical' event.start_day.year event.start_day.month event.start_day.day event.id %}" role="button">Exporter ical {% picto_from_name "calendar" %}</a>
{% if perms.agenda_culturel.change_event and not noedit %}
{% include "agenda_culturel/edit-buttons-inc.html" with event=event with_clone=1 %}
{% endif %}
{% endif %}
</div>
</footer>

View File

@ -35,8 +35,8 @@ urlpatterns = [
),
path("event/<int:pk>/edit", EventUpdateView.as_view(), name="edit_event"),
path("event/<int:pk>/moderate", EventModerateView.as_view(), name="moderate_event"),
path("event/<int:pk>/moderate-next", EventModerateView.as_view(), name="moderate_event_next"),
path("event/<int:pk>/moderate-next/error", error_next_event, name="error_next_event"),
path("event/<int:pk>/moderate/after/<int:pred>", EventModerateView.as_view(), name="moderate_event_step"),
path("event/<int:pk>/moderate-next", moderate_event_next, name="moderate_event_next"),
path("moderate", EventModerateView.as_view(), name="moderate"),
path("event/<int:pk>/simple-clone/edit", EventUpdateView.as_view(), name="simple_clone_edit"),
path("event/<int:pk>/clone/edit", EventUpdateView.as_view(), name="clone_edit"),

View File

@ -356,15 +356,18 @@ class EventModerateView(
permission_required = "agenda_culturel.change_event"
template_name = "agenda_culturel/event_form_moderate.html"
form_class = EventModerateForm
success_message = _("The event has been successfully moderated.")
def get_success_message(self, cleaned_data):
return mark_safe(_('The event <a href="{}">{}</a> has been moderated with success.').format(self.object.get_absolute_url(), self.object.title))
def is_moderate_next(self):
return "moderate-next" in self.request.path.split('/')
return "after" in self.request.path.split('/')
def is_starting_moderation(self):
return not "pk" in self.kwargs
def get_next_event(self, start_day, start_time):
def get_next_event(start_day, start_time):
# select non moderated events
qs = Event.objects.filter(moderated_date__isnull=True)
@ -391,19 +394,15 @@ class EventModerateView(
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
if self.is_moderate_next():
context['pred'] = self.kwargs["pk"]
context['pred'] = self.kwargs["pred"]
return context
def get_object(self, queryset=None):
if self.is_starting_moderation():
now = datetime.now()
return self.get_next_event(now.date(), now.time())
return EventModerateView.get_next_event(now.date(), now.time())
else:
result = super().get_object(queryset)
if self.is_moderate_next():
return self.get_next_event(result.start_day, result.start_time)
else:
return result
return super().get_object(queryset)
def post(self, request, *args, **kwargs):
try:
@ -421,10 +420,6 @@ class EventModerateView(
def get_success_url(self):
if 'save_and_next' in self.request.POST:
return reverse_lazy("moderate_event_next", args=[self.object.pk])
elif 'save_and_create_local' in self.request.POST:
return reverse_lazy("clone_edit", args=[self.object.pk])
elif 'save_and_edit' in self.request.POST:
return reverse_lazy("edit_event", args=[self.object.pk])
elif 'save_and_edit_local' in self.request.POST:
return reverse_lazy("edit_event", args=[self.object.get_local_version().pk])
else:
@ -443,6 +438,23 @@ def error_next_event(request, pk):
{"pk": pk, "object": obj},
)
@login_required(login_url="/accounts/login/")
@permission_required("agenda_culturel.change_event")
def moderate_event_next(request, pk):
# current event
obj = Event.objects.filter(pk=pk).first()
start_day = obj.start_day
start_time = obj.start_time
next_obj = EventModerateView.get_next_event(start_day, start_time)
if next_obj is None:
return render(
request,
"agenda_culturel/event_next_error_message.html",
{"pk": pk, "object": obj},
)
else:
return HttpResponseRedirect(reverse_lazy("moderate_event_step", args=[next_obj.pk, obj.pk]))
class EventDeleteView(