parent
0924d5d36c
commit
1e278581ed
@ -137,6 +137,7 @@ class EventForm(ModelForm):
|
|||||||
required_css_class = 'required'
|
required_css_class = 'required'
|
||||||
|
|
||||||
old_local_image = CharField(widget=HiddenInput(), required=False)
|
old_local_image = CharField(widget=HiddenInput(), required=False)
|
||||||
|
simple_cloning = CharField(widget=HiddenInput(), required=False)
|
||||||
|
|
||||||
tags = MultipleChoiceField(
|
tags = MultipleChoiceField(
|
||||||
label=_("Tags"),
|
label=_("Tags"),
|
||||||
@ -181,6 +182,7 @@ class EventForm(ModelForm):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
is_authenticated = kwargs.pop("is_authenticated", False)
|
is_authenticated = kwargs.pop("is_authenticated", False)
|
||||||
self.cloning = kwargs.pop("is_cloning", False)
|
self.cloning = kwargs.pop("is_cloning", False)
|
||||||
|
self.simple_cloning = kwargs.pop("is_simple_cloning", False)
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
if not is_authenticated:
|
if not is_authenticated:
|
||||||
del self.fields["status"]
|
del self.fields["status"]
|
||||||
@ -192,6 +194,9 @@ class EventForm(ModelForm):
|
|||||||
def is_clone_from_url(self):
|
def is_clone_from_url(self):
|
||||||
return self.cloning
|
return self.cloning
|
||||||
|
|
||||||
|
def is_simple_clone_from_url(self):
|
||||||
|
return self.simple_cloning
|
||||||
|
|
||||||
def clean_end_day(self):
|
def clean_end_day(self):
|
||||||
start_day = self.cleaned_data.get("start_day")
|
start_day = self.cleaned_data.get("start_day")
|
||||||
end_day = self.cleaned_data.get("end_day")
|
end_day = self.cleaned_data.get("end_day")
|
||||||
|
@ -41,3 +41,6 @@
|
|||||||
<a href="{% url 'delete_event' event.id %}" role="button">supprimer définitivement {% picto_from_name "x-circle" %}</a>
|
<a href="{% url 'delete_event' event.id %}" role="button">supprimer définitivement {% picto_from_name "x-circle" %}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if with_clone %}
|
||||||
|
<a href="{% url 'simple_clone_edit' event.id %}" role="button">Dupliquer {% picto_from_name "copy" %}</a>
|
||||||
|
{% endif %}
|
||||||
|
@ -4,7 +4,11 @@
|
|||||||
|
|
||||||
{% block title %}{% block og_title %}
|
{% block title %}{% block og_title %}
|
||||||
{% if object %}{% if form.is_clone_from_url %}
|
{% if object %}{% if form.is_clone_from_url %}
|
||||||
Création d'une copie de {% else %}
|
Création d'une copie locale de {% else %}
|
||||||
|
Édition de l'événement {{ object.title }} ({{ object.start_day }})
|
||||||
|
{% endif %}
|
||||||
|
{% if form.is_simple_clone_from_url %}
|
||||||
|
Duplication de {% else %}
|
||||||
Édition de l'événement {{ object.title }} ({{ object.start_day }})
|
Édition de l'événement {{ object.title }} ({{ object.start_day }})
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
@ -48,9 +52,10 @@ Création d'une copie de {% else %}
|
|||||||
<header>
|
<header>
|
||||||
{% if object %}
|
{% if object %}
|
||||||
<h1>{% if form.is_clone_from_url %}
|
<h1>{% if form.is_clone_from_url %}
|
||||||
Création d'une copie de {% else %}
|
Création d'une copie locale de {% else %}
|
||||||
Édition de l'événement{% endif %} {{ object.title }} ({{ object.start_day }})</h1>
|
{% if form.is_simple_clone_from_url %}
|
||||||
{% else %}
|
Duplication de {% else %}
|
||||||
|
Édition de l'événement{% endif %}{% endif %} {{ object.title }} ({{ object.start_day }})</h1>
|
||||||
{% if from_import %}
|
{% if from_import %}
|
||||||
<h1>Ajuster l'événement importé</h1>
|
<h1>Ajuster l'événement importé</h1>
|
||||||
{% else %}
|
{% else %}
|
||||||
@ -61,7 +66,7 @@ Création d'une copie de {% else %}
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
|
||||||
{% if form.is_clone_from_url %}
|
{% if form.is_clone_from_url or form.is_simple_clone_from_url %}
|
||||||
{% url "add_event_details" as urlparam %}
|
{% url "add_event_details" as urlparam %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<form method="post" action="{{ urlparam }}" enctype="multipart/form-data">{% csrf_token %}
|
<form method="post" action="{{ urlparam }}" enctype="multipart/form-data">{% csrf_token %}
|
||||||
|
@ -98,7 +98,7 @@
|
|||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<a href="{% url 'export_event_ical' event.start_day.year event.start_day.month event.start_day.day event.id %}" role="button">Exporter ical {% picto_from_name "calendar" %}</a>
|
<a href="{% url 'export_event_ical' event.start_day.year event.start_day.month event.start_day.day event.id %}" role="button">Exporter ical {% picto_from_name "calendar" %}</a>
|
||||||
{% if perms.agenda_culturel.change_event and not noedit %}
|
{% if perms.agenda_culturel.change_event and not noedit %}
|
||||||
{% include "agenda_culturel/edit-buttons-inc.html" with event=event %}
|
{% include "agenda_culturel/edit-buttons-inc.html" with event=event with_clone=1 %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
@ -38,6 +38,7 @@ urlpatterns = [
|
|||||||
path("event/<int:pk>/moderate-next", EventModerateView.as_view(), name="moderate_event_next"),
|
path("event/<int:pk>/moderate-next", EventModerateView.as_view(), name="moderate_event_next"),
|
||||||
path("event/<int:pk>/moderate-next/error", error_next_event, name="error_next_event"),
|
path("event/<int:pk>/moderate-next/error", error_next_event, name="error_next_event"),
|
||||||
path("moderate", EventModerateView.as_view(), name="moderate"),
|
path("moderate", EventModerateView.as_view(), name="moderate"),
|
||||||
|
path("event/<int:pk>/simple-clone/edit", EventUpdateView.as_view(), name="simple_clone_edit"),
|
||||||
path("event/<int:pk>/clone/edit", EventUpdateView.as_view(), name="clone_edit"),
|
path("event/<int:pk>/clone/edit", EventUpdateView.as_view(), name="clone_edit"),
|
||||||
path("event/<int:pk>/update-from-source", update_from_source, name="update_from_source"),
|
path("event/<int:pk>/update-from-source", update_from_source, name="update_from_source"),
|
||||||
path(
|
path(
|
||||||
|
@ -304,14 +304,18 @@ class EventUpdateView(
|
|||||||
success_message = _("The event has been successfully modified.")
|
success_message = _("The event has been successfully modified.")
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
|
logger.warning("start kwargs")
|
||||||
kwargs = super().get_form_kwargs()
|
kwargs = super().get_form_kwargs()
|
||||||
kwargs["is_authenticated"] = self.request.user.is_authenticated
|
kwargs["is_authenticated"] = self.request.user.is_authenticated
|
||||||
kwargs["is_cloning"] = self.is_cloning
|
kwargs["is_cloning"] = self.is_cloning
|
||||||
|
kwargs["is_simple_cloning"] = self.is_simple_cloning
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
self.is_cloning = "clone" in self.request.path.split('/')
|
self.is_cloning = "clone" in self.request.path.split('/')
|
||||||
|
self.is_simple_cloning = "simple-clone" in self.request.path.split('/')
|
||||||
result = super().get_initial()
|
result = super().get_initial()
|
||||||
|
|
||||||
if self.is_cloning and not "other_versions" in result:
|
if self.is_cloning and not "other_versions" in result:
|
||||||
obj = self.get_object()
|
obj = self.get_object()
|
||||||
# if no DuplicatedEvents is associated, create one
|
# if no DuplicatedEvents is associated, create one
|
||||||
@ -322,20 +326,18 @@ class EventUpdateView(
|
|||||||
obj.save()
|
obj.save()
|
||||||
result["other_versions"] = obj.other_versions
|
result["other_versions"] = obj.other_versions
|
||||||
result["status"] = Event.STATUS.PUBLISHED
|
result["status"] = Event.STATUS.PUBLISHED
|
||||||
|
|
||||||
|
if self.is_simple_cloning:
|
||||||
|
result["other_versions"] = None
|
||||||
|
result["simple_cloning"] = True
|
||||||
|
|
||||||
|
if self.is_cloning or self.is_simple_cloning:
|
||||||
|
obj = self.get_object()
|
||||||
if obj.local_image:
|
if obj.local_image:
|
||||||
result["old_local_image"] = obj.local_image.name
|
result["old_local_image"] = obj.local_image.name
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def form_valid(self, form):
|
|
||||||
original = self.get_object()
|
|
||||||
# if an image is uploaded, it removes the url stored
|
|
||||||
if form.cleaned_data['local_image'] != original.local_image:
|
|
||||||
form.instance.image = None
|
|
||||||
|
|
||||||
form.instance.import_sources = None
|
|
||||||
|
|
||||||
return super().form_valid(form)
|
|
||||||
|
|
||||||
|
|
||||||
class EventModerateView(
|
class EventModerateView(
|
||||||
@ -504,6 +506,17 @@ class EventCreateView(SuccessMessageMixin, CreateView):
|
|||||||
return _("The event has been submitted and will be published as soon as it has been validated by the moderation team.")
|
return _("The event has been submitted and will be published as soon as it has been validated by the moderation team.")
|
||||||
|
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
|
||||||
|
logger.warning(str(form.cleaned_data))
|
||||||
|
if form.cleaned_data['simple_cloning']:
|
||||||
|
form.instance.set_skip_duplicate_check()
|
||||||
|
|
||||||
|
form.instance.import_sources = None
|
||||||
|
|
||||||
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
def import_from_details(request):
|
def import_from_details(request):
|
||||||
form = EventForm(request.POST, is_authenticated=request.user.is_authenticated)
|
form = EventForm(request.POST, is_authenticated=request.user.is_authenticated)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user