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 import Base
|
||||||
from atst.models.types import Id
|
from atst.models.types import Id
|
||||||
from atst.models.request_status_event import RequestStatus
|
from atst.models.request_status_event import RequestStatus
|
||||||
|
from atst.utils import first_or_none
|
||||||
def first_or_none(predicate, lst):
|
|
||||||
return next((x for x in lst if predicate(x)), None,)
|
|
||||||
|
|
||||||
|
|
||||||
class Request(Base):
|
class Request(Base):
|
||||||
|
@ -4,6 +4,7 @@ from sqlalchemy.orm import relationship
|
|||||||
from atst.models import Base
|
from atst.models import Base
|
||||||
from atst.models.types import Id
|
from atst.models.types import Id
|
||||||
from atst.models.mixins import TimestampsMixin
|
from atst.models.mixins import TimestampsMixin
|
||||||
|
from atst.utils import first_or_none
|
||||||
|
|
||||||
|
|
||||||
MOCK_MEMBERS = [
|
MOCK_MEMBERS = [
|
||||||
@ -48,14 +49,10 @@ class Workspace(Base, TimestampsMixin):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def owner(self):
|
def owner(self):
|
||||||
return next(
|
def _is_workspace_owner(workspace_role):
|
||||||
(
|
return workspace_role.role.name == "owner"
|
||||||
workspace_role.user
|
|
||||||
for workspace_role in self.roles
|
return first_or_none(_is_workspace_owner, self.roles)
|
||||||
if workspace_role.role.name == "owner"
|
|
||||||
),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def users(self):
|
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