From 07e62b96658499f61d070cb3b84121e0599022ea Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Fri, 24 Apr 2020 10:54:11 -0700 Subject: [PATCH] Add factory.try_user for non-exception user lookup --- amanuensis/models/factory.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/amanuensis/models/factory.py b/amanuensis/models/factory.py index 072fd85..8d265bf 100644 --- a/amanuensis/models/factory.py +++ b/amanuensis/models/factory.py @@ -1,3 +1,5 @@ +from typing import Optional + from amanuensis.config import is_guid, RootConfigDirectoryContext from amanuensis.errors import ArgumentError from amanuensis.models.user import UserModel @@ -8,6 +10,15 @@ class ModelFactory(): def __init__(self, root: RootConfigDirectoryContext): self.root: RootConfigDirectoryContext = root + def try_user(self, identifier: str) -> Optional[UserModel]: + user: Optional[UserModel] = None + try: + user = self.user(identifier) + except Exception: + pass + finally: + return user + def user(self, identifier: str) -> UserModel: """Get the user model for the given id or username""" # Ensure we have something to work with