Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
00f306dc
authored
Apr 08, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: change password on profile page
parent
ddffdf96
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
8 deletions
+68
-8
circle/dashboard/forms.py
+13
-1
circle/dashboard/templates/dashboard/profile_form.html
+14
-1
circle/dashboard/views.py
+41
-6
No files found.
circle/dashboard/forms.py
View file @
00f306dc
...
...
@@ -3,6 +3,7 @@ from datetime import timedelta
from
django.contrib.auth.models
import
User
from
django.contrib.auth.forms
import
(
AuthenticationForm
,
PasswordResetForm
,
SetPasswordForm
,
PasswordChangeForm
,
)
from
crispy_forms.helper
import
FormHelper
...
...
@@ -1013,9 +1014,20 @@ class MyProfileForm(forms.ModelForm):
def
helper
(
self
):
helper
=
FormHelper
()
helper
.
layout
=
Layout
(
'preferred_language'
,
)
helper
.
add_input
(
Submit
(
"submit"
,
_
(
"
Sav
e"
)))
helper
.
add_input
(
Submit
(
"submit"
,
_
(
"
Change languag
e"
)))
return
helper
def
save
(
self
,
*
args
,
**
kwargs
):
value
=
super
(
MyProfileForm
,
self
)
.
save
(
*
args
,
**
kwargs
)
return
value
class
CirclePasswordChangeForm
(
PasswordChangeForm
):
@property
def
helper
(
self
):
helper
=
FormHelper
()
helper
.
add_input
(
Submit
(
"submit"
,
_
(
"Change password"
),
css_class
=
"btn btn-primary"
,
css_id
=
"submit-password-button"
))
return
helper
circle/dashboard/templates/dashboard/profile_form.html
View file @
00f306dc
...
...
@@ -14,7 +14,20 @@
<h3
class=
"no-margin"
><i
class=
"icon-desktop"
></i>
{% trans "My profile" %}
</h3>
</div>
<div
class=
"panel-body"
>
{% crispy form %}
<div
class=
"row"
>
<div
class=
"col-sm-4"
style=
"margin-bottom: 50px;"
>
<fieldset>
<legend>
{% trans "Password change" %}
</legend>
{% crispy forms.change_password %}
</fieldset>
</div>
<div
class=
"col-sm-offset-5 col-sm-3"
>
<fieldset>
<legend>
{% trans "Language selection" %}
</legend>
{% crispy forms.change_language %}
</fieldset>
</div>
</div>
</div>
</div>
</div>
...
...
circle/dashboard/views.py
View file @
00f306dc
...
...
@@ -38,6 +38,7 @@ from braces.views import (
from
.forms
import
(
CircleAuthenticationForm
,
DiskAddForm
,
HostForm
,
LeaseForm
,
MyProfileForm
,
NodeForm
,
TemplateForm
,
TraitForm
,
VmCustomizeForm
,
CirclePasswordChangeForm
)
from
.tables
import
(
NodeListTable
,
NodeVmListTable
,
TemplateListTable
,
LeaseListTable
,
GroupListTable
,)
...
...
@@ -2126,9 +2127,17 @@ class DiskAddView(TemplateView):
class
MyPreferencesView
(
UpdateView
):
model
=
Profile
form_class
=
MyProfileForm
def
get_context_data
(
self
,
*
args
,
**
kwargs
):
context
=
super
(
MyPreferencesView
,
self
)
.
get_context_data
(
*
args
,
**
kwargs
)
context
[
'forms'
]
=
{
'change_password'
:
CirclePasswordChangeForm
(
user
=
self
.
request
.
user
),
'change_language'
:
MyProfileForm
(
instance
=
self
.
get_object
()),
}
return
context
def
get_object
(
self
,
queryset
=
None
):
if
self
.
request
.
user
.
is_anonymous
():
...
...
@@ -2138,10 +2147,36 @@ class MyPreferencesView(UpdateView):
except
Profile
.
DoesNotExist
:
raise
Http404
(
_
(
"You don't have a profile."
))
def
form_valid
(
self
,
form
):
response
=
super
(
MyPreferencesView
,
self
)
.
form_valid
(
form
)
set_language_cookie
(
self
.
request
,
response
)
return
response
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
ojbect
=
self
.
get_object
()
redirect_response
=
HttpResponseRedirect
(
reverse
(
"dashboard.views.profile"
))
if
"preferred_language"
in
request
.
POST
:
form
=
MyProfileForm
(
request
.
POST
,
instance
=
self
.
get_object
())
if
form
.
is_valid
():
lang
=
form
.
cleaned_data
.
get
(
"preferred_language"
)
set_language_cookie
(
self
.
request
,
redirect_response
,
lang
)
form
.
save
()
else
:
form
=
CirclePasswordChangeForm
(
user
=
request
.
user
,
data
=
request
.
POST
)
if
form
.
is_valid
():
form
.
save
()
if
form
.
is_valid
():
return
redirect_response
else
:
return
self
.
get
(
request
,
form
=
form
,
*
args
,
**
kwargs
)
def
get
(
self
,
request
,
form
=
None
,
*
args
,
**
kwargs
):
# if this is not here, it won't work
self
.
object
=
self
.
get_object
()
context
=
self
.
get_context_data
(
*
args
,
**
kwargs
)
if
form
is
not
None
:
# a little cheating, users can't post invalid
# language selection forms (without modifying the HTML)
context
[
'forms'
][
'change_password'
]
=
form
return
self
.
render_to_response
(
context
)
def
set_language_cookie
(
request
,
response
,
lang
=
None
):
...
...
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