Source

graphalchemy / graphalchemy / properties.py

Full commit
# -*- coding: utf-8 -*-
'''graph model properties'''

import sys

from spine.traits import Trait
from spine.keys.core import NoDefault
from spine.traits import Regex, Bool, Float as Ft, Integer, Unicode

__all__ = (
    'BooleanField', 'CharField', 'FloatField', 'IntegerField', 'StringField',
    'TextField',
)


class PropertyMixin(Trait):

    metadata = dict(property=True)

    def __init__(self, initial=NoDefault, **kw):
        kw.update(dict(property=True, indexed=kw.get('indexed', False)))
        super(PropertyMixin, self).__init__(initial, **kw)


class StringMixin(PropertyMixin):

    def __init__(self, initial=NoDefault, **kw):
        kw.update(dict(
            escaped=kw.get('escaped', False),
            slug_from=kw.get('slug_from', False)
        ))
        super(StringMixin, self).__init__(initial, **kw)


class BooleanField(PropertyMixin, Bool):

    '''boolean field'''


class CharField(StringMixin, Regex):

    '''checked string field'''

    def __init__(self, value='', minlen=0, maxlen=sys.maxsize, regex='', **kw):
        super(CharField, self).__init__(value, minlen, maxlen, regex, **kw)


class FloatField(PropertyMixin, Ft):

    '''float field'''


class IntegerField(PropertyMixin, Integer):

    '''integer field'''


class StringField(StringMixin, Unicode):

    '''string field'''


class TextField(StringField):

    '''string that can be full text searched'''

    def __init__(self, initial=NoDefault, **kw):
        super(TextField, self).__init__(initial, **kw)
        kw.update(dict(full_text=kw.get('full_text', False)))