Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9ece75fb
authored
Jun 12, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: move get_avatar_url to model
parent
3bcecbcd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
12 deletions
+12
-12
circle/dashboard/models.py
+10
-0
circle/dashboard/views.py
+2
-12
No files found.
circle/dashboard/models.py
View file @
9ece75fb
...
...
@@ -18,6 +18,7 @@
from
__future__
import
absolute_import
from
itertools
import
chain
from
hashlib
import
md5
from
logging
import
getLogger
from
django.conf
import
settings
...
...
@@ -29,6 +30,7 @@ from django.db.models import (
DateTimeField
,
permalink
,
BooleanField
)
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
model_utils.models
import
TimeStampedModel
...
...
@@ -96,6 +98,14 @@ class Profile(Model):
return
reverse
(
"dashboard.views.profile"
,
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"
)
class
GroupProfile
(
AclBase
):
ACL_LEVELS
=
(
...
...
circle/dashboard/views.py
View file @
9ece75fb
...
...
@@ -22,7 +22,6 @@ from os import getenv
import
json
import
logging
import
re
from
hashlib
import
md5
import
requests
from
django.conf
import
settings
...
...
@@ -48,7 +47,6 @@ from django.utils.translation import ungettext as __
from
django.template.defaultfilters
import
title
as
title_filter
from
django.template.loader
import
render_to_string
from
django.template
import
RequestContext
from
django.templatetags.static
import
static
from
django.forms.models
import
inlineformset_factory
from
django_tables2
import
SingleTableView
...
...
@@ -2845,7 +2843,7 @@ class ProfileView(LoginRequiredMixin, DetailView):
context
=
super
(
ProfileView
,
self
)
.
get_context_data
(
**
kwargs
)
user
=
self
.
get_object
()
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
(
"owner"
,
user
,
disregard_superuser
=
True
)
.
filter
(
destroyed_at
=
None
)
context
[
'instances_with_access'
]
=
Instance
.
get_objects_with_level
(
...
...
@@ -2889,16 +2887,8 @@ def toggle_use_gravatar(request, **kwargs):
profile
.
use_gravatar
=
not
profile
.
use_gravatar
profile
.
save
()
new_avatar_url
=
get_user_avatar_url
(
user
)
new_avatar_url
=
user
.
profile
.
get_avatar_url
(
)
return
HttpResponse
(
json
.
dumps
({
'new_avatar_url'
:
new_avatar_url
}),
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