2018-09-01 19:57:09 +00:00
|
|
|
from django import forms
|
|
|
|
from django.contrib.auth.models import User, Group
|
2018-10-05 22:03:02 +00:00
|
|
|
from dal import autocomplete
|
|
|
|
from .models import School, CotisationHistory, WhiteListHistory
|
2018-12-16 10:20:02 +00:00
|
|
|
from preferences.models import PaymentMethod
|
2018-09-01 19:57:09 +00:00
|
|
|
|
|
|
|
class LoginForm(forms.Form):
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2019-02-28 12:18:41 +00:00
|
|
|
Form to log in.
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2018-09-01 19:57:09 +00:00
|
|
|
username = forms.CharField(max_length=255, label="Nom d'utitisateur")
|
|
|
|
password = forms.CharField(max_length=255, widget=forms.PasswordInput, label="Mot de passe")
|
|
|
|
|
|
|
|
class CreateUserForm(forms.ModelForm):
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2019-02-28 12:18:41 +00:00
|
|
|
Form to create a new user (:class:`django.contrib.auth.models.User`).
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2018-09-01 19:57:09 +00:00
|
|
|
class Meta:
|
|
|
|
model = User
|
|
|
|
fields = ("username", "last_name", "first_name", "email")
|
|
|
|
|
|
|
|
school = forms.ModelChoiceField(queryset=School.objects.all(), label="École")
|
|
|
|
|
|
|
|
class CreateGroupForm(forms.ModelForm):
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2019-02-28 12:18:41 +00:00
|
|
|
Form to create a new group (:class:`django.contrib.auth.models.Group`).
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2018-09-01 19:57:09 +00:00
|
|
|
class Meta:
|
|
|
|
model = Group
|
|
|
|
fields = ("name", )
|
|
|
|
|
|
|
|
class EditGroupForm(forms.ModelForm):
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2019-02-28 12:18:41 +00:00
|
|
|
Form to edit a group (:class:`django.contrib.auth.models.Group`).
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2018-09-01 19:57:09 +00:00
|
|
|
class Meta:
|
|
|
|
model = Group
|
|
|
|
fields = "__all__"
|
|
|
|
|
|
|
|
class SelectUserForm(forms.Form):
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2019-02-28 12:18:41 +00:00
|
|
|
Form to select a user from all users (:class:`django.contrib.auth.models.User`).
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2018-11-22 21:52:15 +00:00
|
|
|
user = forms.ModelChoiceField(queryset=User.objects.all(), required=True, label="Utilisateur", widget=autocomplete.ModelSelect2(url='users:all-users-autocomplete', attrs={'data-minimum-input-length':2}))
|
2018-10-05 22:03:02 +00:00
|
|
|
|
|
|
|
class SelectNonSuperUserForm(forms.Form):
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2019-02-28 12:18:41 +00:00
|
|
|
Form to select a user from all non-superuser users (:class:`django.contrib.auth.models.User`).
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2018-10-05 22:03:02 +00:00
|
|
|
user = forms.ModelChoiceField(queryset=User.objects.filter(is_active=True), required=True, label="Utilisateur", widget=autocomplete.ModelSelect2(url='users:non-super-users-autocomplete', attrs={'data-minimum-input-length':2}))
|
|
|
|
|
|
|
|
class SelectNonAdminUserForm(forms.Form):
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2019-02-28 12:18:41 +00:00
|
|
|
Form to select a user from all non-staff users (:class:`django.contrib.auth.models.User`).
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2018-11-22 21:52:15 +00:00
|
|
|
user = forms.ModelChoiceField(queryset=User.objects.filter(is_active=True), required=True, label="Utilisateur", widget=autocomplete.ModelSelect2(url='users:non-admin-users-autocomplete', attrs={'data-minimum-input-length':2}))
|
2018-10-05 22:03:02 +00:00
|
|
|
|
|
|
|
class GroupsEditForm(forms.ModelForm):
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2019-02-28 12:18:41 +00:00
|
|
|
Form to edit a user's list of groups (:class:`django.contrib.auth.models.User` and :class:`django.contrib.auth.models.Group`).
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2018-10-05 22:03:02 +00:00
|
|
|
class Meta:
|
|
|
|
model = User
|
|
|
|
fields = ("groups", )
|
|
|
|
|
|
|
|
class EditPasswordForm(forms.Form):
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2019-02-28 12:18:41 +00:00
|
|
|
Form to change the password of a user (:class:`django.contrib.auth.models.User`).
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2018-10-05 22:03:02 +00:00
|
|
|
password = forms.CharField(max_length=255, widget=forms.PasswordInput, label="Mot de passe actuel")
|
|
|
|
password1 = forms.CharField(max_length=255, widget=forms.PasswordInput, label="Nouveau mot de passe")
|
|
|
|
password2 = forms.CharField(max_length=255, widget=forms.PasswordInput, label="Nouveau mot de passe (répétez)")
|
|
|
|
|
|
|
|
def clean_password2(self):
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
|
|
|
Verify if the two new passwords are identical
|
|
|
|
"""
|
2018-10-05 22:03:02 +00:00
|
|
|
password1 = self.cleaned_data.get("password1")
|
|
|
|
password2 = self.cleaned_data.get("password2")
|
|
|
|
if password1 and password2 and password1 != password2:
|
|
|
|
raise forms.ValidationError("Les mots de passe ne sont pas identiques")
|
|
|
|
return password2
|
|
|
|
|
|
|
|
class addCotisationHistoryForm(forms.ModelForm):
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2019-02-28 12:18:41 +00:00
|
|
|
Form to add a :class:`users.models.CotisationHistory` to user (:class:`django.contrib.auth.models.User`).
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2018-12-16 10:20:02 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(addCotisationHistoryForm, self).__init__(*args, **kwargs)
|
|
|
|
self.fields['paymentMethod'].queryset = PaymentMethod.objects.filter(is_usable_in_cotisation=True).filter(is_active=True)
|
|
|
|
|
2018-10-05 22:03:02 +00:00
|
|
|
class Meta:
|
|
|
|
model = CotisationHistory
|
|
|
|
fields = ("cotisation", "paymentMethod")
|
|
|
|
|
|
|
|
class addWhiteListHistoryForm(forms.ModelForm):
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2019-02-28 12:18:41 +00:00
|
|
|
Form to add a :class:`users.models.WhiteListHistory` to user (:class:`django.contrib.auth.models.User`).
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2018-10-05 22:03:02 +00:00
|
|
|
class Meta:
|
|
|
|
model = WhiteListHistory
|
2019-06-23 09:06:39 +00:00
|
|
|
fields = ("duration", "reason")
|
2018-10-05 22:03:02 +00:00
|
|
|
|
|
|
|
class SchoolForm(forms.ModelForm):
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2019-02-28 12:18:41 +00:00
|
|
|
Form to add and edit a :class:`users.models.School`.
|
2018-12-02 15:28:40 +00:00
|
|
|
"""
|
2018-10-05 22:03:02 +00:00
|
|
|
class Meta:
|
|
|
|
model = School
|
2018-12-18 10:16:06 +00:00
|
|
|
fields = "__all__"
|
|
|
|
|
|
|
|
class ExportForm(forms.Form):
|
2019-02-28 12:18:41 +00:00
|
|
|
"""
|
|
|
|
Form to export list of users (:class:`django.contrib.auth.models.User`) to csv file
|
|
|
|
"""
|
2018-12-18 10:16:06 +00:00
|
|
|
QUERY_TYPE_CHOICES = (
|
|
|
|
('all', 'Tous les comptes'),
|
|
|
|
('all_active', 'Tous les comptes actifs'),
|
|
|
|
('adherent', 'Tous les adhérents'),
|
|
|
|
('adherent_active', 'Tous les adhérents actifs')
|
|
|
|
)
|
|
|
|
|
|
|
|
FIELDS_CHOICES = (
|
|
|
|
('username', 'Nom d\'utilisateur'),
|
|
|
|
('last_name', 'Nom'),
|
|
|
|
('first_name', 'Prénom'),
|
|
|
|
('email', 'Adresse mail'),
|
2018-12-18 18:01:09 +00:00
|
|
|
('school', 'École'),
|
|
|
|
('balance', 'Solde'),
|
|
|
|
('credit', 'Crédit'),
|
|
|
|
('debit', 'Débit')
|
2018-12-18 10:16:06 +00:00
|
|
|
)
|
|
|
|
query_type = forms.ChoiceField(choices=QUERY_TYPE_CHOICES, label="Ensemble de la demande")
|
2019-01-06 05:02:16 +00:00
|
|
|
fields = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices=FIELDS_CHOICES, label="Champs")
|
|
|
|
group = forms.ModelChoiceField(queryset=Group.objects.all(), empty_label="Tous les groupes", required=False, label="Groupe")
|