Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_DataTable(env, request_factory):
dt = Table(env['request'], common.Contributor)
assert 'exclude' in dt._toolbar.options
assert str(dt) == 'Contributors'
assert repr(dt) == 'Contributors'
dt.get_query(undefer_cols=['updated']).all()
html = dt.render()
assert 'xytt' in html
assert ' multiple ' in html
def test_table(env):
handle_dt(env['request'], Unitparameters, common.UnitParameter)
(None, common.Contributor, {}, None),
(None, common.Sentence, {}, None),
(None, common.Value, {}, None),
(
None,
common.Contributor,
{'is_xhr': True, 'params': {'sEcho': 'a'}},
'application/json'),
(
None,
common.Contributor,
{'is_xhr': True, 'params': {'sEcho': 'a'}},
'application/json'),
(
None,
common.Contributor,
{
def test_Sources(request_factory, params):
with request_factory(params=params) as req:
handle_dt(req, Sources, common.Source)
def base_query(self, query):
query = query\
.join(common.Unit)\
.outerjoin(common.UnitDomainElement)\
.options(joinedload(common.UnitValue.unit))
if self.unit:
return query.filter(common.UnitValue.unit_pk == self.unit.pk)
if self.unitparameter:
return query.filter(
common.UnitValue.unitparameter_pk == self.unitparameter.pk)
if self.contribution:
return query.filter(common.UnitValue.contribution_pk == self.contribution.pk)
return query
provs.add(prov)
DBSession.add(models.Refprovider(
provider_pk=data['Provider'][prov].pk,
ref_pk=ref.pk,
id='{0}:{1}'.format(prov, key)))
if not reflangs:
reflangs, trigger = entry.languoids(lgcodes)
if trigger and ((provs in no_ca) or (reflangs)):
# Discard computerized assigned languoids for bibs where this does not make sense,
# or for bib entries that have been manually assigned in a Languoid's ini file.
reflangs, trigger = [], None
for lid in set(reflangs):
DBSession.add(
common.LanguageSource(
language_pk=data['Languoid'][lid].pk, source_pk=ref.pk, active=not bool(trigger)))
if trigger:
ref.ca_language_trigger = trigger
doctypes, trigger = entry.doctypes(data['Doctype'])
if trigger is None or provs not in no_ca:
for dt in set(doctypes):
DBSession.add(models.Refdoctype(doctype_pk=dt.pk, ref_pk=ref.pk))
if trigger:
ref.ca_doctype_trigger = trigger
return ref
if query == custom_query:
# no customizations done, apply the defaults
f = getattr(model, 'refine_factory_query', None)
if f:
query = f(query)
else:
if model == common.Contribution:
query = query.options(
joinedload(
common.Contribution.valuesets
).joinedload(
common.ValueSet.parameter
),
joinedload(
common.Contribution.valuesets
).joinedload(
common.ValueSet.values
).joinedload(
common.Value.domainelement
),
joinedload(
common.Contribution.references
).joinedload(
common.ContributionReference.source
),
joinedload(
common.Contribution.data
)
)
else:
query = custom_query # pragma: no cover
def dataset(self):
"""Convenient access to the Dataset object.
Properties of the :py:class:`clld.db.models.common.Dataset` object an
application serves are used in various places, so we want to have a reference to
it.
"""
return self.db.query(common.Dataset).options(undefer('updated')).first()
def order(self):
return common.UnitDomainElement.id \
if self.dt.unitparameter and self.dt.unitparameter.domain \
else [common.UnitValue.name, common.UnitValue.id]
def search(self, qs):
if self.dt.unitparameter and self.dt.unitparameter.domain:
return common.UnitDomainElement.name.contains(qs)
return common.UnitValue.name.contains(qs)
class Unitvalues(DataTable):
"""Default DataTable for UnitValue objects."""
__constraints__ = [common.UnitParameter, common.Contribution, common.Unit]
def base_query(self, query):
query = query\
.join(common.Unit)\
.outerjoin(common.UnitDomainElement)\
.options(joinedload(common.UnitValue.unit))
if self.unit:
return query.filter(common.UnitValue.unit_pk == self.unit.pk)
if self.unitparameter:
return query.filter(
common.UnitValue.unitparameter_pk == self.unitparameter.pk)
if self.contribution:
return query.filter(common.UnitValue.contribution_pk == self.contribution.pk)
joinedload(
common.Contribution.valuesets
).joinedload(
common.ValueSet.parameter
),
joinedload(
common.Contribution.valuesets
).joinedload(
common.ValueSet.values
).joinedload(
common.Value.domainelement
),
joinedload(
common.Contribution.references
).joinedload(
common.ContributionReference.source
),
joinedload(
common.Contribution.data
)
)
else:
query = custom_query # pragma: no cover
return query.one()