mirror of
				https://gitlab.crans.org/bde/nk20
				synced 2025-11-04 09:12:11 +01:00 
			
		
		
		
	Add WEI form on signup form
This commit is contained in:
		@@ -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))
 | 
			
		||||
            )
 | 
			
		||||
 
 | 
			
		||||
@@ -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.
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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', )
 | 
			
		||||
 
 | 
			
		||||
@@ -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"),
 | 
			
		||||
 
 | 
			
		||||
@@ -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):
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user