From 2c02c747f458066d1d499f354f7f0e3a1023a484 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 9 Sep 2021 09:23:12 +0200 Subject: [PATCH] [WEI] Fix errors when a user go to the WEI registration form while it is already registered Signed-off-by: Yohann D'ANELLO --- apps/wei/views.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/wei/views.py b/apps/wei/views.py index 6ea0ddbb..83f40f3b 100644 --- a/apps/wei/views.py +++ b/apps/wei/views.py @@ -510,6 +510,10 @@ class WEIRegister1AView(ProtectQuerysetMixin, ProtectedCreateView): # We can't register someone once the WEI is started and before the membership start date if today >= wei.date_start or today < wei.membership_start: return redirect(reverse_lazy('wei:wei_closed', args=(wei.pk,))) + # Don't register twice + if 'myself' in self.request.path and WEIRegistration.objects.filter(wei=wei, user=self.request.user).exists(): + obj = WEIRegistration.objects.get(wei=wei, user=self.request.user) + return redirect(reverse_lazy('wei:wei_update_registration', args=(obj.pk,))) return super().dispatch(request, *args, **kwargs) def get_context_data(self, **kwargs): @@ -585,6 +589,10 @@ class WEIRegister2AView(ProtectQuerysetMixin, ProtectedCreateView): # We can't register someone once the WEI is started and before the membership start date if today >= wei.date_start or today < wei.membership_start: return redirect(reverse_lazy('wei:wei_closed', args=(wei.pk,))) + # Don't register twice + if 'myself' in self.request.path and WEIRegistration.objects.filter(wei=wei, user=self.request.user).exists(): + obj = WEIRegistration.objects.get(wei=wei, user=self.request.user) + return redirect(reverse_lazy('wei:wei_update_registration', args=(obj.pk,))) return super().dispatch(request, *args, **kwargs) def get_context_data(self, **kwargs):