1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2025-01-30 18:13:01 +00:00
med/users/forms.py

58 lines
1.5 KiB
Python
Raw Normal View History

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