Source

graphalchemy / graphalchemy / models / elements.py

Full commit
# -*- coding: utf-8 -*-
'''graph element models'''

from stuf.utils import lazy_class, selfname

from graphalchemy.core import octopus, join
from graphalchemy.mixins.elements import NodeMixin, ElementMixin

__all__ = ['Node']
# settings
conf = octopus.G


class Node(NodeMixin, ElementMixin, octopus.workflow.Thing):

    '''node model'''

    # node collection
    _nodes = join(conf.model.collector.node, conf.models)

    @lazy_class
    def L(self):
        '''local settings'''
        class_names = self.names
        metas = dict(
            # properties to index
            indexed=set(k for k in class_names(indexed=True)),
            # properties indexed for full text search
            fts_indexed=set(k for k in class_names(full_text=True)),
            # properties to HTML escape
            escaped=set(k for k in class_names(escaped=True)),
            # model name
            name=selfname(self),
        )
        # slug field
        try:
            metas['slug_from'] = class_names(slug_from=True)[0]
        except IndexError:
            metas['slug_from'] = ''
        return self.M.localize(self, metas)

    def _version(self):
        '''increment current snapshot number of node'''
        self.update({'_versions': self._current['_versions'] + 1})
        return self._current['_versions']

    def anchor(self, anchor, **kw):
        '''link node to anchor'''
        self._l.create(self.L.anchor_link, self, anchor, kw)

    class Meta:
        # anchor link label
        anchor_link = ''
        # fork link label
        fork_link = ''
        # full text index name
        fts_index = ''
        # index name
        index = ''
        # reference link label
        reference_link = ''
        # root index name
        root_index = 'roots'
        # slug field name
        slug_field = ''
        # snapshot link label
        version_link = ''
        # whether to track changes
        versioned = False