From 07729353ae5e42f2d281124afd6cc26326abe4a9 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Sat, 23 Dec 2023 13:17:14 +0100 Subject: [PATCH] =?UTF-8?q?on=20fait=20la=20distinction=20entre=20url=20af?= =?UTF-8?q?fich=C3=A9e=20au=20public,=20et=20url=20servant=20=C3=A0=20iden?= =?UTF-8?q?tifier=20un=20=C3=A9v=C3=A9nement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/agenda_culturel/extractors.py | 1 + src/agenda_culturel/forms.py | 3 ++- .../migrations/0015_event_uuids.py | 19 +++++++++++++++++++ src/agenda_culturel/models.py | 1 + src/agenda_culturel/views.py | 4 ++-- 5 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 src/agenda_culturel/migrations/0015_event_uuids.py diff --git a/src/agenda_culturel/extractors.py b/src/agenda_culturel/extractors.py index de4c123..76dd75e 100644 --- a/src/agenda_culturel/extractors.py +++ b/src/agenda_culturel/extractors.py @@ -205,6 +205,7 @@ class ExtractorFacebook(Extractor): description=self.get_element("description"), image=self.get_element("image"), image_alt=self.get_element("image_alt"), + uuids=[url], reference_urls=[url]) diff --git a/src/agenda_culturel/forms.py b/src/agenda_culturel/forms.py index b9149a2..ab27976 100644 --- a/src/agenda_culturel/forms.py +++ b/src/agenda_culturel/forms.py @@ -1,4 +1,4 @@ -from django.forms import ModelForm, ValidationError, TextInput, Form, URLField +from django.forms import ModelForm, ValidationError, TextInput, Form, URLField, MultipleHiddenInput from datetime import date @@ -19,6 +19,7 @@ class EventForm(ModelForm): 'start_time': TextInput(attrs={'type': 'time', 'onchange': 'update_datetimes(event);', "onfocus": "this.oldvalue = this.value;"}), 'end_day': TextInput(attrs={'type': 'date'}), 'end_time': TextInput(attrs={'type': 'time'}), + 'uuids': MultipleHiddenInput(), } diff --git a/src/agenda_culturel/migrations/0015_event_uuids.py b/src/agenda_culturel/migrations/0015_event_uuids.py new file mode 100644 index 0000000..bddfa15 --- /dev/null +++ b/src/agenda_culturel/migrations/0015_event_uuids.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.7 on 2023-12-23 11:58 + +from django.db import migrations, models +import django_better_admin_arrayfield.models.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('agenda_culturel', '0014_batchimportation_celery_id'), + ] + + operations = [ + migrations.AddField( + model_name='event', + name='uuids', + field=django_better_admin_arrayfield.models.fields.ArrayField(base_field=models.CharField(max_length=512), blank=True, help_text='UUIDs from import to detect duplicated entries.', null=True, size=None, verbose_name='UUIDs'), + ), + ] diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index 29c2adf..933e4ff 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -123,6 +123,7 @@ class Event(models.Model): image = models.URLField(verbose_name=_('Illustration'), help_text=_("URL of the illustration image"), max_length=1024, blank=True, null=True) image_alt = models.CharField(verbose_name=_('Illustration description'), help_text=_('Alternative text used by screen readers for the image'), blank=True, null=True, max_length=1024) + uuids = ArrayField(models.CharField(max_length=512), verbose_name=_('UUIDs'), help_text=_("UUIDs from import to detect duplicated entries."), blank=True, null=True) reference_urls = ArrayField(models.URLField(max_length=512), verbose_name=_('URLs'), help_text=_("List of all the urls where this event can be found."), blank=True, null=True) tags = ArrayField(models.CharField(max_length=64), verbose_name=_('Tags'), help_text=_("A list of tags that describe the event."), blank=True, null=True) diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index 7025123..4d24df3 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -270,7 +270,7 @@ def import_from_url(request): url = ExtractorAllURLs.clean_url(url) - existing = Event.objects.filter(reference_urls__contains=[url]) + existing = Event.objects.filter(uuids__contains=[url]) if len(existing) == 0: event = ExtractorAllURLs.extract(url) @@ -279,7 +279,7 @@ def import_from_url(request): messages.success(request, _("The event has been successfully extracted, and you can now submit it after modifying it if necessary.")) return render(request, 'agenda_culturel/event_form.html', context={'form': form }) else: - form = EventForm(initial={'url': [url]}) + form = EventForm(initial={'reference_urls': [url]}) messages.error(request, _("Unable to extract an event from the proposed URL. Please use the form below to submit the event.")) return render(request, 'agenda_culturel/import.html', context={'form': form, 'form_event': form_event}) else: