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
c1cb2807
authored
Jun 17, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature-profile-rework' into 'master'
Feature Profile Rework
parents
e561b9eb
561ab759
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
59 additions
and
20 deletions
+59
-20
circle/dashboard/forms.py
+9
-1
circle/dashboard/migrations/0009_use_gravatar_default_true.py
+0
-0
circle/dashboard/models.py
+26
-1
circle/dashboard/templates/base.html
+1
-1
circle/dashboard/templates/dashboard/profile.html
+1
-1
circle/dashboard/templates/dashboard/profile_form.html
+20
-4
circle/dashboard/views.py
+2
-12
No files found.
circle/dashboard/forms.py
View file @
c1cb2807
...
@@ -46,6 +46,12 @@ from vm.models import (
...
@@ -46,6 +46,12 @@ from vm.models import (
InstanceTemplate
,
Lease
,
InterfaceTemplate
,
Node
,
Trait
InstanceTemplate
,
Lease
,
InterfaceTemplate
,
Node
,
Trait
)
)
from
.models
import
Profile
,
GroupProfile
from
.models
import
Profile
,
GroupProfile
from
circle.settings.base
import
LANGUAGES
from
django.utils.translation
import
string_concat
LANGUAGES_WITH_CODE
=
((
l
[
0
],
string_concat
(
l
[
1
],
" ("
,
l
[
0
],
")"
))
for
l
in
LANGUAGES
)
class
VmSaveForm
(
forms
.
Form
):
class
VmSaveForm
(
forms
.
Form
):
...
@@ -1051,9 +1057,11 @@ class TraitForm(forms.ModelForm):
...
@@ -1051,9 +1057,11 @@ class TraitForm(forms.ModelForm):
class
MyProfileForm
(
forms
.
ModelForm
):
class
MyProfileForm
(
forms
.
ModelForm
):
preferred_language
=
forms
.
ChoiceField
(
LANGUAGES_WITH_CODE
)
class
Meta
:
class
Meta
:
fields
=
(
'preferred_language'
,
'email_notifications'
,
)
fields
=
(
'preferred_language'
,
'email_notifications'
,
'use_gravatar'
,
)
model
=
Profile
model
=
Profile
@property
@property
...
...
circle/dashboard/migrations/0009_use_gravatar_default_true.py
0 → 100644
View file @
c1cb2807
This diff is collapsed.
Click to expand it.
circle/dashboard/models.py
View file @
c1cb2807
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
from
__future__
import
absolute_import
from
__future__
import
absolute_import
from
itertools
import
chain
from
itertools
import
chain
from
hashlib
import
md5
from
logging
import
getLogger
from
logging
import
getLogger
from
django.conf
import
settings
from
django.conf
import
settings
...
@@ -29,6 +30,7 @@ from django.db.models import (
...
@@ -29,6 +30,7 @@ from django.db.models import (
DateTimeField
,
permalink
,
BooleanField
DateTimeField
,
permalink
,
BooleanField
)
)
from
django.template.loader
import
render_to_string
from
django.template.loader
import
render_to_string
from
django.templatetags.static
import
static
from
django.utils.translation
import
ugettext_lazy
as
_
,
override
,
ugettext
from
django.utils.translation
import
ugettext_lazy
as
_
,
override
,
ugettext
from
model_utils.models
import
TimeStampedModel
from
model_utils.models
import
TimeStampedModel
...
@@ -83,7 +85,9 @@ class Profile(Model):
...
@@ -83,7 +85,9 @@ class Profile(Model):
unique
=
True
,
blank
=
True
,
null
=
True
,
max_length
=
64
,
unique
=
True
,
blank
=
True
,
null
=
True
,
max_length
=
64
,
help_text
=
_
(
'Unique identifier of the person, e.g. a student number.'
))
help_text
=
_
(
'Unique identifier of the person, e.g. a student number.'
))
instance_limit
=
IntegerField
(
default
=
5
)
instance_limit
=
IntegerField
(
default
=
5
)
use_gravatar
=
BooleanField
(
default
=
False
)
use_gravatar
=
BooleanField
(
verbose_name
=
_
(
"Use Gravatar"
),
default
=
True
,
help_text
=
_
(
"Whether to use email address as Gravatar profile image"
))
email_notifications
=
BooleanField
(
email_notifications
=
BooleanField
(
verbose_name
=
_
(
"Email notifications"
),
default
=
True
,
verbose_name
=
_
(
"Email notifications"
),
default
=
True
,
help_text
=
_
(
'Whether user wants to get digested email notifications.'
))
help_text
=
_
(
'Whether user wants to get digested email notifications.'
))
...
@@ -96,6 +100,27 @@ class Profile(Model):
...
@@ -96,6 +100,27 @@ class Profile(Model):
return
reverse
(
"dashboard.views.profile"
,
return
reverse
(
"dashboard.views.profile"
,
kwargs
=
{
'username'
:
self
.
user
.
username
})
kwargs
=
{
'username'
:
self
.
user
.
username
})
def
get_avatar_url
(
self
):
if
self
.
use_gravatar
:
gravatar_hash
=
md5
(
self
.
user
.
email
)
.
hexdigest
()
return
(
"https://secure.gravatar.com/avatar/
%
s"
"?s=200"
%
gravatar_hash
)
else
:
return
static
(
"dashboard/img/avatar.png"
)
def
get_display_name
(
self
):
if
self
.
user
.
get_full_name
():
name
=
self
.
user
.
get_full_name
()
else
:
name
=
self
.
user
.
username
if
self
.
org_id
:
name
=
"
%
s (
%
s)"
%
(
name
,
self
.
org_id
)
return
name
def
__unicode__
(
self
):
return
self
.
get_display_name
()
class
GroupProfile
(
AclBase
):
class
GroupProfile
(
AclBase
):
ACL_LEVELS
=
(
ACL_LEVELS
=
(
...
...
circle/dashboard/templates/base.html
View file @
c1cb2807
...
@@ -49,7 +49,7 @@
...
@@ -49,7 +49,7 @@
</ul>
</ul>
{% if user.is_authenticated and user.pk %}
{% if user.is_authenticated and user.pk %}
<a
class=
"navbar-brand pull-right"
href=
"{% url "
logout
"
%}?
next=
{%
url
"
login
"
%}"
style=
"color: white; font-size: 10px;"
><i
class=
"icon-signout icon-sign-out"
></i>
{% trans "Log out" %}
</a>
<a
class=
"navbar-brand pull-right"
href=
"{% url "
logout
"
%}?
next=
{%
url
"
login
"
%}"
style=
"color: white; font-size: 10px;"
><i
class=
"icon-signout icon-sign-out"
></i>
{% trans "Log out" %}
</a>
<a
class=
"navbar-brand pull-right"
href=
"{% url "
dashboard
.
views
.
profile
"
username=
user.username
%}"
<a
class=
"navbar-brand pull-right"
href=
"{% url "
dashboard
.
views
.
profile
-preferences
"
%}"
title=
"{% trans "
User
profile
"
%}"
style=
"color: white; font-size: 10px;"
>
title=
"{% trans "
User
profile
"
%}"
style=
"color: white; font-size: 10px;"
>
<i
class=
"icon-user"
></i>
<i
class=
"icon-user"
></i>
{% include "dashboard/_display-name.html" with user=user show_org=True %}
{% include "dashboard/_display-name.html" with user=user show_org=True %}
...
...
circle/dashboard/templates/dashboard/profile.html
View file @
c1cb2807
...
@@ -38,7 +38,7 @@
...
@@ -38,7 +38,7 @@
{%
if
profile
.
profile
.
use_gravatar
%}
checked=
"checked"
{%
endif
%}
{%
if
profile
.
profile
.
use_gravatar
%}
checked=
"checked"
{%
endif
%}
type=
"checkbox"
/>
<a
href=
"https://gravatar.com"
>
{% trans "What's Gravatar?" %}
</a>
type=
"checkbox"
/>
<a
href=
"https://gravatar.com"
>
{% trans "What's Gravatar?" %}
</a>
</p>
</p>
<a
href=
"{% url "
dashboard
.
views
.
profile-preferences
"
%}"
>
{% trans "Change
password and language
" %}
</a>
<a
href=
"{% url "
dashboard
.
views
.
profile-preferences
"
%}"
>
{% trans "Change
my preferences
" %}
</a>
{% endif %}
{% endif %}
</div>
</div>
<div
class=
"clearfix"
></div>
<div
class=
"clearfix"
></div>
...
...
circle/dashboard/templates/dashboard/profile_form.html
View file @
c1cb2807
...
@@ -10,23 +10,39 @@
...
@@ -10,23 +10,39 @@
<div
class=
"col-md-12"
>
<div
class=
"col-md-12"
>
<div
class=
"panel panel-default"
>
<div
class=
"panel panel-default"
>
<div
class=
"panel-heading"
>
<div
class=
"panel-heading"
>
<a
class=
"pull-right btn btn-default btn-xs"
href=
"{% url "
dashboard
.
index
"
%}"
>
{% trans "Back" %}
</a>
<a
class=
"pull-right btn btn-default btn-xs"
href=
"{% url "
dashboard
.
views
.
profile
"
username=
object.user.username
%}"
>
{% trans "Go to my profile" %}
</a>
<h3
class=
"no-margin"
><i
class=
"icon-desktop"
></i>
{% trans "My profile" %}
</h3>
<h3
class=
"no-margin"
><i
class=
"icon-desktop"
></i>
{% trans "My profile" %}
</h3>
</div>
</div>
<div
class=
"panel-body"
>
<div
class=
"panel-body"
>
<div
class=
"row"
>
<div
class=
"row"
>
<div
class=
"col-
sm
-4"
style=
"margin-bottom: 50px;"
>
<div
class=
"col-
md
-4"
style=
"margin-bottom: 50px;"
>
<fieldset>
<fieldset>
<legend>
{% trans "Password change" %}
</legend>
<legend>
{% trans "Password change" %}
</legend>
{% crispy forms.change_password %}
{% crispy forms.change_password %}
</fieldset>
</fieldset>
</div>
</div>
<div
class=
"col-
sm-offset-5 col-sm-3
"
>
<div
class=
"col-
md-4"
style=
"margin-bottom: 50px;
"
>
<fieldset>
<fieldset>
<legend>
{% trans "
Language selection
" %}
</legend>
<legend>
{% trans "
My preferences
" %}
</legend>
{% crispy forms.change_language %}
{% crispy forms.change_language %}
</fieldset>
</fieldset>
</div>
</div>
<div
class=
"col-md-4"
>
<fieldset>
<legend>
{% trans "Current avatar" %}
</legend>
<p>
<img
id=
"dashboard-profile-avatar"
class=
"img-rounded"
src=
"{{ object.get_avatar_url }}"
/>
</p>
<p>
<a
href=
"{% url "
dashboard
.
views
.
profile
"
username=
profile.user.username
%}"
>
{% trans "Go to my profile" %}
</a>
</p>
</fieldset>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
...
...
circle/dashboard/views.py
View file @
c1cb2807
...
@@ -22,7 +22,6 @@ from os import getenv
...
@@ -22,7 +22,6 @@ from os import getenv
import
json
import
json
import
logging
import
logging
import
re
import
re
from
hashlib
import
md5
import
requests
import
requests
from
django.conf
import
settings
from
django.conf
import
settings
...
@@ -47,7 +46,6 @@ from django.utils.translation import ugettext as _
...
@@ -47,7 +46,6 @@ from django.utils.translation import ugettext as _
from
django.utils.translation
import
ungettext
as
__
from
django.utils.translation
import
ungettext
as
__
from
django.template.loader
import
render_to_string
from
django.template.loader
import
render_to_string
from
django.template
import
RequestContext
from
django.template
import
RequestContext
from
django.templatetags.static
import
static
from
django.forms.models
import
inlineformset_factory
from
django.forms.models
import
inlineformset_factory
from
django_tables2
import
SingleTableView
from
django_tables2
import
SingleTableView
...
@@ -2818,7 +2816,7 @@ class ProfileView(LoginRequiredMixin, DetailView):
...
@@ -2818,7 +2816,7 @@ class ProfileView(LoginRequiredMixin, DetailView):
context
=
super
(
ProfileView
,
self
)
.
get_context_data
(
**
kwargs
)
context
=
super
(
ProfileView
,
self
)
.
get_context_data
(
**
kwargs
)
user
=
self
.
get_object
()
user
=
self
.
get_object
()
context
[
'profile'
]
=
user
context
[
'profile'
]
=
user
context
[
'avatar_url'
]
=
get_user_avatar_url
(
user
)
context
[
'avatar_url'
]
=
user
.
profile
.
get_avatar_url
(
)
context
[
'instances_owned'
]
=
Instance
.
get_objects_with_level
(
context
[
'instances_owned'
]
=
Instance
.
get_objects_with_level
(
"owner"
,
user
,
disregard_superuser
=
True
)
.
filter
(
destroyed_at
=
None
)
"owner"
,
user
,
disregard_superuser
=
True
)
.
filter
(
destroyed_at
=
None
)
context
[
'instances_with_access'
]
=
Instance
.
get_objects_with_level
(
context
[
'instances_with_access'
]
=
Instance
.
get_objects_with_level
(
...
@@ -2862,16 +2860,8 @@ def toggle_use_gravatar(request, **kwargs):
...
@@ -2862,16 +2860,8 @@ def toggle_use_gravatar(request, **kwargs):
profile
.
use_gravatar
=
not
profile
.
use_gravatar
profile
.
use_gravatar
=
not
profile
.
use_gravatar
profile
.
save
()
profile
.
save
()
new_avatar_url
=
get_user_avatar_url
(
user
)
new_avatar_url
=
user
.
profile
.
get_avatar_url
(
)
return
HttpResponse
(
return
HttpResponse
(
json
.
dumps
({
'new_avatar_url'
:
new_avatar_url
}),
json
.
dumps
({
'new_avatar_url'
:
new_avatar_url
}),
content_type
=
"application/json"
,
content_type
=
"application/json"
,
)
)
def
get_user_avatar_url
(
user
):
if
user
.
profile
.
use_gravatar
:
gravatar_hash
=
md5
(
user
.
email
)
.
hexdigest
()
return
"https://secure.gravatar.com/avatar/
%
s?s=200"
%
gravatar_hash
else
:
return
static
(
"dashboard/img/avatar.png"
)
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