utils package#

Subpackages#

Submodules#

utils.admin module#

Generated by utils/cgit/cgit_util_generate_admin_file on 2022-01-24 14:40:23.466006

utils.apps module#

class utils.apps.UtilsConfig(app_name, app_module)[source]#

Bases: AppConfig

name = 'utils'#

utils.can_login_as module#

utils.can_login_as.check(request, target)[source]#

We use django-loginas to control admins taking over user sessions. This function validates and logs actions.

Note: we only get an event for a user becoming another user, not for any actions they perform as that user.

utils.forms module#

class utils.forms.SystemSettingsForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None, bound_field_class=None)[source]#

Bases: Form

system settings from AWS

base_fields = {'debug_flag': <django.forms.fields.BooleanField object>, 'disable_playpen': <django.forms.fields.BooleanField object>, 'maintenance_mode': <django.forms.fields.BooleanField object>}#
declared_fields = {'debug_flag': <django.forms.fields.BooleanField object>, 'disable_playpen': <django.forms.fields.BooleanField object>, 'maintenance_mode': <django.forms.fields.BooleanField object>}#
property media#

Return all media required to render the widgets on this form.

utils.middleware module#

class utils.middleware.CobaltMiddleware(get_response)[source]#

Bases: object

custom middleware to add last activity time to user object.

If you are here to switch this off to improve performance then I apologise. It seemed like a good idea at the time!

process_view(request, view_func, view_args, view_kwargs)[source]#

utils.models module#

Utilities.

This handles the models for general things such as batch processing.

class utils.models.Batch(*args, **kwargs)[source]#

Bases: Model

Batch job status

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

end_time#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_job_status_display(*, field=<django.db.models.fields.CharField: job_status>)#
get_next_by_run_date(*, field=<django.db.models.fields.DateTimeField: run_date>, is_next=True, **kwargs)#
get_next_by_start_time(*, field=<django.db.models.fields.DateTimeField: start_time>, is_next=True, **kwargs)#
get_previous_by_run_date(*, field=<django.db.models.fields.DateTimeField: run_date>, is_next=False, **kwargs)#
get_previous_by_start_time(*, field=<django.db.models.fields.DateTimeField: start_time>, is_next=False, **kwargs)#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

instance#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

job_status#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

node#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
run_date#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

start_time#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class utils.models.Lock(*args, **kwargs)[source]#

Bases: Model

Equivalent of a lock file for a distributed environment

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

get_next_by_lock_created_time(*, field=<django.db.models.fields.DateTimeField: lock_created_time>, is_next=True, **kwargs)#
get_previous_by_lock_created_time(*, field=<django.db.models.fields.DateTimeField: lock_created_time>, is_next=False, **kwargs)#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

lock_created_time#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

lock_open_time#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
owner#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

topic#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class utils.models.Seat(*values)[source]#

Bases: TextChoices

EAST = 'E'#
NORTH = 'N'#
SOUTH = 'S'#
WEST = 'W'#
class utils.models.Slug(*args, **kwargs)[source]#

Bases: Model

This maps short names to redirects. e.g. localhost/my-nice-slug -> localhost/events/5

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
owner#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

owner_id#
redirect_path#

redirect path should not have a leading /

slug#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

utils.storage module#

class utils.storage.ForgivingManifestStaticFilesStorage(*args, **kwargs)[source]#

Bases: ManifestStaticFilesStorage

If we update static files such as .js or .css files then user’s browsers will still cache the old version causing problems. We could disable caching but that would make the system much slower. Instead we use ManifestStaticFilesStorage which sticks an MD5 hash on the end of the filename making it unique.

We need to do three things though to make it work properly. First we need to ignore errors if it can’t find an entry in its staticfiles.json. We do this with manifest_strict = False See https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#django.contrib.staticfiles.storage.ManifestStaticFilesStorage.manifest_strict

Secondly we sub-class it here so we can ignore missing file references.

Thirdly, we need to use relative paths so {% static “/ddd” %} won’t work. It needs to be {% static “ddd” %}

hashed_name(name, content=None, filename=None)[source]#
manifest_strict = False#

utils.urls module#

utils.utils module#

utils.utils.cobalt_currency(number)[source]#

take a number and return it as a printable currency

utils.utils.cobalt_paginator(request: HttpRequest, events_list: list, items_per_page: int = 30, page_no: int = None) page[source]#

common pagination function

Parameters:
  • page_no (int) – optional page number to override what is in Request

  • request (HTTPRequest) – standard request object

  • events_list (list) – list of things to paginate

  • items_per_page (int) – number of items on a page

Returns: list

utils.utils.cobalt_round(number)[source]#

round up to 2 decimal places

Parameters:

number (Float) – number to round

Returns: Float

Module contents#