Commit 330c1d38 by Kálmán Viktor

dashboard: basic user profile

parent 1519d326
......@@ -654,3 +654,13 @@ textarea[name="list-new-namelist"] {
80% { -webkit-transform: scale(1); }
100% { -webkit-transform: scale(1); }
}
.dashboard-profile-vm-list, .dashboard-profile-group-list {
list-style: none;
padding-left: 28px;
}
.dashboard-profile-vm-list a, .dashboard-profile-vm-list a:hover {
text-decoration: none;
color: #555;
}
......@@ -49,7 +49,7 @@
</ul>
{% if user.is_authenticated %}
<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" %}" title="{% trans "User profile" %}" style="color: white; font-size: 10px;"><i class="icon-user "></i> {{user}}</a>
<a class="navbar-brand pull-right" href="{% url "dashboard.views.profile" pk=user.pk %}" title="{% trans "User profile" %}" style="color: white; font-size: 10px;"><i class="icon-user "></i> {{user}}</a>
{% if user.is_superuser %}
<a class="navbar-brand pull-right" href="/network/" style="color: white; font-size: 10px;"><i class="icon-globe"></i> {% trans "Network" %}</a>
<a class="navbar-brand pull-right" href="/admin/" style="color: white; font-size: 10px;"><i class="icon-cogs"></i> {% trans "Admin" %}</a>
......
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block title-page %}{{ profile.username}} | {% trans "Profile" %}{% endblock %}
{% 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-user"></i>
{% include "dashboard/_display-name.html" with user=profile show_org=True %}
</h3>
</div>
<div class="panel-body">
<div>
<div class="" style="float: left">
<img src="{{ avatar_url }}?s=200" class="img-rounded"/>
</div>
<div class="" style="padding-left: 215px;">
<p>Username: {{ profile.username }}</p>
<p>Organisation ID: {{ profile.profile.org_id|default:"-" }}</p>
<p>First name: {{ profile.first_name|default:"-" }}</p>
<p>Last name: {{ profile.last_name|default:"-" }}</p>
<p>Email address: {{ profile.email }}</p>
<p>
Use email address as Gravatar profile image:
<input type="checkbox"/> <a href="https://gravatar.com">What's Gravatar?</a>
</p>
</div>
<div class="clearfix"></div>
</div>
<hr />
<h4>
<i class="icon-group"></i> Groups
</h4>
<ul class="dashboard-profile-group-list">
{% for g in groups %}
<li>{{ g.name }}</li>
{% empty %}
{% trans "This user is not in any group." %}
{% endfor %}
</ul>
<hr />
<h4>
<i class="icon-desktop"></i>
Virtual machines owned by the user ({{ instances_owned|length }})
</h4>
<ul class="dashboard-profile-vm-list">
{% for i in instances_owned %}
<li>
<a href="{{ i.get_absolute_url }}">
<i class="icon-li {{ i.get_status_icon }}"></i>
{{ i }}
</a>
</li>
{% empty %}
<li>
{% trans "This user have no virtual machines." %}
</li>
{% endfor %}
</ul>
<hr />
<h4>
<i class="icon-desktop"></i>
Virtual machines with access ({{ instances_with_access|length }})
</h4>
<ul class="dashboard-profile-vm-list">
{% for i in instances_with_access %}
<li>
<a href="{{ i.get_absolute_url }}">
<i class="icon-li {{ i.get_status_icon }}"></i>
{{ i }}
</a>
</li>
{% empty %}
<li>
{% trans "This user have no access to any virtual machine." %}
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
{% endblock %}
......@@ -34,6 +34,7 @@ from .views import (
GroupCreate,
TemplateChoose,
UserCreationView,
ProfileView,
)
urlpatterns = patterns(
......@@ -132,8 +133,9 @@ urlpatterns = patterns(
url(r'^interface/(?P<pk>\d+)/delete/$', InterfaceDeleteView.as_view(),
name="dashboard.views.interface-delete"),
url(r'^profile/$', MyPreferencesView.as_view(),
url(r'^profile/(?P<pk>\d+)$', ProfileView.as_view(),
name="dashboard.views.profile"),
url(r'^group/(?P<group_pk>\d+)/remove/acl/user/(?P<member_pk>\d+)/$',
GroupRemoveAclUserView.as_view(),
name="dashboard.views.remove-acluser"),
......
......@@ -21,6 +21,7 @@ from os import getenv
import json
import logging
import re
from hashlib import md5
import requests
from django.conf import settings
......@@ -2649,3 +2650,36 @@ class InterfaceDeleteView(DeleteView):
if redirect:
return redirect
self.object.instance.get_absolute_url()
class ProfileView(DetailView):
template_name = "dashboard/profile.html"
model = User
def get_context_data(self, **kwargs):
context = super(ProfileView, self).get_context_data(**kwargs)
context['profile'] = self.get_object()
context['avatar_url'] = self.get_avatar_url()
context['instances_owned'] = Instance.get_objects_with_level(
"owner", self.get_object(), disregard_superuser=True
).filter(destroyed_at=None)
context['instances_with_access'] = [
inst for inst in Instance.get_objects_with_level(
"user", self.get_object(), disregard_superuser=True
).filter(destroyed_at=None)
if inst not in context['instances_owned']
]
group_profiles = GroupProfile.get_objects_with_level(
"operator", self.request.user)
groups = Group.objects.filter(groupprofile__in=group_profiles)
context['groups'] = [
g for g in self.get_object().groups.all() if g in groups
]
return context
def get_avatar_url(self):
user = self.get_object()
gravatar_hash = md5(user.email).hexdigest()
return "https://gravatar.com/avatar/%s" % gravatar_hash
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