Commit c1cb2807 by Őry Máté

Merge branch 'feature-profile-rework' into 'master'

Feature Profile Rework
parents e561b9eb 561ab759
......@@ -46,6 +46,12 @@ from vm.models import (
InstanceTemplate, Lease, InterfaceTemplate, Node, Trait
)
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):
......@@ -1051,9 +1057,11 @@ class TraitForm(forms.ModelForm):
class MyProfileForm(forms.ModelForm):
preferred_language = forms.ChoiceField(LANGUAGES_WITH_CODE)
class Meta:
fields = ('preferred_language', 'email_notifications', )
fields = ('preferred_language', 'email_notifications',
'use_gravatar', )
model = Profile
@property
......
......@@ -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
......@@ -83,7 +85,9 @@ class Profile(Model):
unique=True, blank=True, null=True, max_length=64,
help_text=_('Unique identifier of the person, e.g. a student number.'))
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(
verbose_name=_("Email notifications"), default=True,
help_text=_('Whether user wants to get digested email notifications.'))
......@@ -96,6 +100,27 @@ 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")
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):
ACL_LEVELS = (
......
......@@ -49,7 +49,7 @@
</ul>
{% 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 "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;">
<i class="icon-user"></i>
{% include "dashboard/_display-name.html" with user=user show_org=True %}
......
......@@ -38,7 +38,7 @@
{% if profile.profile.use_gravatar %}checked="checked"{% endif %}
type="checkbox"/> <a href="https://gravatar.com">{% trans "What's Gravatar?" %}</a>
</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 %}
</div>
<div class="clearfix"></div>
......
......@@ -10,23 +10,39 @@
<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>
<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>
</div>
<div class="panel-body">
<div class="row">
<div class="col-sm-4" style="margin-bottom: 50px;">
<div class="col-md-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">
<div class="col-md-4" style="margin-bottom: 50px;">
<fieldset>
<legend>{% trans "Language selection" %}</legend>
<legend>{% trans "My preferences" %}</legend>
{% crispy forms.change_language %}
</fieldset>
</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>
......
......@@ -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
......@@ -47,7 +46,6 @@ from django.utils.translation import ugettext as _
from django.utils.translation import ungettext as __
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
......@@ -2818,7 +2816,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(
......@@ -2862,16 +2860,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")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment