Amélioration UX gestion récurrents

Fix #148 (plus simple)
This commit is contained in:
Jean-Marie Favreau 2024-09-21 21:53:52 +02:00
parent 3dd4b02e5b
commit ebfcf8823c
7 changed files with 113 additions and 15 deletions

View File

@ -264,6 +264,15 @@ def run_all_recurrent_imports_failed(self):
run_recurrent_imports_from_list([imp.pk for imp in imports if imp.last_import().status == BatchImportation.STATUS.FAILED])
@app.task(bind=True)
def run_all_recurrent_imports_canceled(self):
from agenda_culturel.models import RecurrentImport, BatchImportation
logger.info("Run only canceled imports")
imports = RecurrentImport.objects.all().order_by("pk")
run_recurrent_imports_from_list([imp.pk for imp in imports if imp.last_import().status == BatchImportation.STATUS.CANCELED])
@app.task(bind=True)
def weekly_imports(self):

View File

@ -1,6 +1,7 @@
{% extends "agenda_culturel/page.html" %}
{% block title %}{% block og_title %}Importations récurrentes{% endblock %}{% endblock %}
{% block title %}{% block og_title %}Importations récurrentes
{% if status %}{{ status }}{% endif %}{% endblock %}{% endblock %}
{% load utils_extra %}
{% load rimports_extra %}
@ -14,13 +15,37 @@
<article>
<header>
<div class="slide-buttons">
<a href="{% url 'run_all_rimports' %}" role="button">Exécuter tout {% picto_from_name "play-circle" %}</a>
{% if has_failed_import %}
<a href="{% url 'run_all_rimports_failed' %}" role="button">Relancer les imports échoués {% picto_from_name "play-circle" %}</a>
{% if not status %}
<a href="{% url 'run_all_rimports' %}" role="button">Exécuter tout {% picto_from_name "play-circle" %}</a>
{% else %}
{% if status == "failed" %}
<a href="{% url 'run_all_rimports_failed' %}" role="button">Relancer les imports échoués {% picto_from_name "play-circle" %}</a>
{% endif %}
{% if status == "canceled" %}
<a href="{% url 'run_all_rimports_canceled' %}" role="button">Relancer les imports annulés {% picto_from_name "play-circle" %}</a>
{% endif %}
{% endif %}
<a href="{% url 'add_rimport'%}" role="button">Ajouter {% picto_from_name "plus-circle" %}</a>
</div>
<h1>Importations récurrentes</h1>
<h1>Importations récurrentes {% if status %}<em>{{ status }}</em>{% endif %}</h1>
{% if status %}
<a href="{% url 'recurrent_imports' %}" role="button">tous ({{ nb_all }})</a>
{% endif %}
{% if not status or status != "failed" %}
{% if nb_failed == 0 %}
<div role="button" class="secondary">échoués ({{ nb_failed }})</div>
{% else %}
<a href="{% url 'recurrent_imports_failed' %}" role="button">échoués ({{ nb_failed }})</a>
{% endif %}
{% endif %}
{% if not status or status != "canceled" %}
{% if nb_canceled == 0 %}
<div role="button" class="secondary">annulés ({{ nb_canceled }})</div>
{% else %}
<a href="{% url 'recurrent_imports_canceled' %}" role="button">annulés ({{ nb_canceled }})</a>
{% endif %}
{% endif %}
</header>
<table role="grid">

View File

@ -0,0 +1,27 @@
{% extends "agenda_culturel/page.html" %}
{% block title %}{% block og_title %}Lancer tous les imports annulés{% endblock %}{% endblock %}
{% block fluid %}{% endblock %}
{% block content %}
<article>
<header>
<h1>Lancement des imports en annulés</h1>
</header>
<form method="post">{% csrf_token %}
<p>Êtes-vous sûr·e de vouloir lancer tous les imports récurrent ayant été annulés lors du dernier import&nbsp;?</p>
{{ form }}
<footer>
<div class="grid buttons">
<a href="{% if request.META.HTTP_REFERER %}{{ request.META.HTTP_REFERER }}{% else %}{% url 'recurrent_imports' %}{% endif %}" role="button" class="secondary">Annuler</a>
<input type="submit" value="Confirmer">
</div>
</footer>
</form>
</article>
{% endblock %}

View File

@ -1,6 +1,8 @@
{% extends "agenda_culturel/page.html" %}
{% block title %}{% block og_title %}Lancer tous les imports{% endblock %}{% endblock %}
{% block title %}{% block og_title %}Lancer tous les imports échoués{% endblock %}{% endblock %}
{% block fluid %}{% endblock %}
{% block content %}

View File

@ -28,7 +28,7 @@ def show_badge_failed_rimports(placement="top"):
if nb_failed != 0:
return mark_safe(
'<a href="'
+ reverse_lazy("recurrent_imports")
+ reverse_lazy("recurrent_imports_failed")
+ '" class="badge error" data-placement="'
+ placement
+ '" data-tooltip="'

View File

@ -71,7 +71,10 @@ urlpatterns = [
path("imports/<int:pk>/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/add", RecurrentImportCreateView.as_view(), name="add_rimport"),
path("rimports/<int:pk>/view", view_rimport, name="view_rimport"),
path(

View File

@ -76,6 +76,7 @@ from .celery import (
run_recurrent_import,
run_all_recurrent_imports,
run_all_recurrent_imports_failed,
run_all_recurrent_imports_canceled,
import_events_from_url,
import_events_from_urls,
)
@ -1146,23 +1147,44 @@ 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(request):
paginator = Paginator(RecurrentImport.objects.all().order_by("-pk"), 10)
page = request.GET.get("page")
def recurrent_imports_canceled(request):
return recurrent_imports(request, BatchImportation.STATUS.CANCELED)
@login_required(login_url="/accounts/login/")
@permission_required("agenda_culturel.view_recurrentimport")
def recurrent_imports(request, status=None):
newest = BatchImportation.objects.filter(recurrentImport=OuterRef("pk")).order_by(
"-created_date"
)
has_failed_import = nb_failed = (
RecurrentImport.objects.annotate(
events = RecurrentImport.objects.annotate(
last_run_status=Subquery(newest.values("status")[:1])
)
if status is None:
events_selected = events.all()
else:
events_selected = events.filter(last_run_status=status)
events_selected = events_selected.order_by("-pk")
paginator = Paginator(events_selected, 10)
page = request.GET.get("page")
nb_failed = (events
.filter(last_run_status=BatchImportation.STATUS.FAILED)
.count()
) > 0
.count())
nb_canceled = (events
.filter(last_run_status=BatchImportation.STATUS.CANCELED)
.count())
nb_all = events.count()
try:
response = paginator.page(page)
@ -1172,7 +1194,7 @@ def recurrent_imports(request):
response = paginator.page(paginator.num_pages)
return render(
request, "agenda_culturel/rimports.html", {"paginator_filter": response, "has_failed_import": has_failed_import}
request, "agenda_culturel/rimports.html", {"paginator_filter": response, "nb_all": nb_all, "nb_failed": nb_failed, "nb_canceled": nb_canceled, "status": status}
)
@ -1276,6 +1298,16 @@ def run_all_rimports_failed(request):
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")
#########################
## duplicated events