From d7da876a23915aa4dfda46024c0c2310a58a920e Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 17 Apr 2020 21:48:50 +0200 Subject: [PATCH] Add a link to register 1A --- apps/wei/urls.py | 5 ++-- apps/wei/views.py | 42 +++++++++++++++++++++++++++++++-- templates/wei/weiclub_info.html | 3 ++- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/apps/wei/urls.py b/apps/wei/urls.py index 673a4d36..cf5b2c49 100644 --- a/apps/wei/urls.py +++ b/apps/wei/urls.py @@ -5,7 +5,7 @@ from django.urls import path from .views import WEIListView, WEICreateView, WEIDetailView, WEIUpdateView,\ BusCreateView, BusManageView, BusUpdateView, BusTeamCreateView, BusTeamManageView, BusTeamUpdateView,\ - WEIRegisterView, WEIUpdateRegistrationView, WEIValidateRegistrationView + WEIRegister1AView, WEIRegister2AView, WEIUpdateRegistrationView, WEIValidateRegistrationView app_name = 'wei' @@ -20,7 +20,8 @@ urlpatterns = [ path('add-bus-team//', BusTeamCreateView.as_view(), name="add_team"), path('manage-bus-team//', BusTeamManageView.as_view(), name="manage_bus_team"), path('update-bus-team//', BusTeamUpdateView.as_view(), name="update_bus_team"), - path('register//', WEIRegisterView.as_view(), name="wei_register"), + path('register//1A/', WEIRegister1AView.as_view(), name="wei_register_1A"), + path('register//2A+/', WEIRegister2AView.as_view(), name="wei_register_2A"), path('edit-registration//', WEIUpdateRegistrationView.as_view(), name="wei_update_registration"), path('validate//', WEIValidateRegistrationView.as_view(), name="validate_registration"), ] diff --git a/apps/wei/views.py b/apps/wei/views.py index 5952608b..02153f22 100644 --- a/apps/wei/views.py +++ b/apps/wei/views.py @@ -251,17 +251,55 @@ class BusTeamManageView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView): return context -class WEIRegisterView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView): +class WEIRegister1AView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView): """ - Register to the WEI + Register a new user to the WEI """ model = WEIRegistration form_class = WEIRegistrationForm + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['title'] = _("Register 1A") + return context + def get_form(self, form_class=None): form = super().get_form(form_class) form.fields["user"].initial = self.request.user del form.fields["first_year"] + del form.fields["caution_check"] + return form + + def form_valid(self, form): + form.instance.wei = WEIClub.objects.get(pk=self.kwargs["wei_pk"]) + form.instance.first_year = True + return super().form_valid(form) + + def get_success_url(self): + self.object.refresh_from_db() + # TODO Replace it with the link of the survey + return reverse_lazy("wei:wei_detail", kwargs={"pk": self.object.wei.pk}) + + +class WEIRegister2AView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView): + """ + Register an old user to the WEI + """ + model = WEIRegistration + form_class = WEIRegistrationForm + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['title'] = _("Register 2A+") + return context + + def get_form(self, form_class=None): + form = super().get_form(form_class) + form.fields["user"].initial = self.request.user + del form.fields["first_year"] + del form.fields["ml_events_registration"] + del form.fields["ml_art_registration"] + del form.fields["ml_sport_registration"] return form def form_valid(self, form): diff --git a/templates/wei/weiclub_info.html b/templates/wei/weiclub_info.html index 1128c4ed..94bde15d 100644 --- a/templates/wei/weiclub_info.html +++ b/templates/wei/weiclub_info.html @@ -55,7 +55,8 @@