MAJ bouton relancer

This commit is contained in:
Jean-Marie Favreau 2024-09-07 17:36:48 +02:00
parent f9038a03f4
commit a2b6f8bf62
3 changed files with 14 additions and 7 deletions

View File

@ -15,7 +15,7 @@
<header> <header>
<div class="slide-buttons"> <div class="slide-buttons">
<a href="{% url 'run_all_rimports' %}" role="button">Exécuter tout {% picto_from_name "play-circle" %}</a> <a href="{% url 'run_all_rimports' %}" role="button">Exécuter tout {% picto_from_name "play-circle" %}</a>
{% if has_failed_rimports %} {% if has_failed_import %}
<a href="{% url 'run_all_rimports_failed' %}" role="button">Relancer les imports échoués {% picto_from_name "play-circle" %}</a> <a href="{% url 'run_all_rimports_failed' %}" role="button">Relancer les imports échoués {% picto_from_name "play-circle" %}</a>
{% endif %} {% endif %}
<a href="{% url 'add_rimport'%}" role="button">Ajouter {% picto_from_name "plus-circle" %}</a> <a href="{% url 'add_rimport'%}" role="button">Ajouter {% picto_from_name "plus-circle" %}</a>

View File

@ -12,10 +12,6 @@ from .utils_extra import picto_from_name
register = template.Library() register = template.Library()
@register.simple_tag
def has_failed_rimports():
return BatchImportation.objects.filter(status=BatchImportation.STATUS.FAILED).count() != 0
@register.simple_tag @register.simple_tag
def show_badge_failed_rimports(placement="top"): def show_badge_failed_rimports(placement="top"):
newest = BatchImportation.objects.filter(recurrentImport=OuterRef("pk")).order_by( newest = BatchImportation.objects.filter(recurrentImport=OuterRef("pk")).order_by(

View File

@ -51,7 +51,7 @@ from django.utils import timezone
from django.utils.html import escape from django.utils.html import escape
from datetime import date, timedelta from datetime import date, timedelta
from django.utils.timezone import datetime 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.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _ 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) paginator = Paginator(RecurrentImport.objects.all().order_by("-pk"), 10)
page = request.GET.get("page") 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: try:
response = paginator.page(page) response = paginator.page(page)
except PageNotAnInteger: except PageNotAnInteger:
@ -1101,7 +1112,7 @@ def recurrent_imports(request):
response = paginator.page(paginator.num_pages) response = paginator.page(paginator.num_pages)
return render( return render(
request, "agenda_culturel/rimports.html", {"paginator_filter": response} request, "agenda_culturel/rimports.html", {"paginator_filter": response, "has_failed_import": has_failed_import}
) )