diff --git a/src/agenda_culturel/celery.py b/src/agenda_culturel/celery.py index dcbd4a1..ce23b7b 100644 --- a/src/agenda_culturel/celery.py +++ b/src/agenda_culturel/celery.py @@ -174,7 +174,7 @@ def run_recurrent_import(self, pk): def daily_imports(self): from agenda_culturel.models import RecurrentImport - logger.info("Imports quotidiens") + logger.info("Everyday imports") imports = RecurrentImport.objects.filter( recurrence=RecurrentImport.RECURRENCE.DAILY ) @@ -187,18 +187,30 @@ def daily_imports(self): def run_all_recurrent_imports(self): from agenda_culturel.models import RecurrentImport - logger.info("Imports complets") + logger.info("Run all imports") imports = RecurrentImport.objects.all() for imp in imports: run_recurrent_import.delay(imp.pk) +@app.task(bind=True) +def run_all_recurrent_imports_failed(self): + from agenda_culturel.models import RecurrentImport, BatchImportation + + logger.info("Run only failed imports") + imports = RecurrentImport.objects.all() + + for imp in imports: + if imp.last_import().status == BatchImportation.STATUS.FAILED: + run_recurrent_import.delay(imp.pk) + + @app.task(bind=True) def weekly_imports(self): from agenda_culturel.models import RecurrentImport - logger.info("Imports hebdomadaires") + logger.info("Weekly imports") imports = RecurrentImport.objects.filter( recurrence=RecurrentImport.RECURRENCE.WEEKLY ) diff --git a/src/agenda_culturel/templates/agenda_culturel/rimports.html b/src/agenda_culturel/templates/agenda_culturel/rimports.html index b6fc83b..366f1b6 100644 --- a/src/agenda_culturel/templates/agenda_culturel/rimports.html +++ b/src/agenda_culturel/templates/agenda_culturel/rimports.html @@ -13,7 +13,8 @@

Importations récurrentes

diff --git a/src/agenda_culturel/templates/agenda_culturel/run_failed_rimports_confirm.html b/src/agenda_culturel/templates/agenda_culturel/run_failed_rimports_confirm.html new file mode 100644 index 0000000..6d59d08 --- /dev/null +++ b/src/agenda_culturel/templates/agenda_culturel/run_failed_rimports_confirm.html @@ -0,0 +1,25 @@ +{% extends "agenda_culturel/page.html" %} + +{% block title %}{% block og_title %}Lancer tous les imports{% endblock %}{% endblock %} + + +{% block content %} + +
+
+

Lancement des imports en échec

+
+
{% csrf_token %} +

Êtes-vous sûr·e de vouloir lancer tous les imports récurrent ayant échoué lors du dernier import ?

+ {{ form }} + + +
+
+ +{% endblock %} \ No newline at end of file diff --git a/src/agenda_culturel/urls.py b/src/agenda_culturel/urls.py index 565643f..adf74f8 100644 --- a/src/agenda_culturel/urls.py +++ b/src/agenda_culturel/urls.py @@ -71,6 +71,7 @@ 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/run", run_all_rimports_failed, name="run_all_rimports_failed"), 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 fbce8ae..c8ed2bc 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -73,6 +73,7 @@ from .celery import ( import_events_from_json, run_recurrent_import, run_all_recurrent_imports, + run_all_recurrent_imports_failed, import_events_from_url, import_events_from_urls, ) @@ -1190,6 +1191,20 @@ def run_all_rimports(request): 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") + ######################### ## duplicated events