Ajout de la gestion des lieux
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
from django.forms import ModelForm, ValidationError, TextInput, Form, URLField, MultipleHiddenInput, Textarea, CharField, ChoiceField, RadioSelect, MultipleChoiceField, BooleanField, HiddenInput
|
||||
from django.forms import ModelForm, ValidationError, TextInput, Form, URLField, MultipleHiddenInput, Textarea, CharField, ChoiceField, RadioSelect, MultipleChoiceField, BooleanField, HiddenInput, ModelChoiceField
|
||||
from datetime import date
|
||||
from django_better_admin_arrayfield.forms.widgets import DynamicArrayWidget
|
||||
|
||||
from .models import Event, BatchImportation, RecurrentImport, CategorisationRule, ModerationAnswer, ModerationQuestion
|
||||
from .models import Event, BatchImportation, RecurrentImport, CategorisationRule, ModerationAnswer, ModerationQuestion, Place
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from string import ascii_uppercase as auc
|
||||
from .templatetags.utils_extra import int_to_abc
|
||||
@@ -283,8 +283,6 @@ class CategorisationForm(Form):
|
||||
if '_' not in f:
|
||||
if f + '_cat' in args[0]:
|
||||
events.append((Event.objects.get(pk=int(f)), args[0][f + '_cat']))
|
||||
|
||||
# TODO
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
for e, c in events:
|
||||
@@ -294,3 +292,48 @@ class CategorisationForm(Form):
|
||||
def get_validated(self):
|
||||
return [(e, self.cleaned_data.get(e + '_cat')) for e in self.fields if '_' not in e and self.cleaned_data.get(e)]
|
||||
|
||||
|
||||
class EventAddPlaceForm(Form):
|
||||
|
||||
place = ModelChoiceField(label=_("Place"), queryset=Place.objects.all(), empty_label=_("Create a missing place"), required=False)
|
||||
add_alias = BooleanField(initial=True, required=False)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.instance = kwargs.pop('instance', False)
|
||||
super().__init__(*args, **kwargs)
|
||||
if self.instance.location:
|
||||
self.fields["add_alias"].label = _("Add \"{}\" to the aliases of the place").format(self.instance.location)
|
||||
else:
|
||||
self.fields.pop("add_alias")
|
||||
|
||||
def modified_event(self):
|
||||
return self.cleaned_data.get('place')
|
||||
|
||||
def save(self):
|
||||
if self.cleaned_data.get("place"):
|
||||
place = self.cleaned_data.get("place")
|
||||
self.instance.exact_location = place
|
||||
self.instance.save()
|
||||
if self.cleaned_data.get('add_alias'):
|
||||
place.aliases.append(self.instance.location)
|
||||
place.save()
|
||||
|
||||
return self.instance
|
||||
|
||||
class PlaceForm(ModelForm):
|
||||
apply_to_all = BooleanField(initial=True, label=_('On saving, use aliases to detect all matching events with missing place'), required=False)
|
||||
|
||||
class Meta:
|
||||
model = Place
|
||||
fields = '__all__'
|
||||
widgets = {
|
||||
'location': TextInput()
|
||||
}
|
||||
|
||||
def as_grid(self):
|
||||
return mark_safe('<div class="grid"><div>' + super().as_p() + '</div><div><div class="map-widget">' +
|
||||
'<div id="map_location" style="width: 100%; aspect-ratio: 16/9"></div></div></div></div>')
|
||||
|
||||
|
||||
def apply(self):
|
||||
return self.cleaned_data.get("apply_to_all")
|
||||
|
||||
Reference in New Issue
Block a user