Fix bug création de lieu depuis un événement

Quand on créé un lieu depuis un événement:
- l'alias est ajouté que si on le souhaite
- l'événement est associé au lieu même si l'alias n'est pas créé
- on redirige vers l'événément
This commit is contained in:
Jean-Marie Favreau 2024-05-01 15:46:57 +02:00
parent 0de957cf8e
commit f226d3cac6

View File

@ -1229,6 +1229,7 @@ class UnknownPlaceAddView(PermissionRequiredMixin, SuccessMessageMixin, UpdateVi
def form_valid(self, form):
self.modified_event = form.cleaned_data.get('place')
self.add_alias = form.cleaned_data.get("add_alias")
result = super().form_valid(form)
if form.cleaned_data.get('place'):
@ -1251,7 +1252,8 @@ class UnknownPlaceAddView(PermissionRequiredMixin, SuccessMessageMixin, UpdateVi
if self.modified_event:
return reverse_lazy('view_unknown_places')
else:
return reverse_lazy('add_place_from_event', args=[self.object.pk])
param = "?add=1" if self.add_alias else ""
return reverse_lazy('add_place_from_event', args=[self.object.pk]) + param
class PlaceFromEventCreateView(PlaceCreateView):
@ -1264,7 +1266,15 @@ class PlaceFromEventCreateView(PlaceCreateView):
def get_initial(self, *args, **kwargs):
initial = super().get_initial(**kwargs)
self.event = get_object_or_404(Event, pk=self.kwargs['pk'])
if self.event.location:
if self.event.location and "add" in self.request.GET:
initial['aliases'] = [self.event.location]
return initial
def form_valid(self, form):
result = super().form_valid(form)
self.event.exact_location = form.instance
self.event.save()
return result
def get_success_url(self):
return self.event.get_absolute_url()