On permet à un import récurrent de n'être jamais lancé

Fix #321
This commit is contained in:
Jean-Marie Favreau 2025-03-02 22:08:15 +01:00
parent f17f24b6c2
commit 18432829b8
7 changed files with 422 additions and 380 deletions

View File

@ -11,6 +11,7 @@ from celery.utils.log import get_task_logger
from django.conf import settings
from django.core.cache import cache
from datetime import date
from django.db.models import Q
from .import_tasks.custom_extractors import (
lacomedie,
@ -367,10 +368,13 @@ def run_all_recurrent_imports(self, only_fb=False):
logger.info("Run all imports")
if only_fb:
imports = RecurrentImport.objects.filter(
processor=RecurrentImport.PROCESSOR.FBEVENTS
Q(processor=RecurrentImport.PROCESSOR.FBEVENTS)
& ~Q(recurrence=RecurrentImport.RECURRENCE.NEVER)
).order_by("pk")
else:
imports = RecurrentImport.objects.all().order_by("pk")
imports = RecurrentImport.objects.filter(
~Q(recurrence=RecurrentImport.RECURRENCE.NEVER)
).order_by("pk")
run_recurrent_imports_from_list([imp.pk for imp in imports])
@ -380,7 +384,9 @@ def run_all_recurrent_imports_failed(self):
from agenda_culturel.models import BatchImportation, RecurrentImport
logger.info("Run only failed imports")
imports = RecurrentImport.objects.all().order_by("pk")
imports = RecurrentImport.objects.filter(
~Q(recurrence=RecurrentImport.RECURRENCE.NEVER)
).order_by("pk")
imports = [(imp.pk, imp.last_import()) for imp in imports]
run_recurrent_imports_from_list(
@ -397,7 +403,9 @@ def run_all_recurrent_imports_canceled(self):
from agenda_culturel.models import BatchImportation, RecurrentImport
logger.info("Run only canceled imports")
imports = RecurrentImport.objects.all().order_by("pk")
imports = RecurrentImport.objects.filter(
~Q(recurrence=RecurrentImport.RECURRENCE.NEVER)
).order_by("pk")
imports = [(imp.pk, imp.last_import()) for imp in imports]
run_recurrent_imports_from_list(

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,23 @@
# Generated by Django 4.2.19 on 2025-03-02 21:54
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("agenda_culturel", "0151_referencelocation_slug"),
]
operations = [
migrations.AlterField(
model_name="recurrentimport",
name="recurrence",
field=models.CharField(
choices=[("daily", "daily"), ("weekly", "weekly"), ("never", "never")],
default="daily",
max_length=10,
verbose_name="Import recurrence",
),
),
]

View File

@ -2504,6 +2504,7 @@ class RecurrentImport(models.Model):
_("daily"),
)
WEEKLY = "weekly", _("weekly")
NEVER = "never", _("never")
name = models.CharField(
verbose_name=_("Name"),

View File

@ -1,3 +1,4 @@
{% load i18n %}
<div class="large-table">
<table role="grid">
<thead>
@ -47,7 +48,7 @@
{% endif %}
</td>
<td>
<span {% if obj.status == "failed" %}data-tooltip="{{ obj.error_message }}"{% endif %}>{{ obj.status }}</span>
<span {% if obj.status == "failed" %}data-tooltip="{{ obj.error_message }}"{% endif %}>{% trans obj.status %}</span>
{% if obj.status == "running" %}
(<a href="{% url 'cancel_import' obj.id %}">annuler</a>)
{% endif %}

View File

@ -3,6 +3,7 @@
{% block og_title %}Import récurrent #{{ object.pk }}{% endblock %}
{% endblock %}
{% load cat_extra %}
{% load i18n %}
{% load utils_extra %}
{% load tag_extra %}
{% block entete_header %}
@ -42,7 +43,7 @@
<strong>Téléchargeur&nbsp;:</strong> {{ object.downloader }}
</li>
<li>
<strong>Recurrence&nbsp;:</strong> {{ object.recurrence }}
<strong>Recurrence&nbsp;:</strong> {% trans object.recurrence %}
</li>
<li>
<strong>Source&nbsp;:</strong> <a href="{{ object.source }}">{{ object.source }}</a>

View File

@ -197,7 +197,11 @@ def mentions_legales(request):
def about(request):
rimports = RecurrentImport.objects.order_by("name__unaccent").all()
rimports = (
RecurrentImport.objects.filter(~Q(recurrence=RecurrentImport.RECURRENCE.NEVER))
.order_by("name__unaccent")
.all()
)
context = {
"title": "À propos",
"static_content": "about",