summaryrefslogtreecommitdiffstats
path: root/tools/pharos-dashboard/account/middleware.py
diff options
context:
space:
mode:
authormaxbr <maxbr@mi.fu-berlin.de>2016-08-19 17:11:58 +0200
committermaxbr <maxbr@mi.fu-berlin.de>2016-08-19 17:11:58 +0200
commit66eb4d851e63d20031502ec0c96aaabe34c6fd32 (patch)
tree98248b6faf6b3c742efef258e34f06cc92d1a888 /tools/pharos-dashboard/account/middleware.py
parent3b5ef3b0a88247eeafeee878de528aad71f9fd4b (diff)
Implement periodic tasks
JIRA: RELENG-12 The dashboard is now querying jenkins periodically and saving the results in the database. This fixes delays that were caused by calling the jenkins API. Signed-off-by: maxbr <maxbr@mi.fu-berlin.de>
Diffstat (limited to 'tools/pharos-dashboard/account/middleware.py')
-rw-r--r--tools/pharos-dashboard/account/middleware.py11
1 files changed, 9 insertions, 2 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()