Pre-register 2A+

This commit is contained in:
Yohann D'ANELLO 2020-04-12 03:31:08 +02:00
parent ea8e25a7b3
commit 6b8e9d45fd
6 changed files with 75 additions and 7 deletions

View File

@ -2,9 +2,11 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from django import forms 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): class WEIForm(forms.ModelForm):
@ -19,3 +21,25 @@ class WEIForm(forms.ModelForm):
"date_start": DatePickerInput(), "date_start": DatePickerInput(),
"date_end": 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(),
}

View File

@ -123,14 +123,22 @@ class WEIRegistration(models.Model):
NoteSpecial, NoteSpecial,
on_delete=models.PROTECT, on_delete=models.PROTECT,
null=True, # null = no credit, paid with note null=True, # null = no credit, paid with note
blank=True,
default=None,
related_name="+", related_name="+",
verbose_name=_("payment method"), verbose_name=_("payment method"),
) )
soge_credit = models.BooleanField( soge_credit = models.BooleanField(
default=False,
verbose_name=_("Credit from Société générale"), verbose_name=_("Credit from Société générale"),
) )
caution_check = models.BooleanField(
default=False,
verbose_name=_("Caution check given")
)
birth_date = models.DateField( birth_date = models.DateField(
verbose_name=_("birth date"), verbose_name=_("birth date"),
) )
@ -160,18 +168,22 @@ class WEIRegistration(models.Model):
) )
ml_events_registration = models.BooleanField( 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)"), verbose_name=_("Register on the mailing list to stay informed of the events of the campus (1 mail/week)"),
) )
ml_sport_registration = models.BooleanField( 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)"), 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( 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)"), verbose_name=_("Register on the mailing list to stay informed of the art events of the campus (1 mail/week)"),
) )
information_json = models.TextField( information_json = models.TextField(
default="{}",
verbose_name=_("registration information"), verbose_name=_("registration information"),
help_text=_("Information about the registration (buses for old members, survey fot the new members), " help_text=_("Information about the registration (buses for old members, survey fot the new members), "
"encoded in JSON"), "encoded in JSON"),

View File

@ -3,7 +3,7 @@
from django.urls import path from django.urls import path
from .views import WEIListView, WEICreateView, WEIDetailView, WEIUpdateView from .views import WEIListView, WEICreateView, WEIDetailView, WEIUpdateView, WEIRegisterView
app_name = 'wei' app_name = 'wei'
@ -12,4 +12,5 @@ urlpatterns = [
path('create/', WEICreateView.as_view(), name="wei_create"), path('create/', WEICreateView.as_view(), name="wei_create"),
path('detail/<int:pk>/', WEIDetailView.as_view(), name="wei_detail"), path('detail/<int:pk>/', WEIDetailView.as_view(), name="wei_detail"),
path('update/<int:pk>/', WEIUpdateView.as_view(), name="wei_update"), path('update/<int:pk>/', WEIUpdateView.as_view(), name="wei_update"),
path('register/<int:wei_pk>/', WEIRegisterView.as_view(), name="wei_register"),
] ]

View File

@ -16,8 +16,8 @@ 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 from .models import WEIClub, WEIRegistration
from .forms import WEIForm from .forms import WEIForm, WEIRegistrationForm
from .tables import WEITable from .tables import WEITable
@ -48,7 +48,6 @@ class WEICreateView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView):
return reverse_lazy("wei:wei_detail", kwargs={"pk": self.object.pk}) return reverse_lazy("wei:wei_detail", kwargs={"pk": self.object.pk})
class WEIDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView): class WEIDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
""" """
View WEI information View WEI information
@ -101,3 +100,24 @@ class WEIUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
def get_success_url(self): def get_success_url(self):
return reverse_lazy("wei:wei_detail", kwargs={"pk": self.object.pk}) 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})

View File

@ -51,7 +51,7 @@
</div> </div>
<div class="card-footer text-center"> <div class="card-footer text-center">
{% if can_add_members %} {% if can_add_members %}
<a class="btn btn-primary btn-sm my-1" href="{% url 'member:club_add_member' club_pk=club.pk %}"> {% trans "Register 2A+" %}</a> <a class="btn btn-primary btn-sm my-1" href="{% url 'wei:wei_register' wei_pk=club.pk %}"> {% trans "Register 2A+" %}</a>
{% endif %} {% endif %}
{% if ".change_"|has_perm:club %} {% if ".change_"|has_perm:club %}
<a class="btn btn-primary btn-sm my-1" href="{% url 'wei:wei_update' pk=club.pk %}"> {% trans "Edit" %}</a> <a class="btn btn-primary btn-sm my-1" href="{% url 'wei:wei_update' pk=club.pk %}"> {% trans "Edit" %}</a>

View File

@ -0,0 +1,11 @@
{% extends "base.html" %}
{% load static %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form|crispy }}
<button class="btn btn-primary" type="submit">{% trans "Submit" %}</button>
</form>
{% endblock %}