1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-12-24 00:12:23 +00:00
nk20/apps/member/forms.py

80 lines
2.4 KiB
Python
Raw Normal View History

2020-02-18 20:30:26 +00:00
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
2019-07-08 11:59:31 +00:00
# SPDX-License-Identifier: GPL-3.0-or-later
2020-02-18 20:30:26 +00:00
2020-03-07 21:28:59 +00:00
from django import forms
2020-03-19 15:12:52 +00:00
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
2019-08-11 14:22:52 +00:00
from django.contrib.auth.models import User
2020-03-31 21:54:14 +00:00
from note_kfet.inputs import Autocomplete, AmountInput, DatePickerInput
2020-03-19 15:12:52 +00:00
from permission.models import PermissionMask
2020-03-20 01:14:43 +00:00
from .models import Profile, Club, Membership
2019-07-08 11:59:31 +00:00
2020-03-19 15:12:52 +00:00
class CustomAuthenticationForm(AuthenticationForm):
permission_mask = forms.ModelChoiceField(
label="Masque de permissions",
queryset=PermissionMask.objects.order_by("rank"),
empty_label=None,
)
class SignUpForm(UserCreationForm):
2020-03-07 21:28:59 +00:00
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['username'].widget.attrs.pop("autofocus", None)
2020-03-07 21:28:59 +00:00
self.fields['first_name'].widget.attrs.update({"autofocus": "autofocus"})
class Meta:
model = User
2020-02-18 11:31:15 +00:00
fields = ['first_name', 'last_name', 'username', 'email']
2019-08-11 14:22:52 +00:00
class ProfileForm(forms.ModelForm):
2019-08-11 15:52:41 +00:00
"""
A form for the extras field provided by the :model:`member.Profile` model.
2019-08-11 15:52:41 +00:00
"""
2020-03-07 21:28:59 +00:00
2019-08-11 14:22:52 +00:00
class Meta:
model = Profile
fields = '__all__'
2019-08-11 15:39:05 +00:00
exclude = ['user']
2019-08-11 21:25:27 +00:00
2020-02-18 11:31:15 +00:00
2019-08-11 21:25:27 +00:00
class ClubForm(forms.ModelForm):
class Meta:
model = Club
2020-02-18 11:31:15 +00:00
fields = '__all__'
2020-03-30 23:03:30 +00:00
widgets = {
"membership_fee_paid": AmountInput(),
"membership_fee_unpaid": AmountInput(),
"parent_club": Autocomplete(
Club,
attrs={
'api_url': '/api/members/club/',
}
),
2020-03-31 21:54:14 +00:00
"membership_start": DatePickerInput(),
"membership_end": DatePickerInput(),
2020-03-30 23:03:30 +00:00
}
class MembershipForm(forms.ModelForm):
class Meta:
model = Membership
2020-02-18 11:31:15 +00:00
fields = ('user', 'roles', 'date_start')
2020-02-08 20:40:32 +00:00
# Le champ d'utilisateur est remplacé par un champ d'auto-complétion.
# Quand des lettres sont tapées, une requête est envoyée sur l'API d'auto-complétion
# et récupère les noms d'utilisateur valides
2020-02-08 19:39:37 +00:00
widgets = {
2020-02-18 11:31:15 +00:00
'user':
Autocomplete(
User,
2020-03-07 21:28:59 +00:00
attrs={
'api_url': '/api/user/',
'name_field': 'username',
'placeholder': 'Nom ...',
2020-03-07 21:28:59 +00:00
},
),
2020-03-31 21:54:14 +00:00
'date_start': DatePickerInput(),
2020-02-08 19:39:37 +00:00
}