Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
django-basetheme-bootstrap
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bryan BRANCOTTE
django-basetheme-bootstrap
Commits
ba8c4e9c
Commit
ba8c4e9c
authored
5 years ago
by
Bryan BRANCOTTE
Browse files
Options
Downloads
Patches
Plain Diff
Visually indicating which field are required
parent
3c00151e
No related branches found
No related tags found
No related merge requests found
Pipeline
#14171
passed
5 years ago
Stage: test
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
basetheme_bootstrap/forms.py
+9
-8
9 additions, 8 deletions
basetheme_bootstrap/forms.py
setup.py
+1
-1
1 addition, 1 deletion
setup.py
with
10 additions
and
9 deletions
basetheme_bootstrap/forms.py
+
9
−
8
View file @
ba8c4e9c
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
1
View file @
ba8c4e9c
...
...
@@ -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
'
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment