Commit ba8c4e9c authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

Visually indicating which field are required

parent 3c00151e
Pipeline #14171 passed with stage
in 31 seconds
......@@ -13,6 +13,7 @@ def is_username_is_email():
except AttributeError:
return False
def is_first_last_name_required():
try:
return settings.BASETHEME_BOOTSTRAP_FIRST_LAST_NAME_REQUIRED
......@@ -36,9 +37,9 @@ class CleanUsernameAndSuggestReset:
'The email already exists, if you have lost your password you can reset it '
'<a href="%s">here</a>.') % (reverse('basetheme_bootstrap:password_reset'))))
if is_first_last_name_required():
if len(f.get("first_name", ""))==0:
if len(f.get("first_name", "")) == 0:
self.add_error("email", _("First name is required"))
if len(f.get("last_name", ""))==0:
if len(f.get("last_name", "")) == 0:
self.add_error("email", _("Last name is required"))
return f
......@@ -51,12 +52,12 @@ class UserCreationFormWithMore(CleanUsernameAndSuggestReset, auth_forms.UserCrea
def __init__(self, *args, **kwargs):
super(UserCreationFormWithMore, self).__init__(*args, **kwargs)
self.fields['email'].widget.attrs.update({'required': True})
self.fields['email'].required = True
if is_username_is_email():
del self.fields['username']
if is_first_last_name_required():
self.fields['first_name'].widget.attrs.update({'required': True})
self.fields['last_name'].widget.attrs.update({'required': True})
self.fields['first_name'].required = True
self.fields['last_name'].required = True
def save(self, commit=True):
user = super().save(commit=False)
......@@ -76,10 +77,10 @@ class MyUserChangeForm(CleanUsernameAndSuggestReset, auth_forms.UserChangeForm):
super().__init__(*args, **kwargs)
if is_username_is_email():
del self.fields['username']
self.fields['email'].widget.attrs.update({'required': True})
self.fields['email'].required = True
if is_first_last_name_required():
self.fields['first_name'].widget.attrs.update({'required': True})
self.fields['last_name'].widget.attrs.update({'required': True})
self.fields['first_name'].required = True
self.fields['last_name'].required = True
def save(self, commit=True):
user = super().save(commit=False)
......
......@@ -7,7 +7,7 @@ readme = open('README.rst').read()
setup(
name='django-basetheme-bootstrap',
version='0.2.9',
version='0.2.10',
description='Django Basetheme Bootstrap',
long_description=readme,
author='Bryan Brancotte',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment