from functools import cached_property
from onegov.town6.request import TownRequest
from typing import TypeVar, TYPE_CHECKING
if TYPE_CHECKING:
from onegov.fsi.app import FsiApp
from onegov.fsi.models import CourseAttendee
from uuid import UUID
[docs]
AppT = TypeVar('AppT', bound='FsiApp', default='FsiApp', covariant=True)
[docs]
class FsiRequest(TownRequest[AppT]):
@cached_property
[docs]
def attendee(self) -> CourseAttendee | None:
return (
# FIXME: backref across module boundaries
self.current_user.attendee # type:ignore[attr-defined]
if self.current_user else None
)
@cached_property
[docs]
def attendee_id(self) -> UUID | None:
return self.attendee.id if self.attendee else None
@cached_property
[docs]
def is_editor(self) -> bool:
return (
self.current_user
and self.current_user.role == 'editor' or False
)
@cached_property
[docs]
def is_member(self) -> bool:
return (
self.current_user
and self.current_user.role == 'member' or False
)