Ajout d'un bouton de réimport

This commit is contained in:
Jean-Marie Favreau 2024-10-17 23:18:54 +02:00
parent 54cbf8e0eb
commit b38717e52b
6 changed files with 256 additions and 214 deletions

View File

@ -286,7 +286,7 @@ def weekly_imports(self):
run_recurrent_imports_from_list([imp.pk for imp in imports]) run_recurrent_imports_from_list([imp.pk for imp in imports])
@app.task(base=ChromiumTask, bind=True) @app.task(base=ChromiumTask, bind=True)
def import_events_from_url(self, url, cat): def import_events_from_url(self, url, cat, force=False):
from .db_importer import DBImporterEvents from .db_importer import DBImporterEvents
from agenda_culturel.models import RecurrentImport, BatchImportation from agenda_culturel.models import RecurrentImport, BatchImportation
from agenda_culturel.models import Event, Category from agenda_culturel.models import Event, Category
@ -302,9 +302,9 @@ def import_events_from_url(self, url, cat):
url = Extractor.clean_url(url) url = Extractor.clean_url(url)
# we check if the url is known # we check if the url is known
existing = Event.objects.filter(uuids__contains=[url]) existing = None if force else Event.objects.filter(uuids__contains=[url])
# if it's unknown # if it's unknown
if len(existing) == 0: if force or len(existing) == 0:
# create an importer # create an importer
importer = DBImporterEvents(self.request.id) importer = DBImporterEvents(self.request.id)

File diff suppressed because it is too large Load Diff

View File

@ -18,6 +18,7 @@ import recurrence
import copy import copy
import unicodedata import unicodedata
from collections import defaultdict from collections import defaultdict
from .import_tasks.extractor_facebook import FacebookEventExtractor
from django.template.defaultfilters import date as _date from django.template.defaultfilters import date as _date
from datetime import time, timedelta, date from datetime import time, timedelta, date
@ -847,6 +848,16 @@ class Event(models.Model):
if self.uuids is None or len(self.uuids) == 0 if self.uuids is None or len(self.uuids) == 0
else Event.objects.filter(uuids__contains=self.uuids) else Event.objects.filter(uuids__contains=self.uuids)
) )
def get_updateable_uuid(self):
if self.uuids and len(self.uuids) > 0:
for s in self.uuids:
if FacebookEventExtractor.is_known_url(s):
return s
return None
def is_updateable(self):
return not self.get_updateable_uuid() is None
def split_uuid(uuid): def split_uuid(uuid):
els = uuid.split(":") els = uuid.split(":")

View File

@ -1,5 +1,10 @@
{% load utils_extra %} {% load utils_extra %}
{% if event.is_updateable %}
<a href="{% url 'update_from_source' event.id %}" role="button">Réimporter {% picto_from_name "download-cloud" %}</a>
{% endif %}
<a href="{% url 'moderate_event' event.id %}" role="button">modérer {% picto_from_name "edit" %}</a> <a href="{% url 'moderate_event' event.id %}" role="button">modérer {% picto_from_name "edit" %}</a>
<a href="{% url 'edit_event' event.id %}" role="button">modifier {% picto_from_name "edit-3" %}</a> <a href="{% url 'edit_event' event.id %}" role="button">modifier {% picto_from_name "edit-3" %}</a>
@ -20,3 +25,4 @@
{% if event.status == "trash" %} {% if event.status == "trash" %}
<a href="{% url 'delete_event' event.id %}" role="button">supprimer définitivement {% picto_from_name "x-circle" %}</a> <a href="{% url 'delete_event' event.id %}" role="button">supprimer définitivement {% picto_from_name "x-circle" %}</a>
{% endif %} {% endif %}

View File

@ -27,6 +27,7 @@ urlpatterns = [
name="view_event", name="view_event",
), ),
path("event/<int:pk>/edit", EventUpdateView.as_view(), name="edit_event"), path("event/<int:pk>/edit", EventUpdateView.as_view(), name="edit_event"),
path("event/<int:pk>/update-from-source", update_from_source, name="update_from_source"),
path( path(
"event/<int:pk>/change-status/<status>", "event/<int:pk>/change-status/<status>",
change_status_event, change_status_event,

View File

@ -533,6 +533,18 @@ class StaticContentUpdateView(
success_message = _("The static content has been successfully updated.") success_message = _("The static content has been successfully updated.")
def update_from_source(request, pk):
event = get_object_or_404(Event, pk=pk)
url = event.get_updateable_uuid()
if url is None:
messages.warning(request, _("The event cannot be updated because the import process is not available for the referenced sources."))
else:
import_events_from_url.delay(url, None, True)
messages.success(request, _("The event update has been queued and will be completed shortly."))
return HttpResponseRedirect(event.get_absolute_url())
class EventUpdateView( class EventUpdateView(
SuccessMessageMixin, PermissionRequiredMixin, LoginRequiredMixin, UpdateView SuccessMessageMixin, PermissionRequiredMixin, LoginRequiredMixin, UpdateView
): ):