mirror of https://gitlab.crans.org/bde/nk20
Distinguish new and old members
This commit is contained in:
parent
080510bcf2
commit
96ad5385b0
|
@ -5,7 +5,7 @@ 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, BooleanField
|
from django.db.models import Q
|
||||||
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
|
||||||
|
@ -33,7 +33,6 @@ class UserCreateView(CreateView):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
form_class = SignUpForm
|
form_class = SignUpForm
|
||||||
success_url = reverse_lazy('registration:email_validation_sent')
|
|
||||||
template_name = 'registration/signup.html'
|
template_name = 'registration/signup.html'
|
||||||
second_form = ProfileForm
|
second_form = ProfileForm
|
||||||
|
|
||||||
|
@ -46,6 +45,7 @@ class UserCreateView(CreateView):
|
||||||
wei_form = WEIRegistrationForm()
|
wei_form = WEIRegistrationForm()
|
||||||
del wei_form.fields["user"]
|
del wei_form.fields["user"]
|
||||||
del wei_form.fields["caution_check"]
|
del wei_form.fields["caution_check"]
|
||||||
|
del wei_form.fields["first_year"]
|
||||||
context["wei_form"] = wei_form
|
context["wei_form"] = wei_form
|
||||||
context["wei_registration_form"] = WEISignupForm()
|
context["wei_registration_form"] = WEISignupForm()
|
||||||
|
|
||||||
|
@ -62,6 +62,7 @@ class UserCreateView(CreateView):
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
|
|
||||||
wei_form = None
|
wei_form = None
|
||||||
|
self.wei = False
|
||||||
|
|
||||||
if "wei" in settings.INSTALLED_APPS:
|
if "wei" in settings.INSTALLED_APPS:
|
||||||
wei_signup_form = WEISignupForm(self.request.POST)
|
wei_signup_form = WEISignupForm(self.request.POST)
|
||||||
|
@ -70,10 +71,13 @@ class UserCreateView(CreateView):
|
||||||
wei_form = WEIRegistrationForm(self.request.POST)
|
wei_form = WEIRegistrationForm(self.request.POST)
|
||||||
del wei_form.fields["user"]
|
del wei_form.fields["user"]
|
||||||
del wei_form.fields["caution_check"]
|
del wei_form.fields["caution_check"]
|
||||||
|
del wei_form.fields["first_year"]
|
||||||
|
|
||||||
if not wei_form.is_valid():
|
if not wei_form.is_valid():
|
||||||
return self.form_invalid(wei_form)
|
return self.form_invalid(wei_form)
|
||||||
|
|
||||||
|
self.wei = True
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -87,15 +91,22 @@ class UserCreateView(CreateView):
|
||||||
|
|
||||||
user.profile.send_email_validation_link()
|
user.profile.send_email_validation_link()
|
||||||
|
|
||||||
if wei_form is not None:
|
if self.wei:
|
||||||
wei_registration = wei_form.instance
|
wei_registration = wei_form.instance
|
||||||
wei_registration.user = user
|
wei_registration.user = user
|
||||||
wei_registration.wei = WEIClub.objects.order_by('date_start').last()
|
wei_registration.wei = WEIClub.objects.order_by('date_start').last()
|
||||||
wei_registration.caution_check = False
|
wei_registration.caution_check = False
|
||||||
|
wei_registration.first_year = True
|
||||||
wei_registration.save()
|
wei_registration.save()
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
if self.wei:
|
||||||
|
return reverse_lazy('registration:email_validation_sent') # TODO Load WEI survey
|
||||||
|
else:
|
||||||
|
return reverse_lazy('registration:email_validation_sent')
|
||||||
|
|
||||||
|
|
||||||
class UserValidateView(TemplateView):
|
class UserValidateView(TemplateView):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.utils.translation import ugettext_lazy as _
|
|
||||||
from note_kfet.inputs import AmountInput, DatePickerInput, Autocomplete, ColorWidget
|
from note_kfet.inputs import AmountInput, DatePickerInput, Autocomplete, ColorWidget
|
||||||
|
|
||||||
from .models import WEIClub, WEIRegistration, Bus, BusTeam, WEIMembership, WEIRole
|
from .models import WEIClub, WEIRegistration, Bus, BusTeam, WEIMembership, WEIRole
|
||||||
|
|
|
@ -7,7 +7,7 @@ from django.contrib.auth.models import User
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from member.models import Role, Club, Membership
|
from member.models import Role, Club, Membership
|
||||||
from note.models import NoteSpecial, MembershipTransaction
|
from note.models import MembershipTransaction
|
||||||
|
|
||||||
|
|
||||||
class WEIClub(Club):
|
class WEIClub(Club):
|
||||||
|
@ -188,6 +188,12 @@ class WEIRegistration(models.Model):
|
||||||
verbose_name=_("Register on the mailing list to stay informed of the art events of the campus (1 mail/week)"),
|
verbose_name=_("Register on the mailing list to stay informed of the art events of the campus (1 mail/week)"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
first_year = models.BooleanField(
|
||||||
|
default=False,
|
||||||
|
verbose_name=_("first year"),
|
||||||
|
help_text=_("Tells if the user is new in the school.")
|
||||||
|
)
|
||||||
|
|
||||||
information_json = models.TextField(
|
information_json = models.TextField(
|
||||||
default="{}",
|
default="{}",
|
||||||
verbose_name=_("registration information"),
|
verbose_name=_("registration information"),
|
||||||
|
@ -210,13 +216,6 @@ class WEIRegistration(models.Model):
|
||||||
"""
|
"""
|
||||||
self.information_json = json.dumps(information)
|
self.information_json = json.dumps(information)
|
||||||
|
|
||||||
@property
|
|
||||||
def is_first_year(self):
|
|
||||||
"""
|
|
||||||
We assume that a user is a new member if it not fully registered yet.
|
|
||||||
"""
|
|
||||||
return not self.user.profile.registration_valid
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.user)
|
return str(self.user)
|
||||||
|
|
||||||
|
|
|
@ -71,16 +71,13 @@ class WEIRegistrationTable(tables.Table):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
def render_is_first_year(self, value):
|
|
||||||
return _("yes") if value else _("no")
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
attrs = {
|
attrs = {
|
||||||
'class': 'table table-condensed table-striped table-hover'
|
'class': 'table table-condensed table-striped table-hover'
|
||||||
}
|
}
|
||||||
model = WEIRegistration
|
model = WEIRegistration
|
||||||
template_name = 'django_tables2/bootstrap4.html'
|
template_name = 'django_tables2/bootstrap4.html'
|
||||||
fields = ('user', 'is_first_year',)
|
fields = ('user', 'first_year',)
|
||||||
row_attrs = {
|
row_attrs = {
|
||||||
'class': 'table-row',
|
'class': 'table-row',
|
||||||
'id': lambda record: "row-" + str(record.pk),
|
'id': lambda record: "row-" + str(record.pk),
|
||||||
|
|
|
@ -16,7 +16,7 @@ from note.tables import HistoryTable
|
||||||
from permission.backends import PermissionBackend
|
from permission.backends import PermissionBackend
|
||||||
from permission.views import ProtectQuerysetMixin
|
from permission.views import ProtectQuerysetMixin
|
||||||
|
|
||||||
from .models import WEIClub, WEIRegistration, WEIMembership, Bus, BusTeam
|
from .models import WEIClub, WEIRegistration, WEIMembership, Bus, BusTeam, WEIRole
|
||||||
from .forms import WEIForm, WEIRegistrationForm, BusForm, BusTeamForm, WEIMembershipForm
|
from .forms import WEIForm, WEIRegistrationForm, BusForm, BusTeamForm, WEIMembershipForm
|
||||||
from .tables import WEITable, WEIRegistrationTable, BusTable, BusTeamTable, WEIMembershipTable
|
from .tables import WEITable, WEIRegistrationTable, BusTable, BusTeamTable, WEIMembershipTable
|
||||||
|
|
||||||
|
@ -77,7 +77,10 @@ class WEIDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
|
||||||
context['member_list'] = membership_table
|
context['member_list'] = membership_table
|
||||||
|
|
||||||
pre_registrations = WEIRegistration.objects.filter(
|
pre_registrations = WEIRegistration.objects.filter(
|
||||||
PermissionBackend.filter_queryset(self.request.user, WEIRegistration, "view")).filter(membership=None)
|
PermissionBackend.filter_queryset(self.request.user, WEIRegistration, "view")).filter(
|
||||||
|
membership=None,
|
||||||
|
wei=club
|
||||||
|
)
|
||||||
pre_registrations_table = WEIRegistrationTable(data=pre_registrations, prefix="pre-registration-")
|
pre_registrations_table = WEIRegistrationTable(data=pre_registrations, prefix="pre-registration-")
|
||||||
pre_registrations_table.paginate(per_page=20, page=self.request.GET.get('membership-page', 1))
|
pre_registrations_table.paginate(per_page=20, page=self.request.GET.get('membership-page', 1))
|
||||||
context['pre_registrations'] = pre_registrations_table
|
context['pre_registrations'] = pre_registrations_table
|
||||||
|
@ -258,10 +261,12 @@ 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["first_year"]
|
||||||
return form
|
return form
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
form.instance.wei = WEIClub.objects.get(pk=self.kwargs["wei_pk"])
|
form.instance.wei = WEIClub.objects.get(pk=self.kwargs["wei_pk"])
|
||||||
|
form.instance.first_year = False
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
|
@ -310,6 +315,12 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Crea
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
def get_form(self, form_class=None):
|
||||||
|
form = super().get_form(form_class)
|
||||||
|
if WEIRegistration.objects.get(pk=self.kwargs["pk"]).first_year:
|
||||||
|
del form.fields["roles"]
|
||||||
|
return form
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
"""
|
"""
|
||||||
Create membership, check that all is good, make transactions
|
Create membership, check that all is good, make transactions
|
||||||
|
@ -336,7 +347,7 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Crea
|
||||||
_("This user don't have enough money to join this club, and can't have a negative balance."))
|
_("This user don't have enough money to join this club, and can't have a negative balance."))
|
||||||
return super().form_invalid(form)
|
return super().form_invalid(form)
|
||||||
|
|
||||||
if not registration.caution_check and True: # TODO: Replace it with "is 2A+"
|
if not registration.caution_check and not registration.first_year:
|
||||||
form.add_error('bus', _("This user didn't give her/his caution check."))
|
form.add_error('bus', _("This user didn't give her/his caution check."))
|
||||||
return super().form_invalid(form)
|
return super().form_invalid(form)
|
||||||
|
|
||||||
|
@ -347,6 +358,13 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Crea
|
||||||
|
|
||||||
# Now, all is fine, the membership can be created.
|
# Now, all is fine, the membership can be created.
|
||||||
|
|
||||||
|
if registration.first_year:
|
||||||
|
membership = form.instance
|
||||||
|
membership.save()
|
||||||
|
membership.refresh_from_db()
|
||||||
|
membership.roles.set(WEIRole.objects.filter(name="1A").all())
|
||||||
|
membership.save()
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
|
|
|
@ -47,6 +47,9 @@
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
<dt class="col-xl-6">{% trans 'first year'|capfirst %}</dt>
|
||||||
|
<dd class="col-xl-6">{{ registration.first_year|yesno }}</dd>
|
||||||
|
|
||||||
<dt class="col-xl-6">{% trans 'gender'|capfirst %}</dt>
|
<dt class="col-xl-6">{% trans 'gender'|capfirst %}</dt>
|
||||||
<dd class="col-xl-6">{{ registration.gender }}</dd>
|
<dd class="col-xl-6">{{ registration.gender }}</dd>
|
||||||
|
|
||||||
|
@ -74,8 +77,10 @@
|
||||||
<dt class="col-xl-6">{% trans 'Payment from Société générale' %}</dt>
|
<dt class="col-xl-6">{% trans 'Payment from Société générale' %}</dt>
|
||||||
<dd class="col-xl-6">{{ registration.soge_credit|yesno }}</dd>
|
<dd class="col-xl-6">{{ registration.soge_credit|yesno }}</dd>
|
||||||
|
|
||||||
<dt class="col-xl-6">{% trans 'caution check given'|capfirst %}</dt>
|
{% if not registration.first_year %}
|
||||||
<dd class="col-xl-6">{{ registration.caution_check|yesno }}</dd>
|
<dt class="col-xl-6">{% trans 'caution check given'|capfirst %}</dt>
|
||||||
|
<dd class="col-xl-6">{{ registration.caution_check|yesno }}</dd>
|
||||||
|
{% endif %}
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer text-center">
|
<div class="card-footer text-center">
|
||||||
|
@ -115,7 +120,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if not registration.caution_check %}
|
{% if not registration.caution_check and not registration.first_year %}
|
||||||
<div class="alert alert-danger">
|
<div class="alert alert-danger">
|
||||||
{% trans "The user didn't give her/his caution check." %}
|
{% trans "The user didn't give her/his caution check." %}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue