dcolumn.common package

dcolumn.common.admin_mixins module

Mixins used in the Django admin.

class dcolumn.common.admin_mixins.UserAdminMixin(model, admin_site)[source]

Bases: ModelAdmin

Admin mixin that must be used in any model implimented with CollectionBase as it’s base class.

property media
save_model(request, obj, form, change)[source]

When saving a record from the admin the creator should be updated with the request user object if change is False. The updater is always updated withthe request user object.

Parameters:
  • request (HttpRequest) – Django request object.

  • obj (Model object) – Django model object

  • form (Form object) – Django form object.

  • change (bool) – If True the record was updated, if False the record was created.

dcolumn.common.choice_mixins module

Dynamic Column dependent choice mixins.

class dcolumn.common.choice_mixins.BaseChoice[source]

Bases: object

We need a base class for all Choice types so we can dynamically find them.

class dcolumn.common.choice_mixins.BaseChoiceManager[source]

Bases: InspectChoice, ChoiceManagerImplementation

This class must be used in any non-django model CHOICE object.

Note

The PK field is manditory, however it does not need to be put into the FIELD_LIST object. It will be removed before processing if found. The list could look like this: ('pk', 'name', 'version',) or ('name', 'version',).

There are two ways to populate the VALUES object in a choice model.

  1. A flat list of objects as such: ('Good', 'Better',)

  2. List in list as such: (('Arduino', 'Mega2560'), ('Raspberry Pi', 'B+'),)

The second method permits more than one fields whereas the first method permits only one field. In neither case does the PK count as a field.

Both the FIELD_LIST and VALUES objects can be either a list or tuple.

FIELD_LIST = []
VALUES = []
all(*args, **kwargs)

This method creates and returns the choice objects the first time it is run, on subsequent runs it returns the stored objects.

Return type:

A list of non-django model CHOICE objects.

get(*args, **kwargs)
get_choices(field, comment=True, sort=True)[source]

Calls model_objects() to be sure the choice objects are created, then returns a list appropriate for HTML select option tags.

Parameters:
  • field (str) – The field of the choice that is used to populate the list.

  • comment (bool) – Defaults to True prepending a choice header to the list.

  • sort (bool) – Defaults ro True sorting the results, a False will turn off sorting.

Return type:

A list of tuples suitable for use in HTML select option tags.

get_value_by_pk(pk, field)[source]

Calls model_objects() to be sure the choice objects are created, then returns the value from the field argument based on the ‘pk’ argument.

Parameters:
  • pk (int or str) – The key of the object.

  • field (str) – The field of the choice the value is taken from.

Return type:

Value from the field on the object.

model_objects(*args, **kwargs)

This method creates and returns the choice objects the first time it is run, on subsequent runs it returns the stored objects.

Return type:

A list of non-django model CHOICE objects.

dcolumn.common.decorators module

Dynamic Column decorators.

class dcolumn.common.decorators.InspectChoice[source]

Bases: object

This class does introspection on a non-model CHOICE object and supplies a decorator for the choice manager mixin. It should not be necessary to use this class outside of DColumns itself.

classmethod set_model(method)[source]

A decorator to set the choices model object of the calling class in the manager.

Parameters:

method (str) – The method name to be decorated.

Return type:

The enclosed function embedded in this method.

dcolumn.common.decorators.dcolumn_login_required(function=None, redirect_field_name='next', login_url=None)[source]

Decorator for views that checks that the user is logged in, redirecting to the log-in page if necessary. Authentication on the API can be turned on or off depending on the settings.DYNAMIC_COLUMNS[ 'INACTIVATE_API_AUTH' ] state.

Parameters:
  • function (Function or method) – The function or method to decorate.

  • redirect_field_name (str) – See Django Docs.

  • login_url (str) – Optional URL to login through.

Return type:

The results from login_required

dcolumn.common.model_mixins module

Mixins used in Django models.

class dcolumn.common.model_mixins.StatusModelManagerMixin(*args, **kwargs)[source]

Bases: Manager

Manager mixin for the StatusModelMixin abstract model.

active(active=True)[source]

Return as default only active database objects.

Parameters:

active (bool) – If True return only active records else if False return non-active records. If None return all records.

Return type:

Django query results.

class dcolumn.common.model_mixins.StatusModelMixin(*args, **kwargs)[source]

Bases: Model

Abstract model mixin used in the model classes to supply the active field.

class Meta[source]

Bases: object

abstract = False
active

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

save(*args, **kwargs)[source]

Save is here to assure that save is executed throughout the MRO.

Parameters:
  • args – Positional arguments.

  • kwargs – Keyword arguments.

class dcolumn.common.model_mixins.TimeModelMixin(*args, **kwargs)[source]

Bases: Model

Abstract model mixin used in the model classes to supply created and updated fields.

class Meta[source]

Bases: object

abstract = False
created

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

get_next_by_created(*, field=<django.db.models.fields.DateTimeField: created>, is_next=True, **kwargs)
get_next_by_updated(*, field=<django.db.models.fields.DateTimeField: updated>, is_next=True, **kwargs)
get_previous_by_created(*, field=<django.db.models.fields.DateTimeField: created>, is_next=False, **kwargs)
get_previous_by_updated(*, field=<django.db.models.fields.DateTimeField: updated>, is_next=False, **kwargs)
save(*args, **kwargs)[source]

Understands two keyword arguments, disable_created and disable_updated. These arguments are used to optionally turn off the updating of the created and updated fields on the model. This can be used when migrating data into a model that already has these fields set so the original date ad times can be kept.

Parameters:
  • args – Positional arguments.

  • kwargs – Keyword arguments.

updated

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

class dcolumn.common.model_mixins.UserModelMixin(*args, **kwargs)[source]

Bases: Model

Abstract model mixin used in the model classes to provide user and creator fields.

class Meta[source]

Bases: object

abstract = False
creator

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.

creator_id
creator_producer()[source]

Primary use is in an admin class to supply the creator’s full name if available else the username.

Return type:

String of creator’s full name.

save(*args, **kwargs)[source]

Save is here to assure that save is executed throughout the MRO.

Parameters:
  • args – Positional arguments.

  • kwargs – Keyword arguments.

updater

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.

updater_id
updater_producer()[source]

Primary use is in an admin class to supply the updater’s full name if available else the username.

Return type:

String of updater’s full name.

class dcolumn.common.model_mixins.ValidateOnSaveMixin(*args, **kwargs)[source]

Bases: Model

class Meta[source]

Bases: object

abstract = False
save(*args, **kwargs)[source]

Execute full_clean.

Parameters:
  • args – Positional arguments.

  • kwargs – Keyword arguments.

dcolumn.common.view_mixins module

Dynamic Column view mixins.

class dcolumn.common.view_mixins.JSONResponseMixin[source]

Bases: object

A mixin that can be used to render a JSON response.

get_data(**context)[source]

Returns the context that will be serialized to JSON.

Note

This method must be implemented by the subclass.

Parameters:

context (dict) – Context added to the JSON response.

Return type:

dict – Updated context

render_to_json_response(context, **response_kwargs)[source]

Returns a JSON response, transforming ‘context’ to make the payload.

Parameters:
  • context (See Django Context.) – The template rendering context.

  • response_kwargs – Response keywords arguments.

Return type:

See Django response_class.

Module contents

Implementation class.

class dcolumn.common.ChoiceManagerImplementation[source]

Bases: object

Manditory methods that must be defined in both choice models and Django models.

get_choices(field, comment=True, sort=True)[source]
get_value_by_pk(pk, field=None)[source]
model_objects(active=True)[source]
dcolumn.common.create_field_name(value)[source]