From 6b8e9d45fd4d5e9a2c8907467015733776e6301d Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sun, 12 Apr 2020 03:31:08 +0200 Subject: [PATCH] Pre-register 2A+ --- apps/wei/forms.py | 28 +++++++++++++++++++++++-- apps/wei/models.py | 12 +++++++++++ apps/wei/urls.py | 3 ++- apps/wei/views.py | 26 ++++++++++++++++++++--- templates/wei/weiclub_info.html | 2 +- templates/wei/weiregistration_form.html | 11 ++++++++++ 6 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 templates/wei/weiregistration_form.html diff --git a/apps/wei/forms.py b/apps/wei/forms.py index 48a0a00a..e8cd39fe 100644 --- a/apps/wei/forms.py +++ b/apps/wei/forms.py @@ -2,9 +2,11 @@ # SPDX-License-Identifier: GPL-3.0-or-later from django import forms -from note_kfet.inputs import AmountInput, DatePickerInput +from django.contrib.auth.models import User +from django.utils.translation import ugettext_lazy as _ +from note_kfet.inputs import AmountInput, DatePickerInput, Autocomplete -from .models import WEIClub +from .models import WEIClub, WEIRegistration class WEIForm(forms.ModelForm): @@ -19,3 +21,25 @@ class WEIForm(forms.ModelForm): "date_start": DatePickerInput(), "date_end": DatePickerInput(), } + + +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', ) + widgets = { + "user": Autocomplete( + User, + attrs={ + 'api_url': '/api/user/', + 'name_field': 'username', + 'placeholder': 'Nom ...', + }, + ), + "birth_date": DatePickerInput(), + } diff --git a/apps/wei/models.py b/apps/wei/models.py index 326882ca..1884308f 100644 --- a/apps/wei/models.py +++ b/apps/wei/models.py @@ -123,14 +123,22 @@ class WEIRegistration(models.Model): 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"), ) + caution_check = models.BooleanField( + default=False, + verbose_name=_("Caution check given") + ) + birth_date = models.DateField( verbose_name=_("birth date"), ) @@ -160,18 +168,22 @@ class WEIRegistration(models.Model): ) ml_events_registration = models.BooleanField( + default=False, verbose_name=_("Register on the mailing list to stay informed of the events of the campus (1 mail/week)"), ) ml_sport_registration = models.BooleanField( + default=False, verbose_name=_("Register on the mailing list to stay informed of the sport events of the campus (1 mail/week)"), ) ml_art_registration = models.BooleanField( + default=False, verbose_name=_("Register on the mailing list to stay informed of the art events of the campus (1 mail/week)"), ) information_json = models.TextField( + default="{}", verbose_name=_("registration information"), help_text=_("Information about the registration (buses for old members, survey fot the new members), " "encoded in JSON"), diff --git a/apps/wei/urls.py b/apps/wei/urls.py index bce87e1f..de10d1f4 100644 --- a/apps/wei/urls.py +++ b/apps/wei/urls.py @@ -3,7 +3,7 @@ from django.urls import path -from .views import WEIListView, WEICreateView, WEIDetailView, WEIUpdateView +from .views import WEIListView, WEICreateView, WEIDetailView, WEIUpdateView, WEIRegisterView app_name = 'wei' @@ -12,4 +12,5 @@ urlpatterns = [ path('create/', WEICreateView.as_view(), name="wei_create"), path('detail//', WEIDetailView.as_view(), name="wei_detail"), path('update//', WEIUpdateView.as_view(), name="wei_update"), + path('register//', WEIRegisterView.as_view(), name="wei_register"), ] diff --git a/apps/wei/views.py b/apps/wei/views.py index 59059d4c..ef99f9c7 100644 --- a/apps/wei/views.py +++ b/apps/wei/views.py @@ -16,8 +16,8 @@ from note.tables import HistoryTable from permission.backends import PermissionBackend from permission.views import ProtectQuerysetMixin -from .models import WEIClub -from .forms import WEIForm +from .models import WEIClub, WEIRegistration +from .forms import WEIForm, WEIRegistrationForm from .tables import WEITable @@ -48,7 +48,6 @@ class WEICreateView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView): return reverse_lazy("wei:wei_detail", kwargs={"pk": self.object.pk}) - class WEIDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView): """ View WEI information @@ -101,3 +100,24 @@ class WEIUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView): def get_success_url(self): return reverse_lazy("wei:wei_detail", kwargs={"pk": self.object.pk}) + + +class WEIRegisterView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView): + """ + Register to the WEI + """ + model = WEIRegistration + form_class = WEIRegistrationForm + + def get_form(self, form_class=None): + form = super().get_form(form_class) + form.fields["user"].initial = self.request.user + return form + + def form_valid(self, form): + ret = super().form_valid(form) + return ret + + def get_success_url(self): + self.object.refresh_from_db() + return reverse_lazy("wei:wei_detail", kwargs={"pk": self.object.pk}) diff --git a/templates/wei/weiclub_info.html b/templates/wei/weiclub_info.html index c47b9127..16f2527d 100644 --- a/templates/wei/weiclub_info.html +++ b/templates/wei/weiclub_info.html @@ -51,7 +51,7 @@