diff options
Diffstat (limited to 'src/account')
-rw-r--r-- | src/account/models.py | 8 | ||||
-rw-r--r-- | src/account/tasks.py | 5 | ||||
-rw-r--r-- | src/account/views.py | 6 |
3 files changed, 17 insertions, 2 deletions
diff --git a/src/account/models.py b/src/account/models.py index 294e109..4aab306 100644 --- a/src/account/models.py +++ b/src/account/models.py @@ -10,9 +10,11 @@ from django.contrib.auth.models import User from django.db import models +from django.apps import apps import json import random +from collections import Counter class LabStatus(object): """ @@ -212,6 +214,12 @@ class Lab(models.Model): key += random.choice(alphabet) return key + def get_available_resources(self): + # Cannot import model normally due to ciruclar import + Server = apps.get_model('resource_inventory', 'Server') # TODO: Find way to import ResourceQuery + resources = [str(resource.profile) for resource in Server.objects.filter(lab=self, booked=False)] + return dict(Counter(resources)) + def __str__(self): return self.name diff --git a/src/account/tasks.py b/src/account/tasks.py index fe51974..53fbaf5 100644 --- a/src/account/tasks.py +++ b/src/account/tasks.py @@ -26,7 +26,10 @@ def sync_jira_accounts(): except JIRAError: # User can be anonymous (local django admin account) continue - user.email = user_dict['emailAddress'] + try: + user.email = user_dict['emailAddress'] + except: + pass user.userprofile.url = user_dict['self'] user.userprofile.full_name = user_dict['displayName'] diff --git a/src/account/views.py b/src/account/views.py index d1cc813..1cb2275 100644 --- a/src/account/views.py +++ b/src/account/views.py @@ -127,7 +127,11 @@ class JiraAuthenticatedView(RedirectView): jira = JIRA(server=settings.JIRA_URL, oauth=oauth_dict) username = jira.current_user() - email = jira.user(username).emailAddress + email = "" + try: + email = jira.user(username).emailAddress + except: + email = "" url = '/' # Step 3. Lookup the user or create them if they don't exist. try: |