oioioi.base.permissions

Module Contents

Classes

AccessDenied

A False-like class with additional response to use as the access

Condition

Class representing a condition (a function which returns a boolean

RequestBasedCondition

Subclass of the Condition class.

Functions

make_condition([condition_class])

Decorator which transforms a function into an instance of a given

enforce_condition(condition[, template, login_redirect])

Decorator for views that checks that the request passes the given

not_anonymous(request)

Checks if user is logged in and if his account is active.

is_superuser(request)

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.

__nonzero__()[source]
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

__call__(*args, **kwargs)[source]
__or__(other)[source]
__and__(other)[source]
__invert__()[source]
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().

__call__(request, *args, **kwargs)[source]
oioioi.base.permissions.make_condition(condition_class=Condition)[source]

Decorator which transforms a function into an instance of a given condition_class (subclass of Condition).

oioioi.base.permissions.make_request_condition[source]
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 of Condition.

If the condition returns False and template is not None, a suitable TemplateResponse is returned.

If template is None and the user is not authenticated and the login_redirect flag is set to True, a redirect to the login page is issued, otherwise PermissionDenied 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 check

  • template (basestring) – template name to return when condition fails

oioioi.base.permissions.not_anonymous(request)[source]

Checks if user is logged in and if his account is active. Logs out inactive users, effectively blocking them from performing actions.

Parameters

request

Returns

oioioi.base.permissions.is_superuser(request)[source]