From e04d94f97a1469fb1598f53b2ebf57df2e67aba5 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Sat, 21 Sep 2024 23:05:51 +0200 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20de=20l'UX=20des=20imports?= =?UTF-8?q?=20r=C3=A9currents?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/agenda_culturel/page.html | 3 +- .../templates/agenda_culturel/rimports.html | 41 ++++++++------ .../templatetags/rimports_extra.py | 33 +++++++---- src/agenda_culturel/urls.py | 6 +- src/agenda_culturel/views.py | 55 ++++++------------- 5 files changed, 67 insertions(+), 71 deletions(-) diff --git a/src/agenda_culturel/templates/agenda_culturel/page.html b/src/agenda_culturel/templates/agenda_culturel/page.html index ed22e52..74b86d8 100644 --- a/src/agenda_culturel/templates/agenda_culturel/page.html +++ b/src/agenda_culturel/templates/agenda_culturel/page.html @@ -58,7 +58,8 @@ {% picto_from_name "plus-circle" %} {% picto_from_name "calendar" %} {% endif %} {% if perms.agenda_culturel.view_recurrentimport %} - {% show_badge_failed_rimports "bottom" %} + {% show_badge_rimports "bottom" "failed" %} + {% show_badge_rimports "bottom" "running" %} {% endif %} {% if perms.agenda_culturel.change_event %} {% show_badges_events "bottom" %} diff --git a/src/agenda_culturel/templates/agenda_culturel/rimports.html b/src/agenda_culturel/templates/agenda_culturel/rimports.html index 9e1ded4..31eab13 100644 --- a/src/agenda_culturel/templates/agenda_culturel/rimports.html +++ b/src/agenda_culturel/templates/agenda_culturel/rimports.html @@ -17,33 +17,38 @@
{% if not status %} Exécuter tout {% picto_from_name "play-circle" %} - {% else %} - {% if status == "failed" %} - Relancer les imports échoués {% picto_from_name "play-circle" %} - {% endif %} - {% if status == "canceled" %} - Relancer les imports annulés {% picto_from_name "play-circle" %} + {% if status == "failed" or status == "canceled" %} + Relancer les imports échoués {% picto_from_name "play-circle" %} {% endif %} {% endif %} Ajouter {% picto_from_name "plus-circle" %}

Importations récurrentes {% if status %}{{ status }}{% endif %}

{% if status %} - tous ({{ nb_all }}) + tous : {{ nb_all }} + {% else %} + tous : {{ nb_all }} {% endif %} - {% if not status or status != "failed" %} - {% if nb_failed == 0 %} -
échoués ({{ nb_failed }})
+ {% if nb_failed > 0 %}— + {% if not status or status != "failed" %} + échoués : {{ nb_failed }} {% else %} - échoués ({{ nb_failed }}) + échoués : {{ nb_failed }} {% endif %} {% endif %} - {% if not status or status != "canceled" %} - {% if nb_canceled == 0 %} -
annulés ({{ nb_canceled }})
+ {% if nb_canceled > 0 %}— + {% if not status or status != "canceled" %} + annulés : {{ nb_canceled }} {% else %} - annulés ({{ nb_canceled }}) + annulés : {{ nb_canceled }} + {% endif %} + {% endif %} + {% if nb_running > 0 %}— + {% if not status or status != "running" %} + en cours : {{ nb_running }} + {% else %} + en cours : {{ nb_running }} {% endif %} {% endif %} @@ -77,7 +82,11 @@
- Exécuter + {% if obj.last_import.status != "running" %} + Exécuter + {% else %} + Annuler + {% endif %} Consulter Modifier
diff --git a/src/agenda_culturel/templatetags/rimports_extra.py b/src/agenda_culturel/templatetags/rimports_extra.py index a242acb..1f89337 100644 --- a/src/agenda_culturel/templatetags/rimports_extra.py +++ b/src/agenda_culturel/templatetags/rimports_extra.py @@ -13,34 +13,43 @@ register = template.Library() @register.simple_tag -def show_badge_failed_rimports(placement="top"): +def show_badge_rimports(placement, status): newest = BatchImportation.objects.filter(recurrentImport=OuterRef("pk")).order_by( "-created_date" ) - nb_failed = ( + nb = ( RecurrentImport.objects.annotate( last_run_status=Subquery(newest.values("status")[:1]) ) - .filter(last_run_status=BatchImportation.STATUS.FAILED) + .filter(last_run_status=status) .count() ) - if nb_failed != 0: + if status == BatchImportation.STATUS.FAILED: + suffix = 'en erreur' + picto = "alert-triangle" + cl = "error" + else: + suffix = ' en cours' + picto = "repeat" + cl = "simple" + + if nb != 0: return mark_safe( '' - + picto_from_name("alert-triangle") + + pluralize(nb) + + ' ' + suffix + '">' + + picto_from_name(picto) + " " - + str(nb_failed) + + str(nb) + "" ) else: diff --git a/src/agenda_culturel/urls.py b/src/agenda_culturel/urls.py index 5b88c22..e1d7473 100644 --- a/src/agenda_culturel/urls.py +++ b/src/agenda_culturel/urls.py @@ -71,10 +71,8 @@ urlpatterns = [ path("imports//cancel", cancel_import, name="cancel_import"), path("rimports/", recurrent_imports, name="recurrent_imports"), path("rimports/run", run_all_rimports, name="run_all_rimports"), - path("rimports/failed", recurrent_imports_failed, name="recurrent_imports_failed"), - path("rimports/failed/run", run_all_rimports_failed, name="run_all_rimports_failed"), - path("rimports/canceled", recurrent_imports_canceled, name="recurrent_imports_canceled"), - path("rimports/canceled/run", run_all_rimports_canceled, name="run_all_rimports_canceled"), + path("rimports/status/", recurrent_imports, name="recurrent_imports_status"), + path("rimports/status//run", run_all_rimports, name="run_all_rimports_status"), path("rimports/add", RecurrentImportCreateView.as_view(), name="add_rimport"), path("rimports//view", view_rimport, name="view_rimport"), path( diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index 706f3aa..df1cbf5 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -1147,16 +1147,6 @@ def cancel_import(request, pk): ## recurrent importations ######################### -@login_required(login_url="/accounts/login/") -@permission_required("agenda_culturel.view_recurrentimport") -def recurrent_imports_failed(request): - return recurrent_imports(request, BatchImportation.STATUS.FAILED) - -@login_required(login_url="/accounts/login/") -@permission_required("agenda_culturel.view_recurrentimport") -def recurrent_imports_canceled(request): - return recurrent_imports(request, BatchImportation.STATUS.CANCELED) - @login_required(login_url="/accounts/login/") @permission_required("agenda_culturel.view_recurrentimport") @@ -1183,6 +1173,9 @@ def recurrent_imports(request, status=None): nb_canceled = (events .filter(last_run_status=BatchImportation.STATUS.CANCELED) .count()) + nb_running = (events + .filter(last_run_status=BatchImportation.STATUS.RUNNING) + .count()) nb_all = events.count() @@ -1194,7 +1187,7 @@ def recurrent_imports(request, status=None): response = paginator.page(paginator.num_pages) return render( - request, "agenda_culturel/rimports.html", {"paginator_filter": response, "nb_all": nb_all, "nb_failed": nb_failed, "nb_canceled": nb_canceled, "status": status} + request, "agenda_culturel/rimports.html", {"paginator_filter": response, "nb_all": nb_all, "nb_failed": nb_failed, "nb_canceled": nb_canceled, "nb_running": nb_running, "status": status} ) @@ -1274,39 +1267,25 @@ def run_rimport(request, pk): @permission_required( ["agenda_culturel.view_recurrentimport", "agenda_culturel.run_recurrentimport"] ) -def run_all_rimports(request): +def run_all_rimports(request, status=None): if request.method == "POST": # run recurrent import - run_all_recurrent_imports.delay() + if status == BatchImportation.STATUS.FAILED: + run_all_recurrent_imports_failed.delay() + elif status == BatchImportation.STATUS.CANCELED: + run_all_recurrent_imports_canceled.delay() + else: + run_all_recurrent_imports.delay() messages.success(request, _("Imports has been launched.")) return HttpResponseRedirect(reverse_lazy("recurrent_imports")) else: - return render(request, "agenda_culturel/run_all_rimports_confirm.html") - -@login_required(login_url="/accounts/login/") -@permission_required( - ["agenda_culturel.view_recurrentimport", "agenda_culturel.run_recurrentimport"] -) -def run_all_rimports_failed(request): - if request.method == "POST": - # run recurrent import - run_all_recurrent_imports_failed.delay() - - messages.success(request, _("Imports has been launched.")) - return HttpResponseRedirect(reverse_lazy("recurrent_imports")) - else: - return render(request, "agenda_culturel/run_failed_rimports_confirm.html") - -def run_all_rimports_canceled(request): - if request.method == "POST": - # run recurrent import - run_all_recurrent_imports_canceled.delay() - - messages.success(request, _("Imports has been launched.")) - return HttpResponseRedirect(reverse_lazy("recurrent_imports")) - else: - return render(request, "agenda_culturel/run_canceled_rimports_confirm.html") + if status == BatchImportation.STATUS.FAILED: + return render(request, "agenda_culturel/run_failed_rimports_confirm.html") + elif status == BatchImportation.STATUS.CANCELED: + return render(request, "agenda_culturel/run_canceled_rimports_confirm.html") + else: + return render(request, "agenda_culturel/run_all_rimports_confirm.html") #########################