API Documentation

This section of the django-lass-utils documentation is automatically generated from the code.

The lass_utils package

This package contains various utility functions, Django models and mixins that wrap up miscellaneous common patterns used throughout the LASS system.

It serves as the common root of the LASS inheritance hierarchy,

Models

The lass_utils module contains several model definitions under lass_utils.models.

Type

This module defines type, a common base class for type-of models.

In LASS, the pattern of dynamic lookup tables representing types and categories of other objects is very prevalent; in order to make using these type models more convenient, we have a common abstract base class for them.

class lass_utils.models.type.Type(*args, **kwargs)

Bases: django.db.models.base.Model

An abstract base class for models representing types, categories or other keyed collections of other models.

class Meta
abstract = False
classmethod Type.get(identifier)

User-friendly type get function.

This function uses the caching system to cache the type for a short amount of time.

If the input is an integer, it will be treated as the target type’s primary key.

If the input is a string, it will be treated as the target type’s name (case-insensitively).

If the input is an instance of cls itself, it will simply be returned.

Else, TypeError will be raised.

Parameters:identifier (string, integer or an element of the called class) – an item of data representing the type to retrieve, or the type itself
Return type:an element of the called class
classmethod Type.get_if_exists(identifier)

Like get(), but returns None instead of raising an exception if the requested type does not exist.

TypeError is still raised in the event of a disallowed identifier type.

Parameters:identifier (string, integer or an element of the called class) – an item of data representing the type to retrieve, or the type itself
Return type:an element of the called class
classmethod Type.get_or_404(*args, **kwargs)

Attempts to use get to retrieve an instance of this type, but returns Http404 instead of cls.DoesNotExist if no object of the given type exists.

Arguments are passed verbatim to get; see the docstring for get for parameter details.

Mixins

Anything that adds functionality, or a common interface, to a model without necessarily specifying anything about the context of the model is termed a mixin.

Many of these are in actual fact abstract models, which means that they often cannot be combined in a class that also inherits directly from django.models.Model.

Mixin for items that are submittable, and thus have a nullable submission date field.

class lass_utils.mixins.submittable.SubmittableMixin(*args, **kwargs)

Bases: django.db.models.base.Model

A mixin for models that represent an item that must be submitted in order to be used.

class Meta
abstract = False

Mixin adding range functions for models that have a defined time range.

class lass_utils.mixins.date_range.DateRangeMixin

Bases: object

Mixin adding range functions for models that have a defined datetime range.

date_range()

Returns both endpoints of this item’s datetime range.

range_duration()

Returns the duration of this item’s datetime range.

range_end()

Returns the end of this item’s datetime range.

Must be overridden in descended classes.

classmethod range_end_filter_arg(inequality, value)

Given a filter inequality and a value to compare against, returns a tuple of the keyword argument and value that can be used to represent that inequality against the range end time in a filter.

range_end_unix()

Returns the end of the range as a UNIX timestamp from UTC.

range_start()

Returns the start of this item’s datetime range.

Must be overridden in descended classes.

classmethod range_start_filter_arg(inequality, value)

Given a filter inequality and a value to compare against, returns a tuple of the keyword argument and value that can be used to represent that inequality against the range start time in a filter.

range_start_unix()

Returns the start of the range as a UNIX timestamp from UTC.

A partial implementation of DateRangeMixin’s interface by which the date range is fulfilled by an ‘effective from’ and an ‘effective to’ pair of fields.

class lass_utils.mixins.effective_range.ERQuerySet(model=None, query=None, using=None)

Bases: django.db.models.query.QuerySet

Custom QuerySet allowing date range-based filtering.

at(date)

Wrapper around ‘in_range’ that retrieves items effective at the given moment in time.

in_range(from_date, to_date)

Filters towards a QuerySet of items in this QuerySet that are effective during the given date range.

The items must cover the entire range.

Items with an ‘effective_from’ of NULL will be discarded; items with an ‘effective_to’ of NULL will be treated as if their effective_to is infinitely far in the future.

If queryset is given, it will be filtered with the above condition; else the entire object set will be considered.

class lass_utils.mixins.effective_range.EffectiveRangeMixin(*args, **kwargs)

Bases: django.db.models.base.Model, lass_utils.mixins.date_range.DateRangeMixin

Mixin adding an ‘effective from’ and ‘effective to’ pair of fields that implement DateRangeMixin.

class Meta

Bases: object

abstract = False
get_latest_by = 'effective_from'
classmethod EffectiveRangeMixin.at(date, queryset=None)

Compatibility wrapper for QuerySet.at.

classmethod EffectiveRangeMixin.in_range(from_date, to_date, queryset=None)

Compatibility wrapper for QuerySet.in_range.

EffectiveRangeMixin.objects = <model_utils.managers._PassThroughManager object at 0x3fec1d0>
EffectiveRangeMixin.range_end()
EffectiveRangeMixin.range_start()

Project Versions

Table Of Contents

Previous topic

Contributors

This Page