Ajout d'un bouton de réimport
This commit is contained in:
parent
54cbf8e0eb
commit
b38717e52b
@ -286,7 +286,7 @@ def weekly_imports(self):
|
||||
run_recurrent_imports_from_list([imp.pk for imp in imports])
|
||||
|
||||
@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 agenda_culturel.models import RecurrentImport, BatchImportation
|
||||
from agenda_culturel.models import Event, Category
|
||||
@ -302,9 +302,9 @@ def import_events_from_url(self, url, cat):
|
||||
url = Extractor.clean_url(url)
|
||||
|
||||
# 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 len(existing) == 0:
|
||||
if force or len(existing) == 0:
|
||||
|
||||
# create an importer
|
||||
importer = DBImporterEvents(self.request.id)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -18,6 +18,7 @@ import recurrence
|
||||
import copy
|
||||
import unicodedata
|
||||
from collections import defaultdict
|
||||
from .import_tasks.extractor_facebook import FacebookEventExtractor
|
||||
|
||||
from django.template.defaultfilters import date as _date
|
||||
from datetime import time, timedelta, date
|
||||
@ -848,6 +849,16 @@ class Event(models.Model):
|
||||
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):
|
||||
els = uuid.split(":")
|
||||
if len(els) == 1:
|
||||
|
@ -1,5 +1,10 @@
|
||||
|
||||
{% 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 'edit_event' event.id %}" role="button">modifier {% picto_from_name "edit-3" %}</a>
|
||||
|
||||
@ -20,3 +25,4 @@
|
||||
{% if event.status == "trash" %}
|
||||
<a href="{% url 'delete_event' event.id %}" role="button">supprimer définitivement {% picto_from_name "x-circle" %}</a>
|
||||
{% endif %}
|
||||
|
||||
|
@ -27,6 +27,7 @@ urlpatterns = [
|
||||
name="view_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(
|
||||
"event/<int:pk>/change-status/<status>",
|
||||
change_status_event,
|
||||
|
@ -533,6 +533,18 @@ class StaticContentUpdateView(
|
||||
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(
|
||||
SuccessMessageMixin, PermissionRequiredMixin, LoginRequiredMixin, UpdateView
|
||||
):
|
||||
|
Loading…
Reference in New Issue
Block a user