diff options
author | Sawyer Bergeron <sbergeron@iol.unh.edu> | 2020-03-25 19:21:04 +0000 |
---|---|---|
committer | Sawyer Bergeron <sbergeron@iol.unh.edu> | 2020-04-14 18:10:14 +0000 |
commit | 557659acfd97ddaacdb89192ff6a575691b39093 (patch) | |
tree | fa261e530212e096536de439b623d9a3cf3a354a /src/api/models.py | |
parent | 45044bdab74c969a9ca4b712625e0c3175b16787 (diff) |
Add user + user list to API
Change-Id: I15cf0c33b9d452fda47f97e3d9b43e00c1bf9bfd
Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Diffstat (limited to 'src/api/models.py')
-rw-r--r-- | src/api/models.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/api/models.py b/src/api/models.py index df9bbf7..e41a44d 100644 --- a/src/api/models.py +++ b/src/api/models.py @@ -33,7 +33,7 @@ from resource_inventory.models import ( ) from resource_inventory.idf_templater import IDFTemplater from resource_inventory.pdf_templater import PDFTemplater -from account.models import Downtime +from account.models import Downtime, UserProfile from dashboard.utils import AbstractModelQuery @@ -174,6 +174,26 @@ class LabManager(object): for profile in ResourceProfile.objects.filter(labs=self.lab)] return prof + def format_user(self, userprofile): + return { + "id": userprofile.user.id, + "username": userprofile.user.username, + "email": userprofile.email_addr, + "first_name": userprofile.user.first_name, + "last_name": userprofile.user.last_name, + "company": userprofile.company + } + + def get_users(self): + userlist = [self.format_user(profile) for profile in UserProfile.objects.select_related("user").all()] + + return json.dumps({"users": userlist}) + + def get_user(self, user_id): + profile = get_object_or_404(UserProfile, pk=user_id) + + return json.dumps(self.format_user(profile)) + def get_inventory(self): inventory = {} resources = ResourceQuery.filter(lab=self.lab) |