Core utillity functions¶
General helper functions in core¶
aleksis.core.util.core_helpers.copyright_years(years, seperator=', ', joiner='–')[source]¶Take a sequence of integegers and produces a string with ranges.
>>> copyright_years([1999, 2000, 2001, 2005, 2007, 2008, 2009]) '1999–2001, 2005, 2007–2009'
- Return type
aleksis.core.util.core_helpers.custom_information_processor(request)[source]¶Provide custom information in all templates.
- Return type
aleksis.core.util.core_helpers.dt_show_toolbar(request)[source]¶Add a helper to determin if Django debug toolbar should be displayed.
Extends the default behaviour by enabling DJDT for superusers independent of source IP.
- Return type
aleksis.core.util.core_helpers.generate_random_code(length, packet_size)[source]¶Generate random code for e.g. invitations.
- Return type
aleksis.core.util.core_helpers.get_allowed_object_ids(request, models)[source]¶Get all objects of all given models the user of a given request is allowed to view.
- Return type
aleksis.core.util.core_helpers.get_app_packages()[source]¶Find all registered apps from the setuptools entrypoint.
aleksis.core.util.core_helpers.get_or_create_favicon(title, default, is_favicon=False)[source]¶Ensure that there is always a favicon object.
- Return type
Favicon
aleksis.core.util.core_helpers.get_site_preferences()[source]¶Get the preferences manager of the current site.
aleksis.core.util.core_helpers.has_person(obj)[source]¶Check wehether a model object has a person attribute linking it to a Person object.
The passed object can also be a HttpRequest object, in which case its associated User object is unwrapped and tested.
- Return type
aleksis.core.util.core_helpers.is_impersonate(request)[source]¶Check whether the user was impersonated by an admin.
- Return type
aleksis.core.util.core_helpers.lazy_preference(section, name)[source]¶Lazily get a config value from dynamic preferences.
Useful to bind preferences to other global settings to make them available to third-party apps that are not aware of dynamic preferences.
aleksis.core.util.core_helpers.merge_app_settings(setting, original, deduplicate=False)[source]¶Merge app settings.
Get a named settings constant from all apps and merge it into the original. To use this, add a settings.py file to the app, in the same format as Django’s main settings.py.
Note: Only selected names will be imported frm it to minimise impact of potentially malicious apps!
aleksis.core.util.core_helpers.monkey_patch()[source]¶Monkey-patch dependencies for special behaviour.
- Return type
aleksis.core.util.core_helpers.objectgetter_optional(model, default=None, default_eval=False)[source]¶Get an object by pk, defaulting to None.
aleksis.core.util.core_helpers.process_custom_context_processors(context_processors)[source]¶Process custom context processors.
Predicates for permission systemd¶
-
aleksis.core.util.predicates.check_global_permission(user, perm)[source]¶ Check whether a user has a global permission.
- Return type
-
aleksis.core.util.predicates.check_object_permission(user, perm, obj, checker_obj=None)[source]¶ Check whether a user has a permission on an object.
You can provide a custom
ObjectPermissionCheckerfor prefetching object permissions by annotating an extensible model withset_object_permission_checker. This can be the provided object (obj) or a special object which is only used to get the checker class (checker_obj).- Return type
-
aleksis.core.util.predicates.contains_site_preference_value(section, pref, value)[source]¶ Check if given site preference contains a value.
-
aleksis.core.util.predicates.has_any_object(perm, klass)[source]¶ Check if has any object.
Build predicate which checks whether a user has access to objects with the provided permission or rule. Differentiates between object-related permissions and rules.
-
aleksis.core.util.predicates.has_global_perm(perm)[source]¶ Build predicate which checks whether a user has a global permission.
-
aleksis.core.util.predicates.has_object_perm(perm)[source]¶ Build predicate which checks whether a user has a permission on a object.
Messages¶
-
aleksis.core.util.messages.add_message(request, level, message, **kwargs)[source]¶ Add a message.
Add a message to either Django’s message framework, if called from a web request, or to the default logger.
Default to DEBUG level.
-
aleksis.core.util.messages.debug(request, message, **kwargs)[source]¶ Add a debug message.
Add a message to either Django’s message framework, if called from a web request, or to the default logger.
Default to DEBUG level.
-
aleksis.core.util.messages.error(request, message, **kwargs)[source]¶ Add an error message.
Add a message to either Django’s message framework, if called from a web request, or to the default logger.
Default to ERROR level.
-
aleksis.core.util.messages.info(request, message, **kwargs)[source]¶ Add a info message.
Add a message to either Django’s message framework, if called from a web request, or to the default logger.
Default to INFO level.
General helper functions for models¶
Helper functions for SASS¶
Helpers for SASS/SCSS compilation.
-
aleksis.core.util.sass_helpers.clean_scss(*args, **kwargs)[source]¶ Unlink compiled CSS (i.e. cache invalidation).
- Return type
Utillity function for AlekSIS app container¶
-
class
aleksis.core.util.apps.AppConfig(app_name, app_module)[source]¶ An extended version of DJango’s AppConfig container.
-
classmethod
get_available_scopes(application=None, request=None, *args, **kwargs)[source]¶ Return a list of all OAuth scopes available to the request and application.
-
classmethod
get_default_scopes(application=None, request=None, *args, **kwargs)[source]¶ Return a list of all OAuth scopes to always include for this request and application.
-
classmethod
get_licence()[source]¶ Get tuple of licence information of application package.
- Return type
-
post_migrate(app_config, verbosity, interactive, using, **kwargs)[source]¶ Call on every app instance after its models have been migrated.
By default, asks all models to do maintenance on their default data.
- Return type
-
pre_migrate(app_config, verbosity, interactive, using, plan, apps, **kwargs)[source]¶ Call on every app instance before its models are migrated.
By default, it does nothing.
- Return type
-
preference_updated(sender, section=None, name=None, old_value=None, new_value=None, **kwargs)[source]¶ Call on every app instance if a dynamic preference changes, and once on startup.
By default, it does nothing.
- Return type
-
classmethod
AlekSIS core middlewares¶
-
class
aleksis.core.util.middlewares.EnsurePersonMiddleware(get_response)[source]¶ Middleware that ensures that the logged-in user is linked to a person.
It is needed to inject a dummy person to a superuser that would otherwise not have an associated person, in order they can get their account set up without external help.
In addition, if configured in preferences, it auto-creates or links persons to regular users if they match.