oioioi.base.permissions
¶
Module Contents¶
Classes¶
A |
|
Class representing a condition (a function which returns a boolean |
|
Subclass of the |
Functions¶
|
Decorator which transforms a function into an instance of a given |
|
Decorator for views that checks that the request passes the given |
|
Checks if user is logged in and if his account is active. |
|
Attributes¶
- class oioioi.base.permissions.AccessDenied(response=None)[source]¶
Bases:
object
A
False
-like class with additional response to use as the access denied message.
- class oioioi.base.permissions.Condition(condition, *args, **kwargs)[source]¶
Bases:
object
Class representing a condition (a function which returns a boolean based on its arguments) intended for use with views and menu items.
Technically, an instance of this class is a callable object wrapping a function.
Additionally, it implements basic logical operators: AND (&), OR (|), and (~) – a logical negation.
- Parameters
condition (fun: *args, **kwargs → bool) – the function to be wrapped
- class oioioi.base.permissions.RequestBasedCondition(condition, *args, **kwargs)[source]¶
Bases:
Condition
Subclass of the
Condition
class.It is a special condition class representing a condition which takes request as its only argument.
It allows the usage of
oioioi.base.utils.request_cached()
.
- oioioi.base.permissions.make_condition(condition_class=Condition)[source]¶
Decorator which transforms a function into an instance of a given
condition_class
(subclass ofCondition
).
- oioioi.base.permissions.enforce_condition(condition, template=None, login_redirect=True)[source]¶
Decorator for views that checks that the request passes the given
condition
.condition
must be an instance ofCondition
.If the condition returns
False
andtemplate
is notNone
, a suitableTemplateResponse
is returned.If
template
isNone
and the user is not authenticated and thelogin_redirect
flag is set toTrue
, a redirect to the login page is issued, otherwisePermissionDenied
is raised.If the condition returns an instance of
AccessDenied
with a specific response to use, this response is used instead of calling the decorated view.- Parameters
condition (
Condition
) – condition to checktemplate (basestring) – template name to return when
condition
fails