From 66eb4d851e63d20031502ec0c96aaabe34c6fd32 Mon Sep 17 00:00:00 2001 From: maxbr Date: Fri, 19 Aug 2016 17:11:58 +0200 Subject: 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 --- tools/pharos-dashboard/account/middleware.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'tools/pharos-dashboard/account/middleware.py') 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() -- cgit 1.2.3-korg