1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2024-12-26 05:02:24 +00:00
med/users/forms.py

58 lines
1.5 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
2019-08-09 20:52:47 +00:00
from django.contrib.auth.forms import UsernameField
from django.core.validators import MinLengthValidator
2019-08-08 13:35:25 +00:00
from django.forms import ModelForm
2019-08-02 12:57:53 +00:00
2019-08-08 13:35:25 +00:00
from .models import User
class PassForm(forms.Form):
2019-08-08 13:35:25 +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-02 19:35:30 +00:00
'username',
2017-07-06 15:41:10 +00:00
'email',
2019-08-08 19:51:37 +00:00
'first_name',
'last_name',
2019-08-08 10:16:40 +00:00
'address',
2019-08-08 19:51:37 +00:00
'telephone',
2017-07-06 15:41:10 +00:00
]
2019-08-09 20:52:47 +00:00
class UserCreationAdminForm(ModelForm):
"""
A form that creates a user, with no privileges,
from the given information.
"""
2019-08-10 08:44:17 +00:00
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['email'].required = True
self.fields['first_name'].required = True
self.fields['last_name'].required = True
2019-08-09 20:52:47 +00:00
class Meta:
model = User
fields = ("username", "email", "first_name", "last_name", "address",
"telephone")
field_classes = {'username': UsernameField}