Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Sith
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
59
Issues
59
List
Boards
Labels
Service Desk
Milestones
Merge Requests
9
Merge Requests
9
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
AE
Sith
Commits
ebcdcf42
Commit
ebcdcf42
authored
Nov 24, 2015
by
Skia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic user profile edit form
parent
259182c1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
5 deletions
+36
-5
core/forms.py
core/forms.py
+9
-2
core/models.py
core/models.py
+11
-0
core/templates/core/user.html
core/templates/core/user.html
+1
-0
core/views.py
core/views.py
+15
-3
No files found.
core/forms.py
View file @
ebcdcf42
...
...
@@ -42,12 +42,19 @@ class LoginForm(AuthenticationForm):
params
=
{
'username'
:
self
.
username_field
.
verbose_name
},
)
class
EditUser
Form
(
UserChangeForm
):
class
UserEdit
Form
(
UserChangeForm
):
error_css_class
=
'error'
required_css_class
=
'required'
class
Meta
:
model
=
User
fields
=
(
'first_name'
,
'last_name'
,
'email'
,
'date_of_birth'
,
'groups'
,
'user_permissions'
)
fields
=
(
'first_name'
,
'last_name'
,
'nick_name'
,
'email'
,
'date_of_birth'
,
'groups'
,
'user_permissions'
,)
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
UserEditForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
def
clean_password
(
self
):
"""We never handle password in this form"""
return
class
PagePropForm
(
forms
.
ModelForm
):
...
...
core/models.py
View file @
ebcdcf42
...
...
@@ -65,6 +65,17 @@ class User(AbstractBaseUser, PermissionsMixin):
def
__str__
(
self
):
return
self
.
username
def
to_dict
(
self
):
return
self
.
__dict__
def
get_profile
(
self
):
return
{
"last_name"
:
self
.
last_name
,
"first_name"
:
self
.
first_name
,
"nick_name"
:
self
.
nick_name
,
"date_of_birth"
:
self
.
date_of_birth
,
}
def
get_full_name
(
self
):
"""
Returns the first_name plus the last_name, with a space in between.
...
...
core/templates/core/user.html
View file @
ebcdcf42
...
...
@@ -17,6 +17,7 @@ User list
<p><a
href=
"{% url 'core:user_edit' profile.id %}"
>
Edit
</a></p>
{% endif %}
<p>
You're seeing the profile of
<strong>
{{ profile.get_display_name }}
</strong></p>
<p>
{{ profile.nick_name }}
</p>
{% endif %}
{% if user_list %}
...
...
core/views.py
View file @
ebcdcf42
...
...
@@ -2,9 +2,10 @@ from django.shortcuts import render, redirect, get_object_or_404
from
django.http
import
HttpResponse
from
django.contrib.auth
import
logout
as
auth_logout
from
django.db
import
models
from
django.contrib.auth.forms
import
PasswordChangeForm
from
.models
import
User
,
Page
from
.forms
import
RegisteringForm
,
LoginForm
,
EditUser
Form
,
PageEditForm
,
PagePropForm
from
.forms
import
RegisteringForm
,
LoginForm
,
UserEdit
Form
,
PageEditForm
,
PagePropForm
import
logging
...
...
@@ -89,8 +90,19 @@ def user_edit(request, user_id=None):
if
user_id
is
not
None
:
user_id
=
int
(
user_id
)
if
request
.
user
.
is_authenticated
()
and
(
request
.
user
.
pk
==
user_id
or
request
.
user
.
is_superuser
):
context
[
'profile'
]
=
get_object_or_404
(
User
,
pk
=
user_id
)
context
[
'user_form'
]
=
EditUserForm
(
instance
=
context
[
'profile'
]).
as_p
()
p
=
get_object_or_404
(
User
,
pk
=
user_id
)
if
request
.
method
==
'POST'
:
f
=
UserEditForm
(
request
.
POST
,
instance
=
p
)
# Saving user
if
f
.
is_valid
():
f
.
save
()
context
[
'tests'
]
=
"USER_SAVED"
else
:
context
[
'tests'
]
=
"USER_NOT_SAVED"
else
:
f
=
UserEditForm
(
instance
=
p
)
context
[
'profile'
]
=
p
context
[
'user_form'
]
=
f
.
as_p
()
return
render
(
request
,
"core/edit_user.html"
,
context
)
return
user
(
request
,
user_id
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment