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:
objectA
False-like class with additional response to use as the access denied message.
- class oioioi.base.permissions.Condition(condition, *args, **kwargs)[source]¶
Bases:
objectClass 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:
ConditionSubclass of the
Conditionclass.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.conditionmust be an instance ofCondition.If the condition returns
Falseandtemplateis notNone, a suitableTemplateResponseis returned.If
templateisNoneand the user is not authenticated and thelogin_redirectflag is set toTrue, a redirect to the login page is issued, otherwisePermissionDeniedis raised.If the condition returns an instance of
AccessDeniedwith 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
conditionfails