summaryrefslogtreecommitdiffstats
path: root/tools/pharos-dashboard/account
diff options
context:
space:
mode:
Diffstat (limited to 'tools/pharos-dashboard/account')
-rw-r--r--tools/pharos-dashboard/account/middleware.py11
-rw-r--r--tools/pharos-dashboard/account/migrations/0001_initial.py18
2 files changed, 13 insertions, 16 deletions
diff --git a/tools/pharos-dashboard/account/middleware.py b/tools/pharos-dashboard/account/middleware.py
index f5170baa..6f7cac7a 100644
--- a/tools/pharos-dashboard/account/middleware.py
+++ b/tools/pharos-dashboard/account/middleware.py
@@ -1,7 +1,8 @@
-from django.core.exceptions import ObjectDoesNotExist
from django.utils import timezone
from django.utils.deprecation import MiddlewareMixin
+from account.models import UserProfile
+
class TimezoneMiddleware(MiddlewareMixin):
"""
@@ -10,6 +11,12 @@ class TimezoneMiddleware(MiddlewareMixin):
"""
def process_request(self, request):
if request.user.is_authenticated:
- timezone.activate(request.user.userprofile.timezone)
+ try:
+ tz = request.user.userprofile.timezone
+ timezone.activate(tz)
+ except UserProfile.DoesNotExist:
+ UserProfile.objects.create(user=request.user)
+ tz = request.user.userprofile.timezone
+ timezone.activate(tz)
else:
timezone.deactivate()
diff --git a/tools/pharos-dashboard/account/migrations/0001_initial.py b/tools/pharos-dashboard/account/migrations/0001_initial.py
index 752d5171..4ff9510a 100644
--- a/tools/pharos-dashboard/account/migrations/0001_initial.py
+++ b/tools/pharos-dashboard/account/migrations/0001_initial.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-# Generated by Django 1.10 on 2016-08-12 09:51
+# Generated by Django 1.10 on 2016-08-15 12:19
from __future__ import unicode_literals
from django.conf import settings
@@ -13,7 +13,6 @@ class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
- ('dashboard', '0001_initial'),
]
operations = [
@@ -21,7 +20,9 @@ class Migration(migrations.Migration):
name='UserProfile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
- ('sshkey', models.CharField(max_length=1024)),
+ ('timezone', models.CharField(default='UTC', max_length=100)),
+ ('sshkey', models.CharField(max_length=2048)),
+ ('pgpkey', models.CharField(max_length=2048)),
('company', models.CharField(max_length=200)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
@@ -29,15 +30,4 @@ class Migration(migrations.Migration):
'db_table': 'user_profile',
},
),
- migrations.CreateModel(
- name='UserResource',
- fields=[
- ('id', models.AutoField(primary_key=True, serialize=False)),
- ('resource', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.Resource')),
- ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
- ],
- options={
- 'db_table': 'user_resource',
- },
- ),
]