How to use the clld.db.models.common.Value 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_datatables_value.py View on Github external
def test_Values(request_factory, params):
    with request_factory(params=params) as req:
        handle_dt(req, Values, common.Value)
github clld / clld / tests / test_web_util_helpers.py View on Github external
def test_format_frequency(env, mocker, utility_factory):
    from clld.web.util.helpers import format_frequency

    format_frequency(env['request'], common.Value.first())
    format_frequency(env['request'], mocker.Mock(frequency=None))

    with utility_factory(mocker.Mock(return_value='url'), IFrequencyMarker):
        format_frequency(env['request'], common.Value.first())
github clld / clld / tests / test_web_adapters_excel.py View on Github external
        (Values, Value, datatables.Values),
        (Sentences, Sentence, datatables.Sentences),
    ])
def test_adapter(env, adapter, model, datatable):
    adapter(None).render_to_response(datatable(env['request'], model), env['request'])
github clld / glottolog3 / glottolog3 / scripts / util.py View on Github external
def add_values(data, dblang, pid, values, with_de=True, **vskw):
    vs = None
    for i, (vid, vname) in enumerate(values):
        if i == 0:
            vs = common.ValueSet(
                id=idjoin(pid, dblang.id),
                language=dblang,
                parameter=data['Parameter'][pid],
                contribution=data['Contribution']['glottolog'],
                **vskw)
        vkw = dict(id=idjoin(pid, slug(vid), dblang.id), name=vname, valueset=vs)
        if with_de:
            vkw['domainelement'] = data['DomainElement'][pid, vid]
        DBSession.add(common.Value(**vkw))
github clld / glottolog3 / glottolog3 / scripts / update_lginfo.py View on Github external
vs = None
            for _vs in l.valuesets:
                if _vs.parameter.id == id_:
                    vs = _vs
                    break

            if not vs:
                args.log.info('%s %s ++' % (l.id, type_))
                vs = ValueSet(
                    id='%s%s' % (id_, l.pk),
                    description=comment,
                    language=l,
                    parameter=Parameter.get(id_),
                    contribution=Contribution.first())
                DBSession.add(Value(
                    id='%s%s' % (id_, l.pk),
                    name='%s - %s' % (l.level, l.status),
                    valueset=vs))
                DBSession.flush()
            else:
                if vs.description != comment:
                    args.log.info('%s %s ~~ description: %s ---> %s' % (l.id, type_, vs.description, comment))
                    vs.description = comment
                    stats.update(['justifications-%s' % type_])

            for r in vs.references:
                DBSession.delete(r)

            for r, pages in refs:
                # FIXME: we must make sure not to link sources which will subsequently be
                # replaced!
github clld / glottolog3 / glottolog3 / langdocstatus.py View on Github external
def count(ppk):
        return DBSession.query(common.DomainElement.pk, func.count(common.Value.pk))\
            .join(common.Value)\
            .join(common.ValueSet)\
            .join(common.Language)\
            .filter(Languoid.category.in_(CATEGORIES))\
            .filter(common.DomainElement.parameter_pk == ppk)\
            .group_by(common.DomainElement.pk)
github clld / clld / src / clld / web / adapters / cldf.py View on Github external
if model == Value:
            res = {
                'ID': item.id,
                'Language_ID': self.pk2id['Language'][item.valueset.language_pk],
                'Parameter_ID': self.pk2id['Parameter'][item.valueset.parameter_pk],
                'Contribution_ID': self.pk2id['Contribution'][item.valueset.contribution_pk],
                'Value': (item.domainelement.name if item.domainelement else item.name) or '-',
                'Source': [
                    '{0}{1}'.format(self.pk2id['Source'][spk], d) for spk, d in iterrefs(item)],
            }
            if item.domainelement_pk:
                res['Code_ID'] = self.pk2id['DomainElement'][item.domainelement_pk]
            if self.module == 'Wordlist':
                res['Form'] = res['Value']
            return res
        raise Value(model)  # pragma: no cover
github clld / glottolog3 / glottolog3 / adapters.py View on Github external
query = req.db.query(
                Languoid.id, Family.id.label('family_id'), Father.id.label('parent_id'),
                Languoid.name,
                Languoid.bookkeeping,
                sa.type_coerce(Languoid.level, sa.Text).label('level'),
                Languoid.latitude, Languoid.longitude,
                sa.select([Identifier.name])
                    .where(LanguageIdentifier.identifier_pk == Identifier.pk)
                    .where(LanguageIdentifier.language_pk == Language.pk)
                    .where(Identifier.type == 'iso639-3')
                    .label('iso639P3code'),
                Languoid.description, Languoid.markup_description,
                Languoid.child_family_count, Languoid.child_language_count, Languoid.child_dialect_count,
                sa.select([sa.literal_column("string_agg(_country.name, ' ' ORDER BY _country.name)")])
                    .where(Value.domainelement_pk == _Country.pk)
                    .where(Value.valueset_pk == ValueSet.pk)
                    .where(ValueSet.parameter_pk == Parameter.pk)
                    .where(Parameter.id == 'country')
                    .where(ValueSet.language_pk == Languoid.pk)
                    .label('country_ids'),
            ).select_from(Languoid).filter(Languoid.active)\
            .outerjoin(Family, Family.pk == Languoid.family_pk)\
            .outerjoin(Father, Father.pk == Languoid.father_pk)\
            .order_by(Languoid.id)
        return query
github clld / glottolog3 / glottolog3 / langdocstatus.py View on Github external
def count(ppk):
        return DBSession.query(common.DomainElement.pk, func.count(common.Value.pk))\
            .join(common.Value)\
            .join(common.ValueSet)\
            .join(common.Language)\
            .filter(Languoid.category.in_(CATEGORIES))\
            .filter(common.DomainElement.parameter_pk == ppk)\
            .group_by(common.DomainElement.pk)
github clld / clld / src / clld / web / datatables / value.py View on Github external
def order(self):
        return DomainElement.number \
            if self.dt.parameter and self.dt.parameter.domain \
            else Value.description