From a2b6f8bf622289bf4a598d8a5997011931a8f8d5 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Sat, 7 Sep 2024 17:36:48 +0200 Subject: [PATCH] MAJ bouton relancer --- .../templates/agenda_culturel/rimports.html | 2 +- .../templatetags/rimports_extra.py | 4 ---- src/agenda_culturel/views.py | 15 +++++++++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/agenda_culturel/templates/agenda_culturel/rimports.html b/src/agenda_culturel/templates/agenda_culturel/rimports.html index 185399a..e6c844d 100644 --- a/src/agenda_culturel/templates/agenda_culturel/rimports.html +++ b/src/agenda_culturel/templates/agenda_culturel/rimports.html @@ -15,7 +15,7 @@
Exécuter tout {% picto_from_name "play-circle" %} - {% if has_failed_rimports %} + {% if has_failed_import %} Relancer les imports échoués {% picto_from_name "play-circle" %} {% endif %} Ajouter {% picto_from_name "plus-circle" %} diff --git a/src/agenda_culturel/templatetags/rimports_extra.py b/src/agenda_culturel/templatetags/rimports_extra.py index b64829e..fa8aa59 100644 --- a/src/agenda_culturel/templatetags/rimports_extra.py +++ b/src/agenda_culturel/templatetags/rimports_extra.py @@ -12,10 +12,6 @@ from .utils_extra import picto_from_name register = template.Library() -@register.simple_tag -def has_failed_rimports(): - return BatchImportation.objects.filter(status=BatchImportation.STATUS.FAILED).count() != 0 - @register.simple_tag def show_badge_failed_rimports(placement="top"): newest = BatchImportation.objects.filter(recurrentImport=OuterRef("pk")).order_by( diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index c8ed2bc..fb7adb0 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -51,7 +51,7 @@ from django.utils import timezone from django.utils.html import escape from datetime import date, timedelta from django.utils.timezone import datetime -from django.db.models import Q +from django.db.models import Q, Subquery, OuterRef from django.urls import reverse_lazy from django.utils.translation import gettext_lazy as _ @@ -1093,6 +1093,17 @@ def recurrent_imports(request): paginator = Paginator(RecurrentImport.objects.all().order_by("-pk"), 10) page = request.GET.get("page") + newest = BatchImportation.objects.filter(recurrentImport=OuterRef("pk")).order_by( + "-created_date" + ) + has_failed_import = nb_failed = ( + RecurrentImport.objects.annotate( + last_run_status=Subquery(newest.values("status")[:1]) + ) + .filter(last_run_status=BatchImportation.STATUS.FAILED) + .count() + ) > 0 + try: response = paginator.page(page) except PageNotAnInteger: @@ -1101,7 +1112,7 @@ def recurrent_imports(request): response = paginator.page(paginator.num_pages) return render( - request, "agenda_culturel/rimports.html", {"paginator_filter": response} + request, "agenda_culturel/rimports.html", {"paginator_filter": response, "has_failed_import": has_failed_import} )