med/users/forms.py

77 lines
2.2 KiB
Python
Raw Normal View History

2019-08-02 12:57:53 +00:00
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django import forms
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from django.core.validators import MinLengthValidator
2019-08-02 12:57:53 +00:00
from django.forms import ModelForm, Form
from .models import Adhesion, Clef, ListRight, Right, User
class PassForm(forms.Form):
2019-08-02 12:57:53 +00:00
passwd1 = forms.CharField(label=u'Nouveau mot de passe', max_length=255, validators=[MinLengthValidator(8)],
widget=forms.PasswordInput)
passwd2 = forms.CharField(label=u'Saisir à nouveau le mot de passe', max_length=255,
validators=[MinLengthValidator(8)], widget=forms.PasswordInput)
2017-07-06 15:41:10 +00:00
class BaseInfoForm(ModelForm):
class Meta:
model = User
fields = [
2019-08-08 10:16:40 +00:00
'first_name',
2019-08-02 19:35:30 +00:00
'username',
2019-08-02 19:47:54 +00:00
'last_name',
2017-07-06 15:41:10 +00:00
'email',
'telephone',
2019-08-08 10:16:40 +00:00
'address',
2017-07-06 15:41:10 +00:00
]
2019-08-02 12:57:53 +00:00
2017-07-06 15:41:10 +00:00
class InfoForm(BaseInfoForm):
class Meta(BaseInfoForm.Meta):
2019-08-02 12:57:53 +00:00
fields = [
2019-08-08 10:16:40 +00:00
'first_name',
2019-08-02 19:35:30 +00:00
'username',
2019-08-02 19:47:54 +00:00
'last_name',
2017-07-06 15:41:10 +00:00
'email',
'telephone',
2019-08-08 10:16:40 +00:00
'address',
2017-07-06 15:41:10 +00:00
'maxemprunt',
]
class PasswordForm(ModelForm):
class Meta:
model = User
fields = ['password']
2019-08-02 12:57:53 +00:00
2017-07-06 15:41:10 +00:00
class AdhesionForm(ModelForm):
adherent = forms.ModelMultipleChoiceField(User.objects.all(), widget=forms.CheckboxSelectMultiple, required=False)
class Meta:
model = Adhesion
fields = '__all__'
2019-08-02 12:57:53 +00:00
2017-07-06 15:41:10 +00:00
class RightForm(ModelForm):
def __init__(self, *args, **kwargs):
super(RightForm, self).__init__(*args, **kwargs)
self.fields['right'].label = 'Droit'
self.fields['right'].empty_label = "Choisir un nouveau droit"
class Meta:
model = Right
fields = ['right']
class DelRightForm(Form):
2019-08-02 12:57:53 +00:00
rights = forms.ModelMultipleChoiceField(queryset=Right.objects.all(), widget=forms.CheckboxSelectMultiple)
2017-07-06 15:41:10 +00:00
def __init__(self, right, *args, **kwargs):
super(DelRightForm, self).__init__(*args, **kwargs)
self.fields['rights'].queryset = Right.objects.filter(right=right)