Première version fonctionnelle de l'import d'événements

This commit is contained in:
Jean-Marie Favreau
2023-12-29 16:56:38 +01:00
parent 07729353ae
commit bec3fef0bf
17 changed files with 650 additions and 137 deletions

View File

@@ -1,8 +1,8 @@
from django.forms import ModelForm, ValidationError, TextInput, Form, URLField, MultipleHiddenInput
from django.forms import ModelForm, ValidationError, TextInput, Form, URLField, MultipleHiddenInput, Textarea, CharField
from datetime import date
from .models import Event
from .models import Event, BatchImportation
from django.utils.translation import gettext_lazy as _
class EventSubmissionForm(Form):
@@ -13,7 +13,7 @@ class EventForm(ModelForm):
class Meta:
model = Event
fields = '__all__'
exclude = ["possibly_duplicated"]
widgets = {
'start_day': TextInput(attrs={'type': 'date', 'onchange': 'update_datetimes(event);', "onfocus": "this.oldvalue = this.value;"}),
'start_time': TextInput(attrs={'type': 'time', 'onchange': 'update_datetimes(event);', "onfocus": "this.oldvalue = this.value;"}),
@@ -54,3 +54,25 @@ class EventForm(ModelForm):
return end_time
class BatchImportationForm(ModelForm):
json = CharField(label="JSON (facultatif)", widget=Textarea(attrs={"rows":"10"}), help_text=_("JSON in the format expected for the import. If the JSON is provided here, we will ignore the URLs given above, and use the information provided by the json without importing any additional events from the URL."), required=False)
class Meta:
model = BatchImportation
fields = ['source', 'browsable_url']
def clean(self):
cleaned_data = super().clean()
json = cleaned_data.get("json")
source = cleaned_data.get("source")
browsable_url = cleaned_data.get("browsable_url")
if (not json or json == "") and (not source or source == "") and (not browsable_url or browsable_url == ""):
raise ValidationError(_("You need to fill in either the json or the source possibly supplemented by the navigable URL."))
# Always return a value to use as the new cleaned data, even if
# this method didn't change it.
return cleaned_data