How to use the clld.db.meta.Base function in clld

To help you get started, we’ve selected a few clld examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github clld / clld / src / clld / db / models / sentence.py View on Github external
language_pk = Column(Integer, ForeignKey('language.pk'))

    @declared_attr
    def language(cls):
        return relationship(
            'Language', backref=backref('sentences', order_by=cls.language_pk))

    @property
    def audio(self):
        for f in self._files:
            if f.mime_type.split('/')[0] == 'audio':
                return f


class SentenceReference(Base, Versioned, HasSourceNotNullMixin):

    """Association table."""

    __table_args__ = (
        UniqueConstraint('sentence_pk', 'source_pk', 'description'),
    )

    sentence_pk = Column(Integer, ForeignKey('sentence.pk'), nullable=False)
    sentence = relationship(Sentence, innerjoin=True, backref="references")
github clld / clld / src / clld / db / models / unitvalue.py View on Github external
from zope.interface import implementer

from clld.db.meta import Base, PolymorphicBaseMixin
from clld.db.versioned import Versioned
from clld import interfaces

from . import (
    IdNameDescriptionMixin,
    DataMixin, HasDataMixin, FilesMixin, HasFilesMixin,
    unitparameter as _unitparameter)  # needed to initalize relationship
assert _unitparameter

__all__ = ('UnitValue',)


class UnitValue_data(Base, Versioned, DataMixin):
    pass


class UnitValue_files(Base, Versioned, FilesMixin):
    pass


@implementer(interfaces.IUnitValue)
class UnitValue(Base,
                PolymorphicBaseMixin,
                Versioned,
                IdNameDescriptionMixin,
                HasDataMixin,
                HasFilesMixin):

    __table_args__ = (UniqueConstraint(
github clld / clld / src / clld / db / models / source.py View on Github external
DataMixin, HasDataMixin, FilesMixin, HasFilesMixin,
    Language, LanguageSource)

__all__ = ('Source', 'HasSourceMixin', 'HasSourceNotNullMixin')


class Source_data(Base, Versioned, DataMixin):
    pass


class Source_files(Base, Versioned, FilesMixin):
    pass


@implementer(interfaces.ISource)
class Source(Base,
             PolymorphicBaseMixin,
             Versioned,
             IdNameDescriptionMixin,
             HasDataMixin,
             HasFilesMixin):

    """A bibliographic record, cited as source for some statement."""

    glottolog_id = Column(String)
    google_book_search_id = Column(String)

    #
    # BibTeX fields:
    #
    bibtex_type = Column(bibtex.EntryType.db_type())
    author = Column(Unicode)
github clld / clld / src / clld / db / models / value.py View on Github external
from clld.db.meta import Base, PolymorphicBaseMixin
from clld.db.versioned import Versioned
from clld import interfaces

from . import (
    IdNameDescriptionMixin,
    DataMixin, HasDataMixin, FilesMixin, HasFilesMixin,
    Sentence, ValueSet,
    parameter as _parameter)  # needed to initalize relationship
assert _parameter

__all__ = ('Value', 'ValueSentence')


class Value_data(Base, Versioned, DataMixin):
    pass


class Value_files(Base, Versioned, FilesMixin):
    pass


@implementer(interfaces.IValue)
class Value(Base,
            PolymorphicBaseMixin,
            Versioned,
            IdNameDescriptionMixin,
            HasDataMixin,
            HasFilesMixin):

    """A measurement of a parameter for a particular language."""
github clld / clld / src / clld / db / models / unitparameter.py View on Github external
from . import IdNameDescriptionMixin, DataMixin, HasDataMixin, FilesMixin, HasFilesMixin

__all__ = ('UnitDomainElement', 'UnitParameter')


class UnitDomainElement_data(Base, Versioned, DataMixin):
    pass


class UnitDomainElement_files(Base, Versioned, FilesMixin):
    pass


@implementer(interfaces.IUnitDomainElement)
class UnitDomainElement(Base,
                        PolymorphicBaseMixin,
                        Versioned,
                        IdNameDescriptionMixin,
                        HasDataMixin,
                        HasFilesMixin):

    """Domain element for the domain of a UnitParameter."""

    __table_args__ = (
        UniqueConstraint('unitparameter_pk', 'name'),
        UniqueConstraint('unitparameter_pk', 'ord'),
    )

    unitparameter_pk = Column(Integer, ForeignKey('unitparameter.pk'), nullable=False)
    ord = Column(Integer)
github clld / clld / src / clld / db / models / parameter.py View on Github external
"""abbreviated name, e.g. as label for map legends"""

    def url(self, request):
        return request.resource_url(self.parameter, _anchor='DE-' + self.id)


class Parameter_data(Base, Versioned, DataMixin):
    pass


class Parameter_files(Base, Versioned, FilesMixin):
    pass


@implementer(interfaces.IParameter)
class Parameter(Base,
                PolymorphicBaseMixin,
                Versioned,
                IdNameDescriptionMixin,
                HasDataMixin,
                HasFilesMixin):

    """A measurable attribute of a language."""

    __table_args__ = (UniqueConstraint('name'),)

    domain = relationship(
        'DomainElement', backref='parameter', order_by=DomainElement.number)


class CombinationDomainElement(object):
    def __init__(self, combination, domainelements, icon=None):
github clld / clld / src / clld / db / models / dataset.py View on Github external
res = ' with '.join([res, _format(secondary)])  # pragma: no cover
        return res

    def formatted_name(self):
        return HTML.span(
            self.name,
            **{
                'xmlns:dct': "http://purl.org/dc/terms/",
                'href': "http://purl.org/dc/dcmitype/Dataset",
                'property': "dct:title",
                'rel': "dct:type",
                'class': 'Dataset'}
        )


class Editor(Base, PolymorphicBaseMixin, Versioned):

    """Many-to-many association between contributors and dataset."""

    __table_args__ = (UniqueConstraint('dataset_pk', 'contributor_pk'),)

    dataset_pk = Column(Integer, ForeignKey('dataset.pk'), nullable=False)
    contributor_pk = Column(Integer, ForeignKey('contributor.pk'), nullable=False)

    # contributors are ordered.
    ord = Column(Integer, default=1)

    # we distinguish between primary and secondary (a.k.a. 'with ...') contributors.
    primary = Column(Boolean, default=True)

    contributor = relationship(
        Contributor, innerjoin=True, lazy=False, backref=backref('editor', uselist=False))
github clld / clld / src / clld / db / models / unitparameter.py View on Github external
UniqueConstraint('unitparameter_pk', 'name'),
        UniqueConstraint('unitparameter_pk', 'ord'),
    )

    unitparameter_pk = Column(Integer, ForeignKey('unitparameter.pk'), nullable=False)
    ord = Column(Integer)

    def url(self, request):
        return request.resource_url(self.parameter, _anchor='DE-%s' % self.id)


class UnitParameter_data(Base, Versioned, DataMixin):
    pass


class UnitParameter_files(Base, Versioned, FilesMixin):
    pass


@implementer(interfaces.IUnitParameter)
class UnitParameter(Base,
                    PolymorphicBaseMixin,
                    Versioned,
                    IdNameDescriptionMixin,
                    HasDataMixin,
                    HasFilesMixin):

    """A measurable attribute of a unit."""

    domain = relationship(
        'UnitDomainElement', backref='parameter', order_by=UnitDomainElement.id)
github clld / clld / src / clld / db / models / contribution.py View on Github external
key=lambda a: (a.ord, a.contributor.id)) if assoc.primary]

    @property
    def secondary_contributors(self):
        return [assoc.contributor for assoc in
                sorted(self.contributor_assocs,
                       key=lambda a: (a.ord, a.contributor.id)) if not assoc.primary]

    def formatted_contributors(self):
        contribs = [' and '.join(c.name for c in self.primary_contributors)]
        if self.secondary_contributors:
            contribs.append(' and '.join(c.name for c in self.secondary_contributors))
        return ' with '.join(contribs)


class ContributionReference(Base, Versioned, HasSourceNotNullMixin):

    """Association table."""

    __table_args__ = (
        UniqueConstraint('contribution_pk', 'source_pk', 'description'),
    )

    contribution_pk = Column(Integer, ForeignKey('contribution.pk'), nullable=False)
    contribution = relationship(Contribution, innerjoin=True, backref="references")


class ContributionContributor(Base, PolymorphicBaseMixin, Versioned):

    """Many-to-many association between contributors and contributions."""

    __table_args__ = (UniqueConstraint('contribution_pk', 'contributor_pk'),)