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.

field[source]

Get the Field instance for this attribute.

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

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]
basename

The filename without extension.

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.
clear_thumbnails()[source]

Remove all cached thumbnails.

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
classmethod find_referencing_models()[source]

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

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

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

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'
    }]
}]
get_thumbnail_path(size)[source]

Get absolute path to the thumbnail.

image_dimensions[source]

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

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

Generator that loops 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:
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 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]

Reading Model definitions is always allowed.

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.

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_impl_class()[source]

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

clone_before_save(clone)[source]

Hook called before saving a new clone.

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]

Reading Model definitions is always allowed.