diff --git a/src/agenda_culturel/forms.py b/src/agenda_culturel/forms.py index af3b97b..033c28a 100644 --- a/src/agenda_culturel/forms.py +++ b/src/agenda_culturel/forms.py @@ -182,6 +182,57 @@ class EventForm(ModelForm): self.cleaned_data['local_image'] = File(name=basename, file=open(old, "rb")) +class MultipleChoiceFieldAcceptAll(MultipleChoiceField): + def validate(self, value): + pass + + +class EventModerateForm(ModelForm): + + tags = MultipleChoiceField( + label=_("Tags"), + help_text=_('Select tags from existing ones.'), + required=False + ) + + new_tags = MultipleChoiceFieldAcceptAll( + label=_("New tags"), + help_text=_('Create new labels (sparingly).'), + widget=DynamicArrayWidget(), + required=False + ) + + class Meta: + model = Event + fields = [ + "status", + "category", + "exact_location", + "tags" + ] + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['category'].queryset = self.fields['category'].queryset.order_by('name') + self.fields['category'].empty_label = None + self.fields['category'].initial = Category.get_default_category() + self.fields['tags'].choices = Tag.get_tag_groups(all=True) + + def clean_new_tags(self): + return list(set(self.cleaned_data.get("new_tags"))) + + def clean(self): + super().clean() + + if self.cleaned_data['tags'] is None: + self.cleaned_data['tags'] = [] + + if not self.cleaned_data.get('new_tags') is None: + self.cleaned_data['tags'] += self.cleaned_data.get('new_tags') + + self.cleaned_data['tags'] = list(set(self.cleaned_data['tags'])) + + class BatchImportationForm(Form): json = CharField( @@ -270,7 +321,6 @@ class FixDuplicates(Form): def get_selected_event(self, edup): selected = self.get_selected_event_code() - logger.warning("selected " + str(selected)) for e in edup.get_duplicated(): if e.pk == selected: return e diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index 3f4ccdb..0b134fc 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -790,6 +790,12 @@ class Event(models.Model): def set_no_modification_date_changed(self): self.no_modification_date_changed = True + def set_in_moderation_process(self): + self.in_moderation_process = True + + def is_in_moderation_process(self): + return hasattr(self, "in_moderation_process") + def update_modification_dates(self): now = timezone.now() if not self.id: @@ -798,6 +804,8 @@ class Event(models.Model): self.imported_date = now if self.modified_date is None or not self.is_no_modification_date_changed(): self.modified_date = now + if self.is_in_moderation_process(): + self.moderated_date = now def get_recurrence_at_date(self, year, month, day): dtstart = timezone.make_aware( diff --git a/src/agenda_culturel/static/style.scss b/src/agenda_culturel/static/style.scss index 23ad0b9..4772c2b 100644 --- a/src/agenda_culturel/static/style.scss +++ b/src/agenda_culturel/static/style.scss @@ -1399,4 +1399,9 @@ form.messages div, form.moderation-events { clear: both; float: left; } +} + +.moderate-preview .event-body { + max-height: 300px; + overflow-y: auto; } \ No newline at end of file diff --git a/src/agenda_culturel/templates/agenda_culturel/edit-buttons-inc.html b/src/agenda_culturel/templates/agenda_culturel/edit-buttons-inc.html index 3c0c9da..7f05b23 100644 --- a/src/agenda_culturel/templates/agenda_culturel/edit-buttons-inc.html +++ b/src/agenda_culturel/templates/agenda_culturel/edit-buttons-inc.html @@ -1,6 +1,12 @@ {% load utils_extra %} +{% if event.moderated_date %} +Modérer de nouveau {% picto_from_name "check-square" %} +{% else %} +Modérer {% picto_from_name "check-square" %} +{% endif %} + {% if event.pure_import %} {% with event.get_local_version as local %} {% if local %} diff --git a/src/agenda_culturel/templates/agenda_culturel/event_form.html b/src/agenda_culturel/templates/agenda_culturel/event_form.html index a43cd20..42bc98a 100644 --- a/src/agenda_culturel/templates/agenda_culturel/event_form.html +++ b/src/agenda_culturel/templates/agenda_culturel/event_form.html @@ -60,7 +60,7 @@ Création d'une copie de {% else %} {% endif %} -
+ {% if form.is_clone_from_url %} {% url "add_event_details" as urlparam %} {% endif %} diff --git a/src/agenda_culturel/templates/agenda_culturel/event_form_moderate.html b/src/agenda_culturel/templates/agenda_culturel/event_form_moderate.html new file mode 100644 index 0000000..a9f654d --- /dev/null +++ b/src/agenda_culturel/templates/agenda_culturel/event_form_moderate.html @@ -0,0 +1,85 @@ +{% extends "agenda_culturel/page.html" %} +{% load static %} + + +{% block title %}{% block og_title %}Modération de l'événement {{ object.title }} ({{ object.start_day }}){% endblock %}{% endblock %} + +{% block ajouter-bouton %}{% block ajouter-menu %}{% endblock %}{% endblock %} + + +{% block entete_header %} + + + + + + + + + + + + + + + + + +{% endblock %} +{% block fluid %}{% endblock %} + + +{% block content %} +{% load static_content_extra %} + +
+
+

Modération de l'événement {{ object.title }} ({{ object.start_day }})

+
+ + {% include "agenda_culturel/single-event/event-single-inc.html" with event=event filter=filter %} + +
{% csrf_token %} + {{ form.media }} + {{ form.as_p }} +
+ Annuler + +
+
+ +{% if object %} +{% include "agenda_culturel/event-info-inc.html" %} +{% endif %} +
+ + +{% endblock %} \ No newline at end of file diff --git a/src/agenda_culturel/templates/agenda_culturel/single-event/event-single-inc.html b/src/agenda_culturel/templates/agenda_culturel/single-event/event-single-inc.html index a636c14..5765814 100644 --- a/src/agenda_culturel/templates/agenda_culturel/single-event/event-single-inc.html +++ b/src/agenda_culturel/templates/agenda_culturel/single-event/event-single-inc.html @@ -49,6 +49,7 @@ {% endif %} +
{% if event.has_image_url %} @@ -58,6 +59,7 @@ {% endif %}

{{ event.description |linebreaks | robust_urlize }}

+