XMM Core Models

class Attribute(*args, **values)[source]

An attribute used by Models, dynamic model definitions, Nodes, Pages etc.

key

Unique. Visible in frontend under “key” symbol.

label

Name tag that makes sense to the user.

description

Description that makes sense to the user.

field_class

Defines attribute field type and its behaviour.

metadata

Additional info like if it references a model or is choice-based.

default

A default value.

nullable

Flag, if true, this attribute’s value can be NULL

hidden

Never show this attribute in UI

multilingual

Is multilingual

multivalue

Can have list of values.

mutable

Changeable in frontend.

unit

Units that values of this attribute have.

use_si_prefixes

Automatically show metric units with their largest suitable SI prefix (e.g. 52319 shows as 52k)

fields

Meta-Attribute fields

classmethod post_delete(sender, document, **kwargs)[source]

Remove all values stored in the database belonging to this attribute.

remove_all_values()[source]

Remove all values of this attribute in the database.

to_elastic()[source]

Return data to be indexed in elasticsearch.

field[source]

Get the Field instance for this attribute.

to_dict(**data)[source]

Get a dict representation suitable for JSON of this instance.

Parameters

data – additional items to be added.

classmethod find_referencing_models()[source]

Find models that should be searched for references of this class.

find_dynamic_usages()[source]

Find usages of this attribute in other dynamic models.

Returns

a list of models (definitions) where this attribute is referenced.

exception DoesNotExist
exception MultipleObjectsReturned
class AttributeGroup(*args, **kwargs)[source]

A model may have attributes grouped together.

key

Unique. Visible in frontend under “key” symbol.

label

Name tag that makes sense to the user.

description

Description that makes sense to the user.

attributes

List of attributes in this group.

to_dict()[source]

Get a dict representation suitable for JSON of this instance.

Parameters

data – additional items to be added.

class ModelReference(*args, **kwargs)[source]
model

References model

key

Unique. Visible in frontend under “key” symbol.

label

Name tag that makes sense to the user.

label_plural

Plural name tag that makes sense to the user.

disallow_sorting

Flag to disallow “manual” sorting of the referenced datasets

iter_by_query(linked_ids: list)[source]

Fetch documents linked by ModelLinks for this ModelReference.

If this is a reference for ‘actors’ on a model ‘movie’ then this method will yield all movies linking the specified actor(s).

class File(*args, **values)[source]
path

Path to file.

missing

Is file deleted from storage?

filename

Actual filename including file extension.

size

Size of file in bytes.

mimetype

Mimetype of file.

isdir

Is it a directory?

title

Title of the file.

description

Text that makes sense to the user.

alt_text

Alternative text shown if frontend can’t load image.

hidden

Is it hidden? Defaults to True for file names starting with a period “.”

ctime

Created time.

mtime

Modified time.

classmethod get_module_permission()[source]

Get the module permission required for this model.

to_api_json(**options)[source]

Return json data for api methods.

classmethod build_elastic_query(term, multilingual=True)[source]

Build a search query for a term.

Parameters
  • term (str) – The search term.

  • multilingual (bool) – Set to False to search only the current language.

classmethod create_from_json(json)[source]

Create a new instance and set its properties with data from the given json dict.

classmethod find_referencing_models()[source]

Find models that should be searched for references of this class.

update_from_json(json, compare_timestamps=True)[source]

Update the current instance with data from the given json dict.

classmethod from_field_map(field_map, dataset, is_list=False)[source]

Find an instance by looking up fields in a referencing dataset.

basename

Get the filename without extension.

get_thumbnail_path(size)[source]

Get absolute path to the thumbnail.

clear_thumbnails()[source]

Remove all cached thumbnails.

classmethod iter_tree_nodes(parent, order_by=None)[source]

Iterate over the subnodes of a given parent.

Parameters

parent (str) – Iterate over this node’s children

move_to(parent, pos=None)[source]

Move the specified node to a new parent.

TODO: This deletes any existing file in the target directory with the same name. This should be configurable.

Parameters
get_meta_data[source]

Read the EXIF data from the file.

Return type

list

Example of a result:

[{
    'category': 'category1',
    'tags': [{
        'tag': 'tag1',
        'value': 'value1'
    }, {
        'tag': 'tag2',
        'value': 'value2'
    }]
}, {
    'category': 'category2',
    'tags': [{
        'tag': 'tag1',
        'value': 'value1'
    }]
}]
image_dimensions[source]

Get the image pixel size as a (width, height) tuple.

clone(**kwargs)[source]

Copy this file or folder.

Parameters

path (str) – New path where the copy should be saved.

Returns

A clone of this File.

Return type

xmm.models.File

exception DoesNotExist
exception MultipleObjectsReturned
class Index(*args, **kwargs)[source]

Index class that defines database level indexes for dynamic models.

key

Unique. Visible in frontend under “key” symbol.

type

What kind of index?, ‘index’ or ‘unique’.

attributes

List of keys of attributes that are part of the index.

model

Model identifier; either a string or ObjectId

reference

Object id of document that is referenced.

is_url

Is it a URL?

url

URL if it is a url.

urlsuffix

Optional text to append to the URL.

title

Title of Link that can be multilingual.

target

HTML target (e.g., ‘_blank’)

anchor

HTML anchor (<a href=”…” id={{ anchor }}>)

class_name

CSS class (<a href=”…” class={{ class_name }}>)

class Model(*args, **values)[source]
title

Title of model

indices

Indices of model

mixins

Class mixins to apply on model

classmethod get_read_permission(obj_id=None)[source]

Get read permission.

Reading Model definitions is always allowed.

to_dict(**data)[source]

Get a dict representation suitable for JSON of this instance.

Parameters

data – additional items to be added.

get_indices(index_key)[source]

Return the by key matching index or raise KeyError.

set_indices(new_index)[source]

Set the by key matching index.

remove_indices(index_key)[source]

Remove the by key matching index or raise KeyError.

get_impl_permissions()[source]

Check access to this Model class for users.

impl_objects(**kwargs)[source]

Return a filtered cursor for this definition’s implementation instances.

Parameters

kwargs – Additional kwargs passed to the query.

classmethod find_referencing_models()[source]

Find models that should be searched for references of this class.

api_reset_column_widths()[source]

Reset columns to default.

api_set_column_widths(**kwargs)[source]

Set new values specified by user’s dragging action.

exception DoesNotExist
exception MultipleObjectsReturned
class Node(*args, **values)[source]

A node implements a node type.

A single node may define any number of additional attributes, which will be available on every linked model instance. Attribute selection is only available if the node’s type has has_classification set to True.

type_field = 'nodetype'

Needed for dynamic models to know that this thing is instance of nodetype.

parent

Page that is parent of this page.

pos

Represents position of page in tree.

nodetype

References type of this node.

classmethod get_module_permission()[source]

Get the module permission required for this model.

classmethod get_impl_class() → type[source]

Get implementation class.

A node may reference datasets as a classification. In this case the impl_class is the node itself.

classmethod find_referencing_models()[source]

Find models that should be searched for references of this class.

classmethod create_from_json(json)[source]

Create a new instance and set its properties with data from the given json dict.

update_from_json(json, compare_timestamps=True)[source]

Update the current instance with data from the given json dict.

classmethod clone_tree(old_parent, new_parent)[source]

Clone child nodes and set their new parent.

Parameters
  • old_parent (Node) – Previous parent

  • new_parent (Node) – New parent

to_elastic()[source]

Return data to be indexed in elasticsearch.

Return the Referencing class object for this model.

exception DoesNotExist
exception MultipleObjectsReturned
class Tag(*args, **values)[source]

Tags will be used for everything in the XMM. But first only for media etc.

key

Unique key of the tag.

classmethod get_read_permission(obj_id=None)[source]

Read of Model definitions is always allowed.

classmethod find_referencing_models()[source]

Find models that should be searched for references of this class.

Should yield pairs of [(model, filter_key)].

exception DoesNotExist
exception MultipleObjectsReturned