diff --git a/apps/member/forms.py b/apps/member/forms.py index 6fe95f5a..89ce3993 100644 --- a/apps/member/forms.py +++ b/apps/member/forms.py @@ -9,7 +9,7 @@ from note.models import NoteSpecial from note_kfet.inputs import Autocomplete, AmountInput, DatePickerInput from permission.models import PermissionMask -from .models import Profile, Club, Membership +from .models import Profile, Club, Membership, Role class CustomAuthenticationForm(AuthenticationForm): @@ -50,6 +50,8 @@ class ClubForm(forms.ModelForm): class MembershipForm(forms.ModelForm): + roles = forms.ModelMultipleChoiceField(queryset=Role.objects.filter(weirole=None).all()) + soge = forms.BooleanField( label=_("Inscription paid by Société Générale"), required=False, diff --git a/apps/wei/admin.py b/apps/wei/admin.py index 4e945ad5..4ebcec3a 100644 --- a/apps/wei/admin.py +++ b/apps/wei/admin.py @@ -1,2 +1,13 @@ # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later + +from django.contrib import admin + +from .models import WEIClub, WEIRegistration, WEIRole, Bus, BusTeam + + +admin.site.register(WEIClub) +admin.site.register(WEIRegistration) +admin.site.register(WEIRole) +admin.site.register(Bus) +admin.site.register(BusTeam) diff --git a/apps/wei/forms.py b/apps/wei/forms.py index e4816cc2..976284f2 100644 --- a/apps/wei/forms.py +++ b/apps/wei/forms.py @@ -6,7 +6,7 @@ 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 .models import WEIClub, WEIRegistration, Bus, BusTeam +from .models import WEIClub, WEIRegistration, Bus, BusTeam, WEIMembership, WEIRole class WEIForm(forms.ModelForm): @@ -45,6 +45,30 @@ class WEIRegistrationForm(forms.ModelForm): } +class WEIMembershipForm(forms.ModelForm): + roles = forms.ModelMultipleChoiceField(queryset=WEIRole.objects) + + class Meta: + model = WEIMembership + fields = ('roles', 'bus', 'team',) + widgets = { + "bus": Autocomplete( + Bus, + attrs={ + 'api_url': '/api/wei/bus/', + 'placeholder': 'Bus ...', + } + ), + "team": Autocomplete( + BusTeam, + attrs={ + 'api_url': '/api/wei/team/', + 'placeholder': 'Équipe ...', + } + ), + } + + class BusForm(forms.ModelForm): class Meta: model = Bus diff --git a/apps/wei/models.py b/apps/wei/models.py index 634038bb..24a1667d 100644 --- a/apps/wei/models.py +++ b/apps/wei/models.py @@ -33,6 +33,10 @@ class WEIClub(Club): """ return + class Meta: + verbose_name = _("WEI") + verbose_name_plural = _("WEI") + class Bus(models.Model): """ @@ -60,6 +64,8 @@ class Bus(models.Model): return self.name class Meta: + verbose_name = _("Bus") + verbose_name_plural = _("Buses") unique_together = ('wei', 'name',) @@ -102,14 +108,10 @@ class WEIRole(Role): """ A Role for the WEI can be bus chief, team chief, free electron, ... """ - bus = models.ForeignKey( - Bus, - on_delete=models.CASCADE, - null=True, - default=None, - related_name="roles", - verbose_name=_("bus"), - ) + + class Meta: + verbose_name = _("WEI Role") + verbose_name_plural = _("WEI Roles") class WEIRegistration(models.Model): @@ -262,3 +264,7 @@ class WEIMembership(Membership): related_name="membership", verbose_name=_("WEI registration"), ) + + class Meta: + verbose_name = _("WEI membership") + verbose_name_plural = _("WEI memberships") diff --git a/apps/wei/tables.py b/apps/wei/tables.py index 69c7babd..457b2cf1 100644 --- a/apps/wei/tables.py +++ b/apps/wei/tables.py @@ -48,7 +48,7 @@ class WEIRegistrationTable(tables.Table): } ) validate = tables.LinkColumn( - 'wei:wei_detail', + 'wei:validate_registration', args=[A('pk')], verbose_name=_("Validate"), text=_("Validate"), diff --git a/apps/wei/urls.py b/apps/wei/urls.py index ade2bae8..673a4d36 100644 --- a/apps/wei/urls.py +++ b/apps/wei/urls.py @@ -5,7 +5,7 @@ from django.urls import path from .views import WEIListView, WEICreateView, WEIDetailView, WEIUpdateView,\ BusCreateView, BusManageView, BusUpdateView, BusTeamCreateView, BusTeamManageView, BusTeamUpdateView,\ - WEIRegisterView, WEIUpdateRegistrationView + WEIRegisterView, WEIUpdateRegistrationView, WEIValidateRegistrationView app_name = 'wei' @@ -22,4 +22,5 @@ urlpatterns = [ path('update-bus-team//', BusTeamUpdateView.as_view(), name="update_bus_team"), path('register//', WEIRegisterView.as_view(), name="wei_register"), 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 5ecd4195..d21b1680 100644 --- a/apps/wei/views.py +++ b/apps/wei/views.py @@ -16,7 +16,7 @@ from permission.backends import PermissionBackend from permission.views import ProtectQuerysetMixin from .models import WEIClub, WEIRegistration, WEIMembership, Bus, BusTeam -from .forms import WEIForm, WEIRegistrationForm, BusForm, BusTeamForm +from .forms import WEIForm, WEIRegistrationForm, BusForm, BusTeamForm, WEIMembershipForm from .tables import WEITable, WEIRegistrationTable, BusTable, BusTeamTable, WEIMembershipTable @@ -257,6 +257,7 @@ 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): @@ -278,8 +279,32 @@ 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): self.object.refresh_from_db() return reverse_lazy("wei:wei_detail", kwargs={"pk": self.object.wei.pk}) + + +class WEIValidateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView): + """ + Validate WEI Registration + """ + model = WEIMembership + form_class = WEIMembershipForm + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + + registration = WEIRegistration.objects.get(pk=self.kwargs["pk"]) + context["registration"] = registration + context["club"] = registration.wei + context["fee"] = registration.wei.membership_fee_paid if registration.user.profile.paid \ + else registration.wei.membership_fee_unpaid + + return context + + def get_success_url(self): + self.object.refresh_from_db() + return reverse_lazy("wei:wei_detail", kwargs={"pk": self.object.wei.pk}) diff --git a/templates/member/club_info.html b/templates/member/club_info.html index eeebc823..59259f10 100644 --- a/templates/member/club_info.html +++ b/templates/member/club_info.html @@ -42,11 +42,11 @@ {% if "note.view_note"|has_perm:club.note %}
{% trans 'balance'|capfirst %}
-
{{ object.note.balance | pretty_money }}
+
{{ club.note.balance | pretty_money }}
{% endif %}
{% trans 'aliases'|capfirst %}
-
{{ object.note.alias_set.all|join:", " }}
+
{{ club.note.alias_set.all|join:", " }}
{% trans 'email'|capfirst %}
{{ club.email }}
diff --git a/templates/wei/weiclub_info.html b/templates/wei/weiclub_info.html index 5e62fe29..1128c4ed 100644 --- a/templates/wei/weiclub_info.html +++ b/templates/wei/weiclub_info.html @@ -27,11 +27,15 @@
{% trans 'membership fee'|capfirst %}
{{ club.membership_fee_paid|pretty_money }}
{% else %} -
{% trans 'fee (paid students)'|capfirst %}
-
{{ club.membership_fee_paid|pretty_money }}
+ {% with bde_kfet_fee=club.parent_club.membership_fee_paid|add:club.parent_club.parent_club.membership_fee_paid %} +
{% trans 'WEI fee / including BDE and Kfet fee (paid students)'|capfirst %}
+
{{ club.membership_fee_paid|pretty_money }} / {{ club.membership_fee_paid|add:bde_kfet_fee|pretty_money }}
+ {% endwith %} -
{% trans 'fee (unpaid students)'|capfirst %}
-
{{ club.membership_fee_unpaid|pretty_money }}
+ {% with bde_kfet_fee=club.parent_club.membership_fee_unpaid|add:club.parent_club.parent_club.membership_fee_unpaid %} +
{% trans 'WEI fee / including BDE and Kfet fee (unpaid students)'|capfirst %}
+
{{ club.membership_fee_unpaid|pretty_money }} / {{ club.membership_fee_unpaid|add:bde_kfet_fee|pretty_money }}
+ {% endwith %} {% endif %} {% endif %} diff --git a/templates/wei/weimembership_form.html b/templates/wei/weimembership_form.html new file mode 100644 index 00000000..1006bf78 --- /dev/null +++ b/templates/wei/weimembership_form.html @@ -0,0 +1,133 @@ +{% extends "member/noteowner_detail.html" %} +{% load crispy_forms_tags %} +{% load i18n %} +{% load pretty_money %} +{% load perms %} + +{% block profile_info %} + {% include "wei/weiclub_info.html" %} +{% endblock %} + +{% block profile_content %} +
+
+

{% trans "Review registration" %}

+
+
+
+
{% trans 'name'|capfirst %}, {% trans 'first name' %}
+
{{ registration.user.last_name }} {{ registration.user.first_name }}
+ +
{% trans 'username'|capfirst %}
+
{{ registration.user.username }}
+ +
{% trans 'email'|capfirst %}
+
{{ registration.user.email }}
+ + {% if not registration.user.profile.email_confirmed and "member.change_profile_email_confirmed"|has_perm:registration.user.profile %} +
+
+ {% trans "This user doesn't have confirmed his/her e-mail address." %} + {% trans "Click here to resend a validation link." %} +
+
+ {% endif %} + +
{% trans 'section'|capfirst %}
+
{{ registration.user.profile.section }}
+ +
{% trans 'address'|capfirst %}
+
{{ registration.user.profile.address }}
+ +
{% trans 'phone number'|capfirst %}
+
{{ registration.user.profile.phone_number }}
+ +
{% trans 'paid'|capfirst %}
+
{{ registration.user.profile.paid|yesno }}
+ +
+ +
{% trans 'gender'|capfirst %}
+
{{ registration.gender }}
+ +
{% trans 'birth date'|capfirst %}
+
{{ registration.birth_date }}
+ +
{% trans 'health issues'|capfirst %}
+
{{ registration.health_issues }}
+ +
{% trans 'emergency contact name'|capfirst %}
+
{{ registration.emergency_contact_name }}
+ +
{% trans 'emergency contact phone'|capfirst %}
+
{{ registration.emergency_contact_phone }}
+ +
{% trans 'Register on the mailing list to stay informed of the events of the campus (1 mail/week)' %}
+
{{ registration.ml_events_registration|yesno }}
+ +
{% trans 'Register on the mailing list to stay informed of the sport events of the campus (1 mail/week)' %}
+
{{ registration.ml_sport_registration|yesno }}
+ +
{% trans 'Register on the mailing list to stay informed of the art events of the campus (1 mail/week)' %}
+
{{ registration.ml_art_registration|yesno }}
+ +
{% trans 'Payment from Société générale' %}
+
{{ registration.soge_credit|yesno }}
+ +
{% trans 'caution check given'|capfirst %}
+
{{ registration.caution_check|yesno }}
+
+
+ +
+ +
+ +
+
+
+

{% trans "Validate registration" %}

+
+ {% if registration.soge_credit %} +
+ {% blocktrans %} + The WEI will be paid by Société générale. The membership will be created even if the bank didn't pay the BDE yet. + The membership transaction will be created but will be invalid. You will have to validate it once the bank + validated the creation of the account, or to change the payment method. + {% endblocktrans %} +
+ {% else %} + {% if registration.user.note.balance < fee %} +
+ {% with pretty_fee=fee|pretty_money %} + {% blocktrans with balance=registration.user.note.balance|pretty_money %} + The note don't have enough money ({{ balance }}, {{ pretty_fee }} required). The registration may fail. + {% endblocktrans %} + {% endwith %} +
+ {% else %} +
+ {% trans "The note has enough money." %} +
+ {% endif %} + {% endif %} + + {% if not registration.caution_check %} +
+ {% trans "The user didn't give her/his caution check." %} +
+ {% endif %} + +
+ {% csrf_token %} + {{ form|crispy }} +
+ +
+
+{% endblock %}