From b62fa4cc6d56ad38e9e532182eb22edc64011028 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 18 Apr 2020 03:55:30 +0200 Subject: [PATCH] Register users themselves --- apps/wei/urls.py | 2 ++ apps/wei/views.py | 20 +++++++++++++++----- templates/wei/weiclub_tables.html | 5 ++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/apps/wei/urls.py b/apps/wei/urls.py index 6f8ddbdc..e6132cbb 100644 --- a/apps/wei/urls.py +++ b/apps/wei/urls.py @@ -23,6 +23,8 @@ urlpatterns = [ path('update-bus-team//', BusTeamUpdateView.as_view(), name="update_bus_team"), path('register//1A/', WEIRegister1AView.as_view(), name="wei_register_1A"), path('register//2A+/', WEIRegister2AView.as_view(), name="wei_register_2A"), + path('register//1A/myself/', WEIRegister1AView.as_view(), name="wei_register_1A_myself"), + path('register//2A+/myself/', WEIRegister2AView.as_view(), name="wei_register_2A_myself"), 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 11db686a..b7e822f6 100644 --- a/apps/wei/views.py +++ b/apps/wei/views.py @@ -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): diff --git a/templates/wei/weiclub_tables.html b/templates/wei/weiclub_tables.html index 7f59a0b6..1671bf7e 100644 --- a/templates/wei/weiclub_tables.html +++ b/templates/wei/weiclub_tables.html @@ -59,7 +59,10 @@ {% if club.is_current_wei %}