Add a link to register 1A

This commit is contained in:
Yohann D'ANELLO 2020-04-17 21:48:50 +02:00
parent 6d0ae80610
commit d7da876a23
3 changed files with 45 additions and 5 deletions

View File

@ -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/<int:pk>/', BusTeamCreateView.as_view(), name="add_team"),
path('manage-bus-team/<int:pk>/', BusTeamManageView.as_view(), name="manage_bus_team"),
path('update-bus-team/<int:pk>/', BusTeamUpdateView.as_view(), name="update_bus_team"),
path('register/<int:wei_pk>/', WEIRegisterView.as_view(), name="wei_register"),
path('register/<int:wei_pk>/1A/', WEIRegister1AView.as_view(), name="wei_register_1A"),
path('register/<int:wei_pk>/2A+/', WEIRegister2AView.as_view(), name="wei_register_2A"),
path('edit-registration/<int:pk>/', WEIUpdateRegistrationView.as_view(), name="wei_update_registration"),
path('validate/<int:pk>/', WEIValidateRegistrationView.as_view(), name="validate_registration"),
]

View File

@ -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):

View File

@ -55,7 +55,8 @@
</div>
<div class="card-footer text-center">
{% if can_add_members %}
<a class="btn btn-primary btn-sm my-1" href="{% url 'wei:wei_register' wei_pk=club.pk %}"> {% trans "Register 2A+" %}</a>
<a class="btn btn-primary btn-sm my-1" href="{% url 'wei:wei_register_1A' wei_pk=club.pk %}"> {% trans "Register 1A" %}</a>
<a class="btn btn-primary btn-sm my-1" href="{% url 'wei:wei_register_2A' wei_pk=club.pk %}"> {% trans "Register 2A+" %}</a>
{% endif %}
{% if ".change_"|has_perm:club %}
<a class="btn btn-primary btn-sm my-1" href="{% url 'wei:wei_update' pk=club.pk %}"> {% trans "Edit" %}</a>