Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1f152bdc
authored
Mar 17, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: add my profile view
parent
3d8b3e44
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
6 deletions
+80
-6
circle/dashboard/forms.py
+19
-0
circle/dashboard/models.py
+3
-0
circle/dashboard/templates/dashboard/profile_form.html
+20
-0
circle/dashboard/urls.py
+6
-4
circle/dashboard/views.py
+32
-2
No files found.
circle/dashboard/forms.py
View file @
1f152bdc
...
...
@@ -22,6 +22,7 @@ from storage.models import Disk, DataStore
from
vm.models
import
(
InstanceTemplate
,
Lease
,
InterfaceTemplate
,
Node
,
Trait
,
Instance
)
from
.models
import
Profile
VLANS
=
Vlan
.
objects
.
all
()
DISKS
=
Disk
.
objects
.
exclude
(
type
=
"qcow2-snap"
)
...
...
@@ -991,3 +992,21 @@ class TraitForm(forms.ModelForm):
class
Meta
:
model
=
Trait
fields
=
[
'name'
]
class
MyProfileForm
(
forms
.
ModelForm
):
class
Meta
:
fields
=
(
'preferred_language'
,
)
model
=
Profile
@property
def
helper
(
self
):
helper
=
FormHelper
()
helper
.
layout
=
Layout
(
'preferred_language'
,
)
helper
.
add_input
(
Submit
(
"submit"
,
_
(
"Save"
)))
return
helper
def
save
(
self
,
*
args
,
**
kwargs
):
value
=
super
(
MyProfileForm
,
self
)
.
save
(
*
args
,
**
kwargs
)
return
value
circle/dashboard/models.py
View file @
1f152bdc
...
...
@@ -4,6 +4,7 @@ from logging import getLogger
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
,
Group
from
django.contrib.auth.signals
import
user_logged_in
from
django.core.urlresolvers
import
reverse
from
django.db.models
import
(
Model
,
ForeignKey
,
OneToOneField
,
CharField
,
IntegerField
,
TextField
,
DateTimeField
,
...
...
@@ -69,6 +70,8 @@ class Profile(Model):
return
Notification
.
send
(
self
.
user
,
subject
,
template
,
context
,
valid_until
)
def
get_absolute_url
(
self
):
return
reverse
(
"dashboard.views.profile"
)
class
GroupProfile
(
AclBase
):
ACL_LEVELS
=
(
...
...
circle/dashboard/templates/dashboard/profile_form.html
0 → 100644
View file @
1f152bdc
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block content %}
<div
class=
"row"
>
<div
class=
"col-md-12"
>
<div
class=
"panel panel-default"
>
<div
class=
"panel-heading"
>
<a
class=
"pull-right btn btn-default btn-xs"
href=
"{% url "
dashboard
.
index
"
%}"
>
{% trans "Back" %}
</a>
<h3
class=
"no-margin"
><i
class=
"icon-desktop"
></i>
{% trans "My profile" %}
</h3>
</div>
<div
class=
"panel-body"
>
{% crispy form %}
</div>
</div>
</div>
</div>
{% endblock %}
circle/dashboard/urls.py
View file @
1f152bdc
...
...
@@ -4,10 +4,10 @@ from vm.models import Instance
from
.views
import
(
AclUpdateView
,
DiskAddView
,
FavouriteView
,
GroupAclUpdateView
,
GroupDelete
,
GroupDetailView
,
GroupList
,
GroupUserDelete
,
IndexView
,
LeaseCreate
,
LeaseDelete
,
LeaseDetail
,
NodeAddTraitView
,
NodeCreate
,
NodeDele
te
,
NodeDe
tailView
,
NodeGraphView
,
NodeList
,
NodeStatus
,
NotificationView
,
PortDelete
,
TemplateAclUpdateView
,
TemplateCreate
,
TemplateDele
te
,
TemplateDetail
,
TemplateList
,
TransferOwnershipConfirmView
,
LeaseDelete
,
LeaseDetail
,
MyPreferencesView
,
NodeAddTraitView
,
NodeCrea
te
,
NodeDe
lete
,
NodeDetailView
,
NodeGraphView
,
NodeList
,
NodeStatus
,
NotificationView
,
PortDelete
,
TemplateAclUpdateView
,
TemplateCrea
te
,
TemplateDe
lete
,
TemplateDe
tail
,
TemplateList
,
TransferOwnershipConfirmView
,
TransferOwnershipView
,
vm_activity
,
VmCreate
,
VmDelete
,
VmDetailView
,
VmDetailVncTokenView
,
VmGraphView
,
VmList
,
VmMassDelete
,
VmMigrateView
,
VmRenewView
,
...
...
@@ -97,4 +97,6 @@ urlpatterns = patterns(
url
(
r'^disk/add/$'
,
DiskAddView
.
as_view
(),
name
=
"dashboard.views.disk-add"
),
url
(
r'^profile/$'
,
MyPreferencesView
.
as_view
(),
name
=
"dashboard.views.profile"
),
)
circle/dashboard/views.py
View file @
1f152bdc
...
...
@@ -34,8 +34,8 @@ from braces.views import (
)
from
.forms
import
(
CircleAuthenticationForm
,
DiskAddForm
,
HostForm
,
LeaseForm
,
Nod
eForm
,
TemplateForm
,
TraitForm
,
VmCustomizeForm
,
CircleAuthenticationForm
,
DiskAddForm
,
HostForm
,
LeaseForm
,
MyProfil
eForm
,
NodeForm
,
TemplateForm
,
TraitForm
,
VmCustomizeForm
,
)
from
.tables
import
(
NodeListTable
,
NodeVmListTable
,
TemplateListTable
,
LeaseListTable
,
GroupListTable
,)
...
...
@@ -2042,3 +2042,33 @@ class DiskAddView(TemplateView):
r
=
obj
.
get_absolute_url
()
r
=
"
%
s#resources"
%
r
return
redirect
(
r
)
class
MyPreferencesView
(
UpdateView
):
model
=
Profile
form_class
=
MyProfileForm
def
get_object
(
self
,
queryset
=
None
):
if
self
.
request
.
user
.
is_anonymous
():
raise
PermissionDenied
()
try
:
return
self
.
request
.
user
.
profile
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
set_language_cookie
(
request
,
response
,
lang
=
None
):
if
lang
is
None
:
try
:
lang
=
request
.
user
.
profile
.
preferred_language
except
:
return
cname
=
getattr
(
settings
,
'LANGUAGE_COOKIE_NAME'
,
'django_language'
)
response
.
set_cookie
(
cname
,
lang
,
365
*
86400
)
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