diff --git a/apps/member/views.py b/apps/member/views.py index 34919597..879b103c 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -165,7 +165,7 @@ class UserListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView): Q(first_name__iregex=pattern) | Q(last_name__iregex=pattern) | Q(profile__section__iregex=pattern) - | Q(profile__username__iregex="^" + pattern) + | Q(username__iregex="^" + pattern) | Q(note__alias__name__iregex="^" + pattern) | Q(note__alias__normalized_name__iregex=Alias.normalize("^" + pattern)) ) diff --git a/apps/registration/forms.py b/apps/registration/forms.py index cba5c2ae..46559487 100644 --- a/apps/registration/forms.py +++ b/apps/registration/forms.py @@ -27,6 +27,15 @@ class SignUpForm(UserCreationForm): fields = ('first_name', 'last_name', 'username', 'email', ) +class WEISignupForm(forms.Form): + wei_registration = forms.BooleanField( + label=_("Register to the WEI"), + required=False, + help_text=_("Check this case if you want to register to the WEI. If you hesitate, you will be able to register" + " later, after validating your account in the Kfet."), + ) + + class ValidationForm(forms.Form): """ Validate the inscription of the new users and pay memberships. diff --git a/apps/registration/views.py b/apps/registration/views.py index 35391b05..31163524 100644 --- a/apps/registration/views.py +++ b/apps/registration/views.py @@ -5,13 +5,13 @@ from django.conf import settings from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.models import User from django.core.exceptions import ValidationError -from django.db.models import Q +from django.db.models import Q, BooleanField from django.shortcuts import resolve_url, redirect from django.urls import reverse_lazy from django.utils.http import urlsafe_base64_decode from django.utils.translation import gettext_lazy as _ from django.views import View -from django.views.generic import CreateView, TemplateView, DetailView, FormView +from django.views.generic import CreateView, TemplateView, DetailView from django.views.generic.edit import FormMixin from django_tables2 import SingleTableView from member.forms import ProfileForm @@ -20,8 +20,9 @@ from note.models import SpecialTransaction, NoteSpecial from note.templatetags.pretty_money import pretty_money from permission.backends import PermissionBackend from permission.views import ProtectQuerysetMixin +from wei.models import WEIClub -from .forms import SignUpForm, ValidationForm +from .forms import SignUpForm, ValidationForm, WEISignupForm from .tables import FutureUserTable from .tokens import email_validation_token @@ -40,6 +41,14 @@ class UserCreateView(CreateView): context = super().get_context_data(**kwargs) context["profile_form"] = self.second_form() + if "wei" in settings.INSTALLED_APPS: + from wei.forms import WEIRegistrationForm + wei_form = WEIRegistrationForm() + del wei_form.fields["user"] + del wei_form.fields["caution_check"] + context["wei_form"] = wei_form + context["wei_registration_form"] = WEISignupForm() + return context def form_valid(self, form): @@ -52,6 +61,19 @@ class UserCreateView(CreateView): if not profile_form.is_valid(): return self.form_invalid(form) + wei_form = None + + if "wei" in settings.INSTALLED_APPS: + wei_signup_form = WEISignupForm(self.request.POST) + if wei_signup_form.is_valid() and wei_signup_form.cleaned_data["wei_registration"]: + from wei.forms import WEIRegistrationForm + wei_form = WEIRegistrationForm(self.request.POST) + del wei_form.fields["user"] + del wei_form.fields["caution_check"] + + if not wei_form.is_valid(): + return self.form_invalid(wei_form) + # Save the user and the profile user = form.save(commit=False) user.is_active = False @@ -65,6 +87,13 @@ class UserCreateView(CreateView): user.profile.send_email_validation_link() + if wei_form is not None: + wei_registration = wei_form.instance + wei_registration.user = user + wei_registration.wei = WEIClub.objects.order_by('date_start').last() + wei_registration.caution_check = False + wei_registration.save() + return super().form_valid(form) @@ -112,7 +141,7 @@ class UserValidateView(TemplateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context['user'] = self.get_user(self.kwargs["uidb64"]) + context['user_object'] = self.get_user(self.kwargs["uidb64"]) context['login_url'] = resolve_url(settings.LOGIN_URL) if self.validlink: context['validlink'] = True diff --git a/apps/wei/forms.py b/apps/wei/forms.py index 976284f2..df403ffc 100644 --- a/apps/wei/forms.py +++ b/apps/wei/forms.py @@ -24,11 +24,6 @@ class WEIForm(forms.ModelForm): class WEIRegistrationForm(forms.ModelForm): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - self.fields["payment_method"].empty_label = _("No credit, directly pay with note balance") - class Meta: model = WEIRegistration exclude = ('wei', 'information_json', ) diff --git a/apps/wei/models.py b/apps/wei/models.py index 2a351cee..4c32af4d 100644 --- a/apps/wei/models.py +++ b/apps/wei/models.py @@ -133,16 +133,6 @@ class WEIRegistration(models.Model): verbose_name=_("WEI"), ) - payment_method = models.ForeignKey( - NoteSpecial, - on_delete=models.PROTECT, - null=True, # null = no credit, paid with note - blank=True, - default=None, - related_name="+", - verbose_name=_("payment method"), - ) - soge_credit = models.BooleanField( default=False, verbose_name=_("Credit from Société générale"), diff --git a/apps/wei/views.py b/apps/wei/views.py index d84b6d62..93d89913 100644 --- a/apps/wei/views.py +++ b/apps/wei/views.py @@ -258,7 +258,6 @@ class WEIRegisterView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView): def get_form(self, form_class=None): form = super().get_form(form_class) form.fields["user"].initial = self.request.user - del form.fields["payment_method"] return form def form_valid(self, form): @@ -280,7 +279,6 @@ class WEIUpdateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Update def get_form(self, form_class=None): form = super().get_form(form_class) del form.fields["user"] - del form.fields["payment_method"] return form def get_success_url(self): diff --git a/templates/member/user_list.html b/templates/member/user_list.html index 0bcd7e89..018c479d 100644 --- a/templates/member/user_list.html +++ b/templates/member/user_list.html @@ -1,6 +1,8 @@ {% extends "base.html" %} {% load render_table from django_tables2 %} -{% load crispy_forms_tags%} +{% load crispy_forms_tags %} +{% load i18n %} + {% block content %} @@ -11,7 +13,7 @@ {% render_table table %} {% else %}
- {% trans "There is no pending user with this pattern." %} + {% trans "There is no user with this pattern." %}
{% endif %} diff --git a/templates/registration/email_validation_complete.html b/templates/registration/email_validation_complete.html index 4835cfa1..b54432f3 100644 --- a/templates/registration/email_validation_complete.html +++ b/templates/registration/email_validation_complete.html @@ -4,7 +4,7 @@ {% block content %} {% if validlink %} {% trans "Your email have successfully been validated." %} - {% if user.profile.registration_valid %} + {% if user_object.profile.registration_valid %} {% blocktrans %}You can now log in.{% endblocktrans %} {% else %} {% trans "You must pay now your membership in the Kfet to complete your registration." %} diff --git a/templates/registration/signup.html b/templates/registration/signup.html index d7b3c23e..d07187af 100644 --- a/templates/registration/signup.html +++ b/templates/registration/signup.html @@ -5,13 +5,47 @@ {% block title %}{% trans "Sign up" %}{% endblock %} {% block content %} -

{% trans "Sign up" %}

-
- {% csrf_token %} - {{ form|crispy }} - {{ profile_form|crispy }} - -
+

{% trans "Sign up" %}

+ +
+ {% blocktrans %} + If you already signed up, your registration is taken into account. The BDE must validate your account before + your can log in. You have to go to the Kfet and pay the registration fee. You must also validate your email + address by following the link you received. If you forgot to register to the WEI, then you can pre-register + to the WEI after your account get validated, so please go to the Kfet. + {% endblocktrans %} +
+ +
+ {% csrf_token %} + {{ form|crispy }} + {{ profile_form|crispy }} + {{ wei_registration_form|crispy }} +
+ {{ wei_form|crispy }} +
+ +
+{% endblock %} + +{% block extrajavascript %} + {% endblock %}