This section of the django-lass-metadata documentation is automatically generated from the code.
The metadata app contains the generic metadata system used in LASS, which allows objects in the LASS model set to contain key-value stores of textual, image-based and other formats of metadata by inheriting a mixin and providing a subclass of the standard metadata models.
The metadata app is dedicated to the LASS metadata system, which allows various different strands of data (generally text, but also image-based and other formats) to be attached to items.
LASS uses the metadata system, for example, to provide shows with names and descriptions that have full recorded history and hooks for an approval system. It is also used to associate images (thumbnails and player insets) with podcasts.
Each model can have zero or more strands of metadata attached to it. Each strand is its own model (see below for more information on how to create a metadata provider model), and represents a specific collection of metadata on objects in the subject model.
Strands are indexed by name; an entire strand (as a dictionary-like object) can be retrieved from an implementor of MetadataSubjectMixin with object.metadata()['strand-name']. Generally, there will be a text strand containing all textual metadata, and an images strand containing thumbnail images and other related pictorial metadata.
All metadata strands are implemented as key-value stores, the key store being implemented as one unified model for simplicity reasons and the value stores being separate for each strand for each model.
Two classes (metadata.mixins.MetadataSubjectMixin and metadata.models.GenericMetadata) provide the core framework for defining a metadata subject and a metadata strand. There are descendents of GenericMetadata available for specific commonly used strand types.
In the LASS project, examples of how to use the metadata system can be found in schedule.models.show, uryplayer.models.podcast and people.models.role.
The metadata module contains several model definitions under metadata.models.
The MetadataKey model, which forms the key in the metadata key-value storage system.
Bases: lass_utils.models.type.Type
A metadata key, which defines the semantics of a piece of metadata.
Bases: django.core.exceptions.ObjectDoesNotExist
Bases: django.core.exceptions.MultipleObjectsReturned
Generic metadata base class.
Bases: people.mixins.approvable.ApprovableMixin, lass_utils.mixins.attachable.AttachableMixin, people.mixins.creatable.CreatableMixin, lass_utils.mixins.effective_range.EffectiveRangeMixin
An item of generic metadata.
NOTE TO IMPLEMENTORS: The final concrete instances of this class must have a field named ‘element’ that foreign key references the element of data to which the metadata is to be attached.
Any further implementors must also include a field named ‘value’ that stores the metadatum value.
Models for the URY text metadata system.
To add metadata to a model, create a subclass of ‘Metadata’ for that model, descend the model from ‘MetadataSubjectMixin’, and fill out the methods identified in those two classes.
Models for the URY image metadata system.
To add metadata to a model, create a subclass of ‘ImageMetadata’ for that model, descend the model from ‘ImageMetadataSubjectMixin’, and fill out the methods identified in those two classes.
Bases: metadata.models.generic.GenericMetadata
Abstract base class for usages of images as metadata.
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.
Bases: django.db.models.base.Model
An abstract base class for models representing types, categories or other keyed collections of other models.
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 |
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.
The metadata module contains mixins for adding metadata to existing models and suchlike.
Administration system hooks for the metadata application.
Bases: django.contrib.admin.options.ModelAdmin
An adminstration snap-in for maintaining the list of metadata keys.
Bases: django.contrib.admin.options.ModelAdmin
An administration snap-in for maintaining the list of packages.
Bases: metadata.admin_base.ImageMetadataInline
alias of PackageImageMetadata
Bases: metadata.admin_base.TextMetadataInline
alias of PackageTextMetadata
Registers the metadata admin hooks with an admin site.
Test suite for the metadata package.
TODO: Cache tests
Bases: django.db.models.base.Model, metadata.mixins.metadata_subject.MetadataSubjectMixin
Test metadata subject model.
Bases: django.core.exceptions.ObjectDoesNotExist
Bases: django.core.exceptions.MultipleObjectsReturned
Bases: django.test.testcases.TestCase
Tests to see if the dictionary access method for metadata is functional on multiple-entry metadata.
Tests whether getting image metadata works.
Tests whether getting textual metadata works.
Tests whether the metadata view supports ‘in’.
Bases: django.test.testcases.TestCase
Tests to see if the metadata packages system is hooked in correctly and used as a fallback metadata source.
Tests whether the package is used to provide default textual metadata.
Bases: django.test.testcases.TestCase
Tests to see if the dictionary access method for metadata is functional on single-entry metadata.
Tests whether default metadata works as expected.
Tests whether the single metadata getting system correctly respects the effective_from and effective_to bounds.
Tests whether getting image metadata works.
Tests whether getting textual metadata works.
Tests whether the metadata view supports ‘in’.
Base admin classes for metadata administration.
Bases: django.contrib.admin.options.TabularInline
Base inline class for anything that’s like metadata.
Provides a form field for foreign keys.
Overrides the normal inline so that submitter and approver are set, by default, to the currently logged in user.
Bases: metadata.admin_base.MetadataInline
Specialisation of MetadataInline for image metadata.
Bases: django.contrib.admin.options.ModelAdmin
Base class for metadata admin-lets.
Bases: metadata.admin_base.GeneralMetadataInline
Base inline class for metadata inline admin-lets.
Bases: metadata.admin_base.GeneralMetadataInline
Snap-in for editing package entries inline.
Bases: metadata.admin_base.MetadataInline
Specialisation of MetadataInline for text metadata.
Default hooks for the metadata system, as well as a function for running metadata hooks on queries.
Bases: exceptions.Exception
Exception raised when a metadata hook fails to fulfil a query, but not in a way that should halt execution.
Bases: exceptions.Exception
Exception raised when a metadata query returns no results, but was expected to do so.
From the given queryset, extracts metadata matching the given key that was active at the given date.
Attempts to get a metadata strand related-set from the element of the given query, given the query’s requested strand.
Handles a metadata set as required by the metadata’s multiplicity and the metadata query type.
Parameters: |
|
---|
Given a metadata query, attempts to fulfil the request using the Django cache.
Parameters: | query (metadata.query.MetadataQuery or similar object.) – The MetadataQuery this hook is trying to run. |
---|
Given a metadata query, attempts to return the default value for the metadata key in the given strand.
Will raise metadata.hooks.HookFailureError on failure.
Parameters: | query (metadata.query.MetadataQuery or similar object.) – The MetadataQuery this hook is trying to run. |
---|
Given a metadata query, attempts to use the query element’s designated metadata packages to fulfil the request.
Will raise metadata.hooks.HookFailureError on failure.
Parameters: | query (metadata.query.MetadataQuery or similar object.) – The MetadataQuery this hook is trying to run. |
---|
Given a metadata query, attempts to use the query element’s designated parent to fulfil the request.
Will raise metadata.hooks.HookFailureError on failure.
Parameters: | query (metadata.query.MetadataQuery or similar object.) – The MetadataQuery this hook is trying to run. |
---|
Given a metadata query, attempts to use the query element’s own metadata sets to fulfil the request.
Will raise metadata.hooks.HookFailureError on failure.
Parameters: | query (metadata.query.MetadataQuery or similar object.) – The MetadataQuery this hook is trying to run. |
---|
Runs a metadata query, optionally with the given set of hooks.
If hooks is None, the default set will be used. (See metadata.hooks.DEFAULT_HOOKS)
Parameters: |
|
---|
In which a metadata query is defined.
Bases: object
An object that holds together all state required for a query for metadata on a metadata subject to be run.
For running a metadata query, see the metadata.hooks module.
Generally, however, most code shouldn’t need to use metadata queries directly. A sugary frontend is provided by metadata.mixins.MetadataSubjectMixin.
Returns a representation of the query that can be used as a cache key.
Return type: | basestring |
---|
Returns the target metadata date of this query.
This will be the time of query creation if no date was specified.
Returns the value that should be the initial state of any running of this query.
Join two successful query runnings in a way that satisfies the query’s requirements.
The old state is given precedence so, for example, trying to join two results for a value query on a single-value key will return the old state only.
Parameters: |
|
---|
Creates a new query representing the query with the initialising parameters in kwargs replacing their counterparts in this query.
Parameters: | kwargs – A keyword argument dict of substitutions to make. |
---|
Given an intermediate result of a metadata query run, returns True if there need not be any more hook processing in order to get a valid answer to the query.
Parameters: | result – the current result of a metadata query run |
---|