diff --git a/src/agenda_culturel/import_tasks/extractor.py b/src/agenda_culturel/import_tasks/extractor.py index 4822dad..3e75870 100644 --- a/src/agenda_culturel/import_tasks/extractor.py +++ b/src/agenda_culturel/import_tasks/extractor.py @@ -2,7 +2,7 @@ from abc import ABC, abstractmethod from datetime import datetime, time, date, timedelta import re import unicodedata - +from django.utils import timezone @@ -240,6 +240,28 @@ class Extractor(ABC): from .extractor_ggcal_link import GoogleCalendarLinkEventExtractor if single_event: - return [FacebookEventExtractor(), GoogleCalendarLinkEventExtractor()] + return [FacebookEventExtractor(), GoogleCalendarLinkEventExtractor(), EventNotFoundExtractor()] else: - return [ICALExtractor(), FacebookEventExtractor(), GoogleCalendarLinkEventExtractor()] + return [ICALExtractor(), FacebookEventExtractor(), GoogleCalendarLinkEventExtractor(), EventNotFoundExtractor()] + + +# A class that only produce a not found event +class EventNotFoundExtractor(Extractor): + + def extract( + self, content, url, url_human=None, default_values=None, published=False + ): + self.set_header(url) + self.clear_events() + + self.add_event(default_values, "événement sans titre", + None, timezone.now().date(), None, + "l'import a échoué, la saisie doit se faire manuellement à partir de l'url source", + [], [url], published=False, url_human=url) + + return self.get_structure() + + + def clean_url(url): + return url + diff --git a/src/agenda_culturel/import_tasks/generic_extractors.py b/src/agenda_culturel/import_tasks/generic_extractors.py index 03061e1..10803c9 100644 --- a/src/agenda_culturel/import_tasks/generic_extractors.py +++ b/src/agenda_culturel/import_tasks/generic_extractors.py @@ -269,4 +269,5 @@ class TwoStepsExtractorNoPause(TwoStepsExtractor): result = super().extract(content, url, url_human, default_values, published, only_future, ignore_404) self.downloader.pause = pause - return result \ No newline at end of file + return result + diff --git a/src/agenda_culturel/import_tasks/importer.py b/src/agenda_culturel/import_tasks/importer.py index 753381f..f9c0b0a 100644 --- a/src/agenda_culturel/import_tasks/importer.py +++ b/src/agenda_culturel/import_tasks/importer.py @@ -1,6 +1,11 @@ from .downloader import * from .extractor import * +import logging + +logger = logging.getLogger(__name__) + + class URL2Events: def __init__( @@ -29,8 +34,9 @@ class URL2Events: else: # if the extractor is not defined, use a list of default extractors for e in Extractor.get_default_extractors(self.single_event): + logger.warning('Extractor::' + type(e).__name__) e.set_downloader(self.downloader) events = e.extract(content, url, url_human, default_values, published) - if events is not None: + if events is not None and len(events) > 0: return events return None diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index d4853a6..022dd6d 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -1490,7 +1490,7 @@ class Event(models.Model): imported = Event.objects.bulk_create(to_import) # update organisers (m2m relation) for i, ti in zip(imported, to_import): - if ti.has_pending_organisers(): + if ti.has_pending_organisers() and ti.pending_organisers is not None: i.organisers.set(ti.pending_organisers) nb_updated = Event.objects.bulk_update(