dcolumn.dcolumns package

dcolumn.dcolumns.admin module

dcolumn.dcolumns.forms module

dcolumn.dcolumns.manager module

The DColumn manager uses the Borg pattern.

class dcolumn.dcolumns.manager.DynamicColumnManager[source]

Bases: object

This class manages the dynamic columns.

property api_auth_state

Gets the value of settings.DYNAMIC_COLUMNS.INACTIVATE_API_AUTH. The state of this variable determines if the backend AJAX API needs authorization. The defaults is False indicating that authorization is active.

Return type:

True or False.

property choice_map

A property that returns a dict (map). This property is used internally by dcolumn.

Return type:

A dict where the key is the choice name (model or choice type) and the value is a tuple of the model/choice object and the field.

property choice_relation_map

A property that returns a dict (map) of the choices.

Return type:

A dict of the choices. {num, <object name>, ...} The key is the number given when added with the register_choice method. The value is the string representation of the choice object.

property choice_relations

A property that returns the HTML select option choices.

Return type:

A list of the choices.

property css_container_map

A property that returns a dict where the key is the CSS container number and the value is the CSS class or id. This property should be used in templates to designate location in the HTML.

Return type:

A dict of the CSS container classes.

property css_containers

A property that returns a list of tuples where the key is the template variable name and the CSS container class.

Return type:

A list of tuples where the tuple is (<template var>, <CSS class name>).

get_collection_name(model_name)[source]

Gets the ColumnCollection name of the model name. The model name can be all lowercase without underscores or the camel case class name.

Parameters:

model_name (str) – The dynamic column model name.

Return type:

A str representing the ColumnCollection name.

Raises:

ValueError – If a ColumnCollection objects could not be found.

This method provides the models that inherit CollectionBase and would usually be used in a drop down menu.

Parameters:

choose (bool) – If True includes a choice text as first item, else False the choice item is not included.

Return type:

A list of tuples.

get_relation_model_field(relation)[source]

Gets the model class object and the field used in the HTML select option text value. e.g. (example_site.books.models.Author, ‘name’)

Parameters:

relation (int) – The value in the DynamicColumn relation field.

Return type:

The model object and field used in the HTML select option text value.

register_choice(choice, relation_num, field)[source]

Register choice field types. These can be Foreign Key or multiple-choice non-database columns. ManyToMany is not supported at this time.

Parameters:
  • choice (ClassType) – This can be either a Django model or sudo model class. A choice class mimics a model class so that this manager can work with them as if they were Django model classes.

  • relation_num (int) – A numeric identifier for the choice used as the HTML select option value.

  • field (str) – A field from the model or choice object used as the HTML select option text.

register_css_containers(container_list)[source]

Register the CSS container objects. This method is usually called in the settings file.

Note

The format that is put in the settings should be something like this: ((<template var>, <CSS class name>), ...)

Example:

(('top', 'container_top'), ('bottom', 'container_bottom'))

Parameters:

container_list (list or tuple) – A list of the CSS classes that will determine the location on the page of the various dynamic columns.

Raises:

TypeError – If container_list is not a list or tuple.

dcolumn.dcolumns.models module

class dcolumn.dcolumns.models.CollectionBase(id, updater, creator, created, updated, active, column_collection)[source]

Bases: TimeModelMixin, UserModelMixin, StatusModelMixin

exception DoesNotExist

Bases: ObjectDoesNotExist

FALSE = 'false'
exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

NO = 'no'
TRUE = 'true'
TRUE_FALSE = ('true', 'false', 'true', 'false')
YES = 'yes'
YES_NO = ('yes', 'no', 'yes', 'no')
column_collection

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.

column_collection_id
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.

get_dynamic_column(slug)[source]

Gets the DynamicColumn instance given the slug.

Parameters:

slug (str) – The DynamicColumn slug value.

Return type:

DynamicColumn model instance.

Raises:
get_key_value(slug, field=None, choice_raw=False)[source]

Return the KeyValue object value for the DynamicColumn slug.

Parameters:
  • slug (str) – The DynamicColumn slug.

  • field (str or None) – Only used with CHOICE objects. Defaults to the field passed to the dcolumn_manager.register_choice(choice, relation_num, field) during configuration. The ‘field’ argument allows the return of a different field on the CHOICE objects, but must be a valid member object on the model.

  • choice_raw (bool) – Only works with dc.CHOICE type. A False indicates normal operation, whereas a True will return the pk.

Return type:

String value from a KeyValue object.

Raises:
  • ValueError – Invalid combination of parameters.

  • AttributeError – If a bad field is passed in.

  • TypeError – If wrong type is passed in.

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)
id

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

keyvalues

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

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

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

objects = <django.db.models.manager.Manager object>
save(*args, **kwargs)[source]

Be sure the complete MRO has their saves called.

save_deferred()[source]
serialize_key_values(by_slug=False)[source]

Returns a dict of the DynamicColumn PK and the KeyValue value.

Parameters:

by_slug (bool) – If False a dict of items are keyed by the dynamic column’s pk, if True the dynamic column’s slug is used.

Return type:

Dict

set_key_value(slug, value, field=None, obj=None, force=False, defer=False)[source]

This method sets an arbitrary key/value object, it will create a new objects or updated a pre-existing object.

If the argument value contains the value ‘increment’ or ‘decrement’ the value associated with the slug will be incremented or decremented.

Parameters:
  • slug (str) – The slug associated with a KeyValue object.

  • value (string or CollectionBase object) – Can be the actual value to set in a KeyValue object, or a model that inherits CollectionBase or BaseChoice.

  • field (str or None) – Only used with CHOICE objects. Used to set the value on the KeyValue object. If this keyword argument is not set the default field will be used when the dcolumn_manager.register_choice(choice, relation_num, field) was configured.

  • obj (KeyValue object) – A KeyValue object.

  • force (bool) – Default is False, do not save empty strings else True save empty strings only.

  • defer (bool) – Defer saving the KeyValue record. False is default.

Raises:
  • ValueError – Invalid combination of parameters.

  • KeyValue.DoesNotExist – If the KeyValue model object was not found.

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.

class dcolumn.dcolumns.models.CollectionBaseManager(*args, **kwargs)[source]

Bases: Manager

The manager class for any model that inherits CollectionBase.

get_all_fields()[source]

Returns all model field names.

Return type:

List of fields.

get_all_fields_and_slugs()[source]

Returns all field names and the DynamicColumn slugs in a sorted list.

Return type:

List of all field and slugs.

get_all_slugs()[source]

Returns all DynamicColumn slug names relative to this model.

Return type:

List of slugs.

get_choices(field, active=True, comment=True, sort=True)[source]

Returns choices that can be used in HTML select options.

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

  • active (bool) – If True only active records will be returned else if False all records will be returned.

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

  • sort (bool) – Defaults to True sorting results, a False will turn off sorting, however, if the model sorts this may have no effect.

Return type:

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

get_value_by_pk(pk, field)[source]

Returns the value from ‘field’ using the pk as the key.

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.

Raises:

CollectionBase.DoesNotExist – If the Dcolumn model object was not found.

model_objects(active=True)[source]

Returns a list of all objects on this model.

Parameters:

active (bool) – If True (default) only active records will be returned else if False all records will be returned.

Return type:

Django queryset.

class dcolumn.dcolumns.models.ColumnCollection(*args, **kwargs)[source]

Bases: TimeModelMixin, UserModelMixin, StatusModelMixin, ValidateOnSaveMixin

This model defines the collection of DynamicColumn objects in this set.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

collectionbase_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

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

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

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.

dynamic_column

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

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)
id

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.

objects = <dcolumn.dcolumns.models.ColumnCollectionManager object>
process_dynamic_columns(dcs)[source]

This method adds or removes DynamicColumn objects to the collection.

Parameters:

dcs – A list of DynamicColumn objects.

related_model

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]

Be sure the complete MRO has their saves called.

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.

class dcolumn.dcolumns.models.ColumnCollectionManager(*args, **kwargs)[source]

Bases: StatusModelManagerMixin

Manager for the ColumnCollection model.

get_active_relation_items(name)[source]

Get a list of all active relation type choice items. The list is made up of the names of each item.

Parameters:

name (str) – Name of the ColumnCollection.

Return type:

A list of all CHOICE items including both model and choice items.

get_collection_choices(name, use_pk=False)[source]

Returns a set of choices for a list of options on an HTML select tag. Normally the slug is returned as the option value, however if use_pk is True then the value attribute will get the pk of the record.

Parameters:
  • name (str) – Name of the ColumnCollection.

  • use_pk (bool) – If False (default) slugs are used else if True PKs are used.

Return type:

A list of tuples. [(<slug or pk>, <KeyValue name>), ...]

get_column_collection(name, unassigned=False)[source]

Get the query set for the named collection. If unassigned is True add the unassigned dynamic columns to the query set.

Parameters:
  • name (str) – Name of the column collection.

  • unassigned (bool) – Also get items that have not been assigned to a column collection yet.

Return type:

A queryset of objects that inherit CollectionBase.

Raises:

ColumnCollection.DoesNotExist – If the collection name is not found and unassigned is False.

serialize_columns(name, obj=None, by_slug=False)[source]

Serialize the DynamicColumn for the name of this collection in an OrderedDict. When a model that inherits CollectionBase is passed in as obj its set of KeyValue objects value are also included. OrderedDict items can be keyed by either a pk or slug.

Parameters:
  • name (str) – Name of the collection.

  • obj (object) – Optional model object that inherits from CollectionBase.

  • by_slug (bool) – If False the OrderedDict items are keyed by the dynamic column’s pk, if True the dynamic column’s slug is used.

Return type:

An OrderedDict of serialized KeyValue values and their DynamicColumn meta data.

class dcolumn.dcolumns.models.DynamicColumn(*args, **kwargs)[source]

Bases: TimeModelMixin, UserModelMixin, StatusModelMixin, ValidateOnSaveMixin

This model defines all the fields used in models that implement dynamic columns.

BOOLEAN = 1
CHOICE = 2
DATE = 3
DATETIME = 4
exception DoesNotExist

Bases: ObjectDoesNotExist

FLOAT = 5
exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

NO = False
NUMBER = 6
TEXT = 7
TEXT_BLOCK = 8
TIME = 9
VALUE_TYPES = ((1, 'Boolean'), (2, 'Choice'), (3, 'Date'), (4, 'Date Time'), (5, 'Floating Point'), (6, 'Number'), (7, 'Text'), (8, 'Text Block'), (9, 'Time'))
VALUE_TYPES_MAP = {1: 'Boolean', 2: 'Choice', 3: 'Date', 4: 'Date Time', 5: 'Floating Point', 6: 'Number', 7: 'Text', 8: 'Text Block', 9: 'Time'}
YES = True
YES_NO = ((False, 'No'), (True, 'Yes'))
clean()[source]

Validate the proper operation between the slug and preferred_slug fields and the relation and value_type fields.

collection_producer()[source]

Produces a Collection name that is used in the Django admin.

Return type:

A comma separated list of Collection names.

column_collection

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

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.

get_choice_relation_object_and_field()[source]

Gets the model class object and the field passed in when dcolumn_manager.register_choice was configured. If this DynamicColumn was not used for a choice model then a tuple of two Nones are returned.

Example of Output:

(example_site.books.models.Promotion, 'name')

or

(None, None)
Return type:

tuple

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)
get_required_display(*, field=<django.db.models.fields.BooleanField: required>)
get_store_relation_display(*, field=<django.db.models.fields.BooleanField: store_relation>)
get_value_type_display(*, field=<django.db.models.fields.IntegerField: value_type>)
id

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

keyvalues

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

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

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

location

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.

objects = <dcolumn.dcolumns.models.DynamicColumnManager object>
order

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

preferred_slug

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

relation

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

relation_producer()[source]

Produces a CHOICE relation that is used in the Django admin.

Return type:

The CHOICE relation or empty string.

required

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]

Be sure the complete MRO has their saves called.

slug

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

store_relation

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

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.

value_type

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

class dcolumn.dcolumns.models.DynamicColumnManager(*args, **kwargs)[source]

Bases: StatusModelManagerMixin

Supplies methods to the DynamicColumn objects instance.

get_fk_slugs()[source]

This method returns a dict of the relation model foreign key name and slug.

Return type:

A dict of {<relation class name>: <slug>, ...}.

class dcolumn.dcolumns.models.KeyValue(id, collection, dynamic_column, value)[source]

Bases: ValidateOnSaveMixin

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

collection

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.

collection_id
dynamic_column

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.

dynamic_column_id
id

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

objects = <dcolumn.dcolumns.models.KeyValueManager object>
save(*args, **kwargs)[source]

Be sure the complete MRO has their saves called.

value

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

class dcolumn.dcolumns.models.KeyValueManager(*args, **kwargs)[source]

Bases: Manager

dcolumn.dcolumns.urls module

dcolumn.dcolumns.views module