Commit 1f152bdc by Őry Máté

dashboard: add my profile view

parent 3d8b3e44
...@@ -22,6 +22,7 @@ from storage.models import Disk, DataStore ...@@ -22,6 +22,7 @@ from storage.models import Disk, DataStore
from vm.models import ( from vm.models import (
InstanceTemplate, Lease, InterfaceTemplate, Node, Trait, Instance InstanceTemplate, Lease, InterfaceTemplate, Node, Trait, Instance
) )
from .models import Profile
VLANS = Vlan.objects.all() VLANS = Vlan.objects.all()
DISKS = Disk.objects.exclude(type="qcow2-snap") DISKS = Disk.objects.exclude(type="qcow2-snap")
...@@ -991,3 +992,21 @@ class TraitForm(forms.ModelForm): ...@@ -991,3 +992,21 @@ class TraitForm(forms.ModelForm):
class Meta: class Meta:
model = Trait model = Trait
fields = ['name'] 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
...@@ -4,6 +4,7 @@ from logging import getLogger ...@@ -4,6 +4,7 @@ from logging import getLogger
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User, Group from django.contrib.auth.models import User, Group
from django.contrib.auth.signals import user_logged_in from django.contrib.auth.signals import user_logged_in
from django.core.urlresolvers import reverse
from django.db.models import ( from django.db.models import (
Model, ForeignKey, OneToOneField, CharField, IntegerField, TextField, Model, ForeignKey, OneToOneField, CharField, IntegerField, TextField,
DateTimeField, DateTimeField,
...@@ -69,6 +70,8 @@ class Profile(Model): ...@@ -69,6 +70,8 @@ class Profile(Model):
return Notification.send(self.user, subject, template, context, return Notification.send(self.user, subject, template, context,
valid_until) valid_until)
def get_absolute_url(self):
return reverse("dashboard.views.profile")
class GroupProfile(AclBase): class GroupProfile(AclBase):
ACL_LEVELS = ( ACL_LEVELS = (
......
{% 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 %}
...@@ -4,10 +4,10 @@ from vm.models import Instance ...@@ -4,10 +4,10 @@ from vm.models import Instance
from .views import ( from .views import (
AclUpdateView, DiskAddView, FavouriteView, GroupAclUpdateView, GroupDelete, AclUpdateView, DiskAddView, FavouriteView, GroupAclUpdateView, GroupDelete,
GroupDetailView, GroupList, GroupUserDelete, IndexView, LeaseCreate, GroupDetailView, GroupList, GroupUserDelete, IndexView, LeaseCreate,
LeaseDelete, LeaseDetail, NodeAddTraitView, NodeCreate, NodeDelete, LeaseDelete, LeaseDetail, MyPreferencesView, NodeAddTraitView, NodeCreate,
NodeDetailView, NodeGraphView, NodeList, NodeStatus, NotificationView, NodeDelete, NodeDetailView, NodeGraphView, NodeList, NodeStatus,
PortDelete, TemplateAclUpdateView, TemplateCreate, TemplateDelete, NotificationView, PortDelete, TemplateAclUpdateView, TemplateCreate,
TemplateDetail, TemplateList, TransferOwnershipConfirmView, TemplateDelete, TemplateDetail, TemplateList, TransferOwnershipConfirmView,
TransferOwnershipView, vm_activity, VmCreate, VmDelete, VmDetailView, TransferOwnershipView, vm_activity, VmCreate, VmDelete, VmDetailView,
VmDetailVncTokenView, VmGraphView, VmList, VmMassDelete, VmMigrateView, VmDetailVncTokenView, VmGraphView, VmList, VmMassDelete, VmMigrateView,
VmRenewView, VmRenewView,
...@@ -97,4 +97,6 @@ urlpatterns = patterns( ...@@ -97,4 +97,6 @@ urlpatterns = patterns(
url(r'^disk/add/$', DiskAddView.as_view(), url(r'^disk/add/$', DiskAddView.as_view(),
name="dashboard.views.disk-add"), name="dashboard.views.disk-add"),
url(r'^profile/$', MyPreferencesView.as_view(),
name="dashboard.views.profile"),
) )
...@@ -34,8 +34,8 @@ from braces.views import ( ...@@ -34,8 +34,8 @@ from braces.views import (
) )
from .forms import ( from .forms import (
CircleAuthenticationForm, DiskAddForm, HostForm, LeaseForm, NodeForm, CircleAuthenticationForm, DiskAddForm, HostForm, LeaseForm, MyProfileForm,
TemplateForm, TraitForm, VmCustomizeForm, NodeForm, TemplateForm, TraitForm, VmCustomizeForm,
) )
from .tables import (NodeListTable, NodeVmListTable, from .tables import (NodeListTable, NodeVmListTable,
TemplateListTable, LeaseListTable, GroupListTable,) TemplateListTable, LeaseListTable, GroupListTable,)
...@@ -2042,3 +2042,33 @@ class DiskAddView(TemplateView): ...@@ -2042,3 +2042,33 @@ class DiskAddView(TemplateView):
r = obj.get_absolute_url() r = obj.get_absolute_url()
r = "%s#resources" % r r = "%s#resources" % r
return redirect(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)
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