oioioi.base.utils
¶
Submodules¶
oioioi.base.utils.api
oioioi.base.utils.archive
oioioi.base.utils.color
oioioi.base.utils.confirmation
oioioi.base.utils.db
oioioi.base.utils.deps
oioioi.base.utils.execute
oioioi.base.utils.filters
oioioi.base.utils.finders
oioioi.base.utils.input_with_generate
oioioi.base.utils.inputs
oioioi.base.utils.loaders
oioioi.base.utils.middleware
oioioi.base.utils.pdf
oioioi.base.utils.query_helpers
oioioi.base.utils.redirect
oioioi.base.utils.tags
oioioi.base.utils.user
oioioi.base.utils.user_selection
oioioi.base.utils.validators
Package Contents¶
Classes¶
Meta class triggering __classinit__ on class intialization. |
|
Abstract base class injecting ClassInitMeta meta class. |
|
A base class for classes which should have a list of subclasses |
|
Base class for objects which support mixins. |
|
A read-only @property that is only evaluated once. |
|
Displays simple textual progress bar. |
Functions¶
|
Simple wrapper that adds result caching for functions with positional |
|
Clear the memoization cache of a function decorated by |
|
Adds per-request caching for functions which operate on sole request. |
|
|
|
|
|
|
|
A framework for building pages that are split into tabs. |
|
|
|
|
|
|
|
|
|
A decorator to serialize view result with JSON. |
|
|
|
Add Access-Control-Allow-Origin header with given value, |
|
Check if 'request' is an jQuery AJAX call. |
Generate an random key, encoded in url-safe way. |
|
|
This method returns the full user name if available and |
|
Finds closure of sets. |
Attributes¶
- class oioioi.base.utils.ClassInitMeta(class_name, bases, new_attrs)[source]¶
Bases:
type
Meta class triggering __classinit__ on class intialization.
- class oioioi.base.utils.ClassInitBase[source]¶
Bases:
object
Abstract base class injecting ClassInitMeta meta class.
- class oioioi.base.utils.RegisteredSubclassesBase[source]¶
Bases:
ClassInitBase
A base class for classes which should have a list of subclasses available.
The list of subclasses is available in their
subclasses
class attributes. Classes which have explicitly setabstract
class attribute toTrue
are not added tosubclasses
.If a class has
modules_with_subclasses
attribute (list or string), then specified modules for all installed applications can be loaded by callingload_subclasses()
.
- class oioioi.base.utils.ObjectWithMixins[source]¶
Bases:
ClassInitBase
Base class for objects which support mixins.
Mixins are nice tools in Python. But they have one drawback – you have to specify new class’ mixins at the point where you declare it. This class solves this problem. Mixins can be now be added on the fly by
mix_in()
method. This allows for a more flexible modular design.For example:
# base.py class UserController(ObjectWithMixins): def render_user_info(self, user): return "Login: " + user.username # some_external_module.py class UserControllerBeautifier(object): def render_user_info(self, user): super_info = super(UserControllerBeautifier, self) .render_user_info(user) return '<font color="red">' + super_info + '</font>' UserController.mix_in(UserControllerBeautifier)
Mixins can also be specified by providing a
mixins
class attribute or by passing an additional keyword argumentmixins
to the constructor.A class with a mixin behave as if it was replaced with a subclass which bases are the mixin and the original class.
The actual class with the mixins is created when the constructor is called or a subclass defined. Mixing in a new mixin to a class which have instances has an undefined effect on them.
- class oioioi.base.utils.memoized_property(fget, doc=None)[source]¶
Bases:
object
A read-only @property that is only evaluated once.
- oioioi.base.utils.memoized(fn)[source]¶
Simple wrapper that adds result caching for functions with positional arguments only.
The arguments must be hashable so that they can be stored as keys in a dict.
- oioioi.base.utils.reset_memoized(memoized_fn)[source]¶
Clear the memoization cache of a function decorated by :fun:`memoized`.
- oioioi.base.utils.request_cached(fn)[source]¶
Adds per-request caching for functions which operate on sole request.
- oioioi.base.utils.tabbed_view(request, template, context, tabs, tab_kwargs, link_builder)[source]¶
A framework for building pages that are split into tabs.
The current tab is picked using the ‘key’ GET parameter. The given template is rendered using the given context, which is extended by ‘current_tab’, representing the opened tab, ‘tabs’, a set of ‘obj’ and ‘link’ pairs for each existing tab, where ‘obj’ represents the tab and ‘link’ is a link to the tab’s page, and ‘content’, the tab’s rendered content.
- Parameters
request – a HttpRequest object given to the view
template – the rendered template
context – additional context to be passed to the template
tabs – an iterable of tabs. Each tab must have a unique ‘key’ attribute that will be used to create an URL to the tab, a ‘view’ attribute returning either HttpResponseRedirect, TemplateResponse or rendered html, and an optional ‘condition’ attribute: a function taking a request and returning if the tab should be accessible for this request. If there is no condition then it is assumed to be always returning True.
tab_kwargs – a dict to be passed as kwargs to each tab’s view
link_builder – a function which receives a tab and returns a link to the tab. It should contain a proper path and the appropriate ‘key’ parameter.
- class oioioi.base.utils.ProgressBar(max_value, length=20)[source]¶
Bases:
object
Displays simple textual progress bar.
- oioioi.base.utils.jsonify(view)[source]¶
A decorator to serialize view result with JSON.
The object returned by
view
will be converted to JSON and returned as an appropriatedjango.http.HttpResponse
.
- oioioi.base.utils.allow_cross_origin(arg='*')[source]¶
Add Access-Control-Allow-Origin header with given value, or ‘*’ if none given.
May be used as any of:
@allow_cross_origin @allow_cross_origin() @allow_cross_origin(’http://example.com’)