mirror of https://gitlab.crans.org/bde/nk20
Add WEI form on signup form
This commit is contained in:
parent
db67598b25
commit
080510bcf2
|
@ -165,7 +165,7 @@ class UserListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
||||||
Q(first_name__iregex=pattern)
|
Q(first_name__iregex=pattern)
|
||||||
| Q(last_name__iregex=pattern)
|
| Q(last_name__iregex=pattern)
|
||||||
| Q(profile__section__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__name__iregex="^" + pattern)
|
||||||
| Q(note__alias__normalized_name__iregex=Alias.normalize("^" + pattern))
|
| Q(note__alias__normalized_name__iregex=Alias.normalize("^" + pattern))
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,15 @@ class SignUpForm(UserCreationForm):
|
||||||
fields = ('first_name', 'last_name', 'username', 'email', )
|
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):
|
class ValidationForm(forms.Form):
|
||||||
"""
|
"""
|
||||||
Validate the inscription of the new users and pay memberships.
|
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.mixins import LoginRequiredMixin
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.exceptions import ValidationError
|
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.shortcuts import resolve_url, redirect
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.utils.http import urlsafe_base64_decode
|
from django.utils.http import urlsafe_base64_decode
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.views import View
|
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.views.generic.edit import FormMixin
|
||||||
from django_tables2 import SingleTableView
|
from django_tables2 import SingleTableView
|
||||||
from member.forms import ProfileForm
|
from member.forms import ProfileForm
|
||||||
|
@ -20,8 +20,9 @@ from note.models import SpecialTransaction, NoteSpecial
|
||||||
from note.templatetags.pretty_money import pretty_money
|
from note.templatetags.pretty_money import pretty_money
|
||||||
from permission.backends import PermissionBackend
|
from permission.backends import PermissionBackend
|
||||||
from permission.views import ProtectQuerysetMixin
|
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 .tables import FutureUserTable
|
||||||
from .tokens import email_validation_token
|
from .tokens import email_validation_token
|
||||||
|
|
||||||
|
@ -40,6 +41,14 @@ class UserCreateView(CreateView):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context["profile_form"] = self.second_form()
|
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
|
return context
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
|
@ -52,6 +61,19 @@ class UserCreateView(CreateView):
|
||||||
if not profile_form.is_valid():
|
if not profile_form.is_valid():
|
||||||
return self.form_invalid(form)
|
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
|
# Save the user and the profile
|
||||||
user = form.save(commit=False)
|
user = form.save(commit=False)
|
||||||
user.is_active = False
|
user.is_active = False
|
||||||
|
@ -65,6 +87,13 @@ class UserCreateView(CreateView):
|
||||||
|
|
||||||
user.profile.send_email_validation_link()
|
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)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
|
@ -112,7 +141,7 @@ class UserValidateView(TemplateView):
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**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)
|
context['login_url'] = resolve_url(settings.LOGIN_URL)
|
||||||
if self.validlink:
|
if self.validlink:
|
||||||
context['validlink'] = True
|
context['validlink'] = True
|
||||||
|
|
|
@ -24,11 +24,6 @@ class WEIForm(forms.ModelForm):
|
||||||
|
|
||||||
|
|
||||||
class WEIRegistrationForm(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:
|
class Meta:
|
||||||
model = WEIRegistration
|
model = WEIRegistration
|
||||||
exclude = ('wei', 'information_json', )
|
exclude = ('wei', 'information_json', )
|
||||||
|
|
|
@ -133,16 +133,6 @@ class WEIRegistration(models.Model):
|
||||||
verbose_name=_("WEI"),
|
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(
|
soge_credit = models.BooleanField(
|
||||||
default=False,
|
default=False,
|
||||||
verbose_name=_("Credit from Société générale"),
|
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):
|
def get_form(self, form_class=None):
|
||||||
form = super().get_form(form_class)
|
form = super().get_form(form_class)
|
||||||
form.fields["user"].initial = self.request.user
|
form.fields["user"].initial = self.request.user
|
||||||
del form.fields["payment_method"]
|
|
||||||
return form
|
return form
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
|
@ -280,7 +279,6 @@ class WEIUpdateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Update
|
||||||
def get_form(self, form_class=None):
|
def get_form(self, form_class=None):
|
||||||
form = super().get_form(form_class)
|
form = super().get_form(form_class)
|
||||||
del form.fields["user"]
|
del form.fields["user"]
|
||||||
del form.fields["payment_method"]
|
|
||||||
return form
|
return form
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load render_table from django_tables2 %}
|
{% load render_table from django_tables2 %}
|
||||||
{% load crispy_forms_tags %}
|
{% load crispy_forms_tags %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<input id="searchbar" type="text" class="form-control" placeholder="Nom/prénom/note/section ...">
|
<input id="searchbar" type="text" class="form-control" placeholder="Nom/prénom/note/section ...">
|
||||||
|
|
||||||
|
@ -11,7 +13,7 @@
|
||||||
{% render_table table %}
|
{% render_table table %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="alert alert-warning">
|
<div class="alert alert-warning">
|
||||||
{% trans "There is no pending user with this pattern." %}
|
{% trans "There is no user with this pattern." %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% if validlink %}
|
{% if validlink %}
|
||||||
{% trans "Your email have successfully been validated." %}
|
{% trans "Your email have successfully been validated." %}
|
||||||
{% if user.profile.registration_valid %}
|
{% if user_object.profile.registration_valid %}
|
||||||
{% blocktrans %}You can now <a href="{{ login_url }}">log in</a>.{% endblocktrans %}
|
{% blocktrans %}You can now <a href="{{ login_url }}">log in</a>.{% endblocktrans %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% trans "You must pay now your membership in the Kfet to complete your registration." %}
|
{% trans "You must pay now your membership in the Kfet to complete your registration." %}
|
||||||
|
|
|
@ -6,12 +6,46 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>{% trans "Sign up" %}</h2>
|
<h2>{% trans "Sign up" %}</h2>
|
||||||
|
|
||||||
|
<div class="alert alert-warning">
|
||||||
|
{% 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 %}
|
||||||
|
</div>
|
||||||
|
|
||||||
<form method="post">
|
<form method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form|crispy }}
|
{{ form|crispy }}
|
||||||
{{ profile_form|crispy }}
|
{{ profile_form|crispy }}
|
||||||
|
{{ wei_registration_form|crispy }}
|
||||||
|
<div id="wei_form_div" class="d-none">
|
||||||
|
{{ wei_form|crispy }}
|
||||||
|
</div>
|
||||||
<button class="btn btn-success" type="submit">
|
<button class="btn btn-success" type="submit">
|
||||||
{% trans "Sign up" %}
|
{% trans "Sign up" %}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block extrajavascript %}
|
||||||
|
<script>
|
||||||
|
$("#id_wei_registration").change(function () {
|
||||||
|
if ($(this).is(":checked")) {
|
||||||
|
$("#wei_form_div").removeClass('d-none');
|
||||||
|
$("#wei_form_div .form-control").removeAttr('disabled');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$("#wei_form_div").addClass('d-none');
|
||||||
|
$("#wei_form_div .form-control").attr('disabled', true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($("#id_wei_registration").is(":checked")) {
|
||||||
|
$("#wei_form_div").removeClass('d-none');
|
||||||
|
$("#wei_form_div .form-control").removeAttr('disabled');
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in New Issue