Factor out first_or_none
This commit is contained in:
parent
6af50b78b0
commit
6bfbaea867
@ -6,9 +6,7 @@ from sqlalchemy.orm import relationship
|
||||
from atst.models import Base
|
||||
from atst.models.types import Id
|
||||
from atst.models.request_status_event import RequestStatus
|
||||
|
||||
def first_or_none(predicate, lst):
|
||||
return next((x for x in lst if predicate(x)), None,)
|
||||
from atst.utils import first_or_none
|
||||
|
||||
|
||||
class Request(Base):
|
||||
|
@ -4,6 +4,7 @@ from sqlalchemy.orm import relationship
|
||||
from atst.models import Base
|
||||
from atst.models.types import Id
|
||||
from atst.models.mixins import TimestampsMixin
|
||||
from atst.utils import first_or_none
|
||||
|
||||
|
||||
MOCK_MEMBERS = [
|
||||
@ -48,14 +49,10 @@ class Workspace(Base, TimestampsMixin):
|
||||
|
||||
@property
|
||||
def owner(self):
|
||||
return next(
|
||||
(
|
||||
workspace_role.user
|
||||
for workspace_role in self.roles
|
||||
if workspace_role.role.name == "owner"
|
||||
),
|
||||
None,
|
||||
)
|
||||
def _is_workspace_owner(workspace_role):
|
||||
return workspace_role.role.name == "owner"
|
||||
|
||||
return first_or_none(_is_workspace_owner, self.roles)
|
||||
|
||||
@property
|
||||
def users(self):
|
||||
|
2
atst/utils.py
Normal file
2
atst/utils.py
Normal file
@ -0,0 +1,2 @@
|
||||
def first_or_none(predicate, lst):
|
||||
return next((x for x in lst if predicate(x)), None,)
|
Loading…
x
Reference in New Issue
Block a user