vkk.users.forms
A collection of forms for user management.
1""" 2A collection of forms for user management. 3""" 4from django.contrib.auth.forms import SetPasswordForm 5from django.forms import ModelForm, CharField, PasswordInput 6from django.core.exceptions import ValidationError 7from django.utils.translation import gettext_lazy as _ 8from .models import User 9 10 11class ConfirmNewUserForm(SetPasswordForm, ModelForm): 12 """ 13 A form for confirming a user registration. 14 """ 15 class Meta: 16 """ 17 Meta information for this form class. 18 """ 19 model = User 20 fields = ['first_name', 'last_name'] 21 22 def __init__(self, *args, **kwargs): 23 """ 24 Constructs a `ConfirmNewUserForm` object. 25 """ 26 kwargs.update({'user': kwargs['instance']}) 27 super().__init__(*args, **kwargs) 28 29 def save(self, commit=True): 30 """ 31 Saves and returns a `User` instance. 32 """ 33 instance = super().save(commit) 34 instance.is_active = True 35 if commit: 36 instance.save() 37 return instance 38 39 40class UserDetailsChangeForm(ModelForm): 41 """ 42 A form for updating some user details. 43 """ 44 class Meta: 45 """ 46 Meta information for this form class. 47 """ 48 model = User 49 fields = ['first_name', 'last_name'] 50 51 error_messages = { 52 'password_incorrect': _("Your password was entered incorrectly. Please enter it again."), 53 } 54 password = CharField( 55 label=_("Password"), 56 strip=False, 57 widget=PasswordInput( 58 attrs={'autocomplete': 'current-password', 'autofocus': True}), 59 help_text=_('Please enter your password to confirm any changes made.') 60 ) 61 62 def clean_password(self): 63 """ 64 Validates and returns a string entered in the `password` field. 65 """ 66 password = self.cleaned_data["password"] 67 if not self.instance.check_password(password): 68 raise ValidationError( 69 self.error_messages['password_incorrect'], 70 code='password_incorrect', 71 ) 72 return password
class
ConfirmNewUserForm(django.contrib.auth.forms.SetPasswordForm, django.forms.models.ModelForm):
12class ConfirmNewUserForm(SetPasswordForm, ModelForm): 13 """ 14 A form for confirming a user registration. 15 """ 16 class Meta: 17 """ 18 Meta information for this form class. 19 """ 20 model = User 21 fields = ['first_name', 'last_name'] 22 23 def __init__(self, *args, **kwargs): 24 """ 25 Constructs a `ConfirmNewUserForm` object. 26 """ 27 kwargs.update({'user': kwargs['instance']}) 28 super().__init__(*args, **kwargs) 29 30 def save(self, commit=True): 31 """ 32 Saves and returns a `User` instance. 33 """ 34 instance = super().save(commit) 35 instance.is_active = True 36 if commit: 37 instance.save() 38 return instance
A form for confirming a user registration.
ConfirmNewUserForm(*args, **kwargs)
23 def __init__(self, *args, **kwargs): 24 """ 25 Constructs a `ConfirmNewUserForm` object. 26 """ 27 kwargs.update({'user': kwargs['instance']}) 28 super().__init__(*args, **kwargs)
Constructs a ConfirmNewUserForm
object.
def
save(self, commit=True):
30 def save(self, commit=True): 31 """ 32 Saves and returns a `User` instance. 33 """ 34 instance = super().save(commit) 35 instance.is_active = True 36 if commit: 37 instance.save() 38 return instance
Saves and returns a User
instance.
declared_fields =
{'new_password1': <django.forms.fields.CharField object>, 'new_password2': <django.forms.fields.CharField object>}
base_fields =
{'first_name': <django.forms.fields.CharField object>, 'last_name': <django.forms.fields.CharField object>, 'new_password1': <django.forms.fields.CharField object>, 'new_password2': <django.forms.fields.CharField object>}
Inherited Members
- django.contrib.auth.forms.SetPasswordForm
- error_messages
- new_password1
- new_password2
- user
- clean_new_password2
- django.forms.models.BaseModelForm
- clean
- validate_unique
- django.forms.forms.BaseForm
- default_renderer
- field_order
- prefix
- use_required_attribute
- template_name_div
- template_name_p
- template_name_table
- template_name_ul
- template_name_label
- is_bound
- data
- files
- auto_id
- initial
- error_class
- label_suffix
- empty_permitted
- fields
- renderer
- order_fields
- errors
- is_valid
- add_prefix
- add_initial_prefix
- template_name
- get_context
- non_field_errors
- add_error
- has_error
- full_clean
- has_changed
- changed_data
- is_multipart
- visible_fields
- get_initial_for_field
- django.forms.utils.RenderableFormMixin
- as_p
- as_table
- as_ul
- as_div
- django.forms.utils.RenderableMixin
- render
class
ConfirmNewUserForm.Meta:
16 class Meta: 17 """ 18 Meta information for this form class. 19 """ 20 model = User 21 fields = ['first_name', 'last_name']
Meta information for this form class.
model =
<class 'vkk.users.models.User'>
class
UserDetailsChangeForm(django.forms.models.ModelForm):
41class UserDetailsChangeForm(ModelForm): 42 """ 43 A form for updating some user details. 44 """ 45 class Meta: 46 """ 47 Meta information for this form class. 48 """ 49 model = User 50 fields = ['first_name', 'last_name'] 51 52 error_messages = { 53 'password_incorrect': _("Your password was entered incorrectly. Please enter it again."), 54 } 55 password = CharField( 56 label=_("Password"), 57 strip=False, 58 widget=PasswordInput( 59 attrs={'autocomplete': 'current-password', 'autofocus': True}), 60 help_text=_('Please enter your password to confirm any changes made.') 61 ) 62 63 def clean_password(self): 64 """ 65 Validates and returns a string entered in the `password` field. 66 """ 67 password = self.cleaned_data["password"] 68 if not self.instance.check_password(password): 69 raise ValidationError( 70 self.error_messages['password_incorrect'], 71 code='password_incorrect', 72 ) 73 return password
A form for updating some user details.
error_messages =
{'password_incorrect': 'Das eingegebene Passwort ist falsch. Bitte versuchen Sie es erneut.'}
def
clean_password(self):
63 def clean_password(self): 64 """ 65 Validates and returns a string entered in the `password` field. 66 """ 67 password = self.cleaned_data["password"] 68 if not self.instance.check_password(password): 69 raise ValidationError( 70 self.error_messages['password_incorrect'], 71 code='password_incorrect', 72 ) 73 return password
Validates and returns a string entered in the password
field.
base_fields =
{'first_name': <django.forms.fields.CharField object>, 'last_name': <django.forms.fields.CharField object>, 'password': <django.forms.fields.CharField object>}
Inherited Members
- django.forms.models.BaseModelForm
- BaseModelForm
- clean
- validate_unique
- save
- django.forms.forms.BaseForm
- default_renderer
- field_order
- prefix
- use_required_attribute
- template_name_div
- template_name_p
- template_name_table
- template_name_ul
- template_name_label
- is_bound
- data
- files
- auto_id
- initial
- error_class
- label_suffix
- empty_permitted
- fields
- renderer
- order_fields
- errors
- is_valid
- add_prefix
- add_initial_prefix
- template_name
- get_context
- non_field_errors
- add_error
- has_error
- full_clean
- has_changed
- changed_data
- is_multipart
- visible_fields
- get_initial_for_field
- django.forms.utils.RenderableFormMixin
- as_p
- as_table
- as_ul
- as_div
- django.forms.utils.RenderableMixin
- render
class
UserDetailsChangeForm.Meta:
45 class Meta: 46 """ 47 Meta information for this form class. 48 """ 49 model = User 50 fields = ['first_name', 'last_name']
Meta information for this form class.
model =
<class 'vkk.users.models.User'>