| Total Complexity | 9 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from contextlib import contextmanager |
||
| 2 | |||
| 3 | from pyramid.decorator import reify |
||
| 4 | from pyramid.request import Request |
||
| 5 | |||
| 6 | from tracim.models import User |
||
| 7 | from tracim.models.data import Workspace |
||
| 8 | from tracim.lib.utils.auth import get_safe_user |
||
| 9 | from tracim.lib.utils.auth import get_workspace |
||
| 10 | |||
| 11 | |||
| 12 | class TracimRequest(Request): |
||
| 13 | def __init__( |
||
| 14 | self, |
||
| 15 | environ, |
||
| 16 | charset=None, |
||
| 17 | unicode_errors=None, |
||
| 18 | decode_param_names=None, |
||
| 19 | **kw |
||
| 20 | ): |
||
| 21 | super().__init__( |
||
| 22 | environ, |
||
| 23 | charset, |
||
| 24 | unicode_errors, |
||
| 25 | decode_param_names, |
||
| 26 | **kw |
||
| 27 | ) |
||
| 28 | self._current_workspace = None # type: Workspace |
||
| 29 | self._current_user = None # type: User |
||
| 30 | |||
| 31 | @property |
||
| 32 | def current_workspace(self) -> Workspace: |
||
| 33 | if self._current_workspace is None: |
||
| 34 | self.current_workspace = get_workspace(self.current_user, self) |
||
| 35 | return self._current_workspace |
||
| 36 | |||
| 37 | @current_workspace.setter |
||
| 38 | def current_workspace(self, workspace: Workspace) -> None: |
||
| 39 | assert self._current_workspace is None |
||
| 40 | self._current_workspace = workspace |
||
| 41 | |||
| 42 | @property |
||
| 43 | def current_user(self) -> User: |
||
| 44 | if self._current_user is None: |
||
| 45 | self.current_user = get_safe_user(self) |
||
| 46 | return self._current_user |
||
| 47 | |||
| 48 | @current_user.setter |
||
| 49 | def current_user(self, user: User) -> None: |
||
| 50 | assert self._current_user is None |
||
| 51 | self._current_user = user |
||
| 52 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.