on fait la distinction entre url affichée au public, et url servant à identifier un événement

This commit is contained in:
Jean-Marie Favreau 2023-12-23 13:17:14 +01:00
parent cc3ede4ed5
commit 07729353ae
5 changed files with 25 additions and 3 deletions

View File

@ -205,6 +205,7 @@ class ExtractorFacebook(Extractor):
description=self.get_element("description"), description=self.get_element("description"),
image=self.get_element("image"), image=self.get_element("image"),
image_alt=self.get_element("image_alt"), image_alt=self.get_element("image_alt"),
uuids=[url],
reference_urls=[url]) reference_urls=[url])

View File

@ -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 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;"}), 'start_time': TextInput(attrs={'type': 'time', 'onchange': 'update_datetimes(event);', "onfocus": "this.oldvalue = this.value;"}),
'end_day': TextInput(attrs={'type': 'date'}), 'end_day': TextInput(attrs={'type': 'date'}),
'end_time': TextInput(attrs={'type': 'time'}), 'end_time': TextInput(attrs={'type': 'time'}),
'uuids': MultipleHiddenInput(),
} }

View File

@ -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'),
),
]

View File

@ -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 = 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) 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) 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) tags = ArrayField(models.CharField(max_length=64), verbose_name=_('Tags'), help_text=_("A list of tags that describe the event."), blank=True, null=True)

View File

@ -270,7 +270,7 @@ def import_from_url(request):
url = ExtractorAllURLs.clean_url(url) url = ExtractorAllURLs.clean_url(url)
existing = Event.objects.filter(reference_urls__contains=[url]) existing = Event.objects.filter(uuids__contains=[url])
if len(existing) == 0: if len(existing) == 0:
event = ExtractorAllURLs.extract(url) 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.")) 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 }) return render(request, 'agenda_culturel/event_form.html', context={'form': form })
else: 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.")) 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}) return render(request, 'agenda_culturel/import.html', context={'form': form, 'form_event': form_event})
else: else: