1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-26 18:37:12 +00:00

Register users themselves

This commit is contained in:
Yohann D'ANELLO 2020-04-18 03:55:30 +02:00
parent 0c9409fd4b
commit b62fa4cc6d
3 changed files with 21 additions and 6 deletions

View File

@ -23,6 +23,8 @@ urlpatterns = [
path('update-bus-team/<int:pk>/', BusTeamUpdateView.as_view(), name="update_bus_team"),
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('register/<int:wei_pk>/1A/myself/', WEIRegister1AView.as_view(), name="wei_register_1A_myself"),
path('register/<int:wei_pk>/2A+/myself/', WEIRegister2AView.as_view(), name="wei_register_2A_myself"),
path('edit-registration/<int:pk>/', WEIUpdateRegistrationView.as_view(), name="wei_update_registration"),
path('validate/<int:pk>/', WEIValidateRegistrationView.as_view(), name="validate_registration"),
]

View File

@ -6,9 +6,8 @@ from datetime import datetime, date
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import User
from django.db.models import Q
from django.shortcuts import redirect
from django.urls import reverse_lazy
from django.views.generic import DetailView, UpdateView, CreateView, View
from django.views.generic import DetailView, UpdateView, CreateView, RedirectView
from django.utils.translation import gettext_lazy as _
from django_tables2 import SingleTableView
from member.models import Membership, Club
@ -22,10 +21,10 @@ from .forms import WEIForm, WEIRegistrationForm, BusForm, BusTeamForm, WEIMember
from .tables import WEITable, WEIRegistrationTable, BusTable, BusTeamTable, WEIMembershipTable
class CurrentWEIDetailView(LoginRequiredMixin, View):
def get(self, *args, **kwargs):
class CurrentWEIDetailView(LoginRequiredMixin, RedirectView):
def get_redirect_url(self, *args, **kwargs):
wei = WEIClub.objects.order_by('date_start').last()
return redirect(reverse_lazy('wei:wei_detail', args=(wei.pk,)))
return reverse_lazy('wei:wei_detail', args=(wei.pk,))
class WEIListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
@ -122,6 +121,8 @@ class WEIDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
)
context["can_add_bus"] = PermissionBackend.check_perm(self.request.user, "wei.add_bus", empty_bus)
context["not_first_year"] = WEIMembership.objects.filter(user=self.request.user).exists()
return context
@ -288,6 +289,8 @@ class WEIRegister1AView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView):
def get_form(self, form_class=None):
form = super().get_form(form_class)
form.fields["user"].initial = self.request.user
if "myself" in self.request.path:
form.fields["user"].disabled = True
del form.fields["first_year"]
del form.fields["caution_check"]
return form
@ -319,10 +322,17 @@ class WEIRegister2AView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView):
def get_form(self, form_class=None):
form = super().get_form(form_class)
form.fields["user"].initial = self.request.user
if "myself" in self.request.path:
form.fields["user"].disabled = True
if self.request.user.profile.soge:
form.fields["soge_credit"].disabled = True
form.fields["soge_credit"].help_text = _("You already opened an account in the Société générale.")
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

@ -59,7 +59,10 @@
{% if club.is_current_wei %}
<div class="card-footer text-center">
{% if not my_registration %}
<a href="{% url "wei:wei_register_1A" wei_pk=club.pk %}"><button class="btn btn-success">{% trans "Register to the WEI!" %}</button></a>
{% if not not_first_year %}
<a href="{% url "wei:wei_register_1A_myself" wei_pk=club.pk %}"><button class="btn btn-success">{% trans "Register to the WEI! 1A" %}</button></a>
{% endif %}
<a href="{% url "wei:wei_register_2A_myself" wei_pk=club.pk %}"><button class="btn btn-success">{% trans "Register to the WEI! 2A+" %}</button></a>
{% elif my_registration.is_validated %}
<a href="{% url "wei:wei_update_registration" pk=user.pk %}"><button class="btn btn-warning">{% trans "Update my registration" %}</button></a>
{% endif %}