From 5e8c4a3231b61872c4b24485acc6fa5f63122f45 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 1 Jul 2021 12:08:18 +0200 Subject: [PATCH] add code of user for show in angular --- ereuse_devicehub/resources/user/models.py | 7 +++++++ ereuse_devicehub/resources/user/schemas.py | 1 + 2 files changed, 8 insertions(+) diff --git a/ereuse_devicehub/resources/user/models.py b/ereuse_devicehub/resources/user/models.py index f1690156..79525286 100644 --- a/ereuse_devicehub/resources/user/models.py +++ b/ereuse_devicehub/resources/user/models.py @@ -59,6 +59,13 @@ class User(Thing): """The individual associated for this database, or None.""" return next(iter(self.individuals), None) + @property + def code(self): + """Code of phantoms accounts""" + if not self.phantom: + return + return self.email.split('@')[0].split('_')[1] + class UserInventory(db.Model): """Relationship between users and their inventories.""" diff --git a/ereuse_devicehub/resources/user/schemas.py b/ereuse_devicehub/resources/user/schemas.py index 220e193b..a70c0da8 100644 --- a/ereuse_devicehub/resources/user/schemas.py +++ b/ereuse_devicehub/resources/user/schemas.py @@ -23,6 +23,7 @@ class User(Thing): description='Use this token in an Authorization header to access the app.' 'The token can change overtime.') inventories = NestedOn(Inventory, many=True, dump_only=True) + code = String(dump_only=True, description='Code of inactive accounts') def __init__(self, only=None,