How to use the clld.db.models.common.Parameter 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 / tests / test_web_maps.py View on Github external
        ('language', dict(z=3, lat=1, lng=1), Map, common.Parameter, 'parameter'),
        ('language', {'z': 'abc'}, Map, common.Parameter, 'parameter'),
        ('parameter', {}, ParameterMap, common.Parameter, 'parameter'),
        ('parameter', {}, ParameterMap, common.Parameter, 'no-domain'),
        ('language', {}, LanguageMap, common.Language, 'language'),
    ])
def test_Map(request_factory, route, params, map_cls, ctx_cls, ctx_id):
    with request_factory(matched_route=route, params=params) as req:
        m = map_cls(ctx_cls.get(ctx_id), req)
        m.render()
github clld / clld / tests / test_db_models.py View on Github external
def test_Combination(data):
    from clld.db.models.common import Combination, Parameter

    p = Parameter.first()
    c = Combination.get(Combination.delimiter.join(2 * [p.id]))
    assert c.values
    assert c.domain
    assert c.__json__()
github clld / clld / tests / test_web_util_multiselect.py View on Github external
def test_CombinationMultiSelect(env):
    from clld.web.util.multiselect import CombinationMultiSelect

    ms = CombinationMultiSelect(
        env['request'], combination=common.Combination(common.Parameter.first()))
    ms.render()
github clld / clld / tests / test_web_datatables_parameter.py View on Github external
def test_Parameters(env):
    from clld.web.datatables.parameter import Parameters

    handle_dt(env['request'], Parameters, common.Parameter)
github clld / clld / tests / test_web_templates.py View on Github external
for rsc in _RESOURCES:
        if not hasattr(rsc.model, 'first'):
            continue
        ctx = rsc.model.first()
        res = render(
            '%s/rdf.mako' % rsc.name, dict(ctx=ctx), request=env['request'])
        assert not qname_as_resource.search(res)
        g = Graph()
        g.load(io.StringIO(res))
        for predicate in ['void:inDataset', 'skos:prefLabel']:
            if predicate == 'void:inDataset' and rsc.name == 'dataset':
                continue
            subject = URIRef(env['request'].resource_url(ctx))
            predicate = URIRef(rdf.url_for_qname(predicate))
            assert (subject, predicate, None) in g
    p = Parameter.get('parameter')
    res = render('parameter/rdf.mako', dict(ctx=p), request=env['request'])
    assert p.domain[0].name in res
github clld / clld / src / clld / web / datatables / valueset.py View on Github external
from sqlalchemy.orm import joinedload

from clld.db.models.common import (
    ValueSet, Parameter, Language, Contribution, ValueSetReference,
)
from clld.web.datatables.base import (
    DataTable, LinkCol, DetailsRowLinkCol, LinkToMapCol, RefsCol,
)


class Valuesets(DataTable):

    """Default DataTable for ValueSet objects."""

    __constraints__ = [Parameter, Contribution, Language]

    def base_query(self, query):
        query = query.join(Language)\
            .options(
                joinedload(
                    ValueSet.language
                ),
                joinedload(
                    ValueSet.references
                ).joinedload(
                    ValueSetReference.source
                ))

        if self.language:
            query = query.join(Parameter).options(joinedload(ValueSet.parameter))
            return query.filter(ValueSet.language_pk == self.language.pk)
github clld / clld / src / clld / __init__.py View on Github external
class Resource(namedtuple('Resource', 'name model interface with_index with_rdfdump')):

    def __new__(cls, name, model, interface, with_index=True, with_rdfdump=True):
        return super(Resource, cls).__new__(cls, name, model, interface, with_index, with_rdfdump)

    @property
    def plural(self):
        return self.name + 's'


RESOURCES = [
    Resource('dataset', common.Dataset, interfaces.IDataset, with_index=False),
    Resource('contribution', common.Contribution, interfaces.IContribution),
    Resource('parameter', common.Parameter, interfaces.IParameter),
    Resource('language', common.Language, interfaces.ILanguage),
    Resource('contributor', common.Contributor, interfaces.IContributor),
    Resource('source', common.Source, interfaces.ISource),
    Resource('sentence', common.Sentence, interfaces.ISentence),
    Resource('valueset', common.ValueSet, interfaces.IValueSet),
    Resource('value', common.Value, interfaces.IValue),
    Resource('unitparameter', common.UnitParameter, interfaces.IUnitParameter),
    Resource('unit', common.Unit, interfaces.IUnit),
    Resource('unitvalue', common.UnitValue, interfaces.IUnitValue),
    Resource(
        'combination',
        common.Combination,
        interfaces.ICombination,
        with_index=False,
        with_rdfdump=False),
]
github clld / glottolog3 / glottolog3 / scripts / util.py View on Github external
def add_parameter(data, id_, domain=None, name=None, pkw=None, dekw=None, delookup='id'):
    p = data.add(common.Parameter, id_, id=id_, name=name or id_.capitalize(), **pkw or {})
    for de in sorted(domain or []):
        kw = dict(id=idjoin(p.id, de.id), parameter=p)
        if dekw:
            kw.update(dekw(de))
        data.add(common.DomainElement, (p.id, getattr(de, delookup)), **kw)
github clld / clld / clld / web / util / helpers.py View on Github external
param = req.params.get('parameter')
    if param is None:  # pragma: no cover
        return

    try:
        param = int(param)
    except ValueError:  # pragma: no cover
        pass

    query = DBSession.query(models.ValueSet)\
        .filter(models.ValueSet.language_pk == ctx.pk)

    if isinstance(param, int):
        query = query.filter(models.ValueSet.parameter_pk == param)
    else:  # pragma: no cover
        query = query.join(models.Parameter).filter(models.Parameter.id == param)

    return query.first()
github clld / clld / src / clld / web / views / sitemap.py View on Github external
common.Identifier.type != 'name')
        )).filter(common.Language.active == true()).order_by(common.Language.id)

        def resources():
            for (id, name, lat, lon), rows in groupby(q, itemgetter(0, 1, 2, 3)):
                identifiers = [
                    {'type': r.itype, 'identifier': r.iname.lower()
                     if r.itype.startswith('WALS') else r.iname}
                    for r in rows if r.iname is not None]
                yield {'id': id, 'name': name, 'latitude': lat, 'longitude': lon,
                       'identifiers': identifiers}
    elif rsc == 'parameter':
        q = DBSession.query(
            common.Parameter.id,
            common.Parameter.name
        ).order_by(common.Parameter.pk)

        def resources():
            for id, name in q:
                yield {'id': id, 'name': name}
    else:
        return HTTPNotFound()

    return {
        'properties': {
            'dataset': req.dataset.id,
            'uri_template': get_url_template(req, rsc, relative=False)},
        'resources': list(resources())}