Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def col_defs(self):
return [Col(self, 'latitude'), TestCol(self, 'pk')]
def __init__(self, dt, name, **kw):
kw.setdefault('sTitle', dt.req.translate('Type'))
kw.setdefault('choices', get_distinct_values(Sentence.type))
super(TypeCol, self).__init__(dt, name, **kw)
def search(self, qs):
return Sentence.type == qs
def format(self, item):
return item.type
def order(self):
return Sentence.type
class TsvCol(Col):
def search(self, qs):
return super(TsvCol, self).search('\t'.join(qs.split()))
class AudioCol(Col):
def __init__(self, dt, name, **kw):
kw['choices'] = ['yes']
kw['input-size'] = 'mini'
kw['model_col'] = Sentence_files.id
Col.__init__(self, dt, name, **kw)
def format(self, item):
if item.audio:
return icon('volume-up')
def order(self):
class DoctypeCol(_CollectionCol):
cls = Doctype
attr = 'doctypes'
route = 'home.glossary'
def query(self):
return DBSession.query(self.cls).order_by(self.cls.ord)
class ProviderCol(_CollectionCol):
cls = Provider
attr = 'providers'
route = 'providers'
class CaCol(Col):
def __init__(self, dt, name, **kw):
kw['bSearchable'] = False
kw['sTitle'] = 'ca'
kw['sDescription'] = 'computerized assignment of ' + name[3:]
self.attr = '%s_trigger' % name
super(CaCol, self).__init__(dt, name, **kw)
def order(self):
return getattr(Ref, self.attr)
def format(self, item):
return format_ca_icon(self.dt.req, item, self.attr.split('_')[1])
class DirectAssignmentCol(Col):
def format(self, item):
return [
NameCol(self, 'name'),
LevelCol(self, 'level'),
MacroareaCol(self, 'macro-area', model_col=Languoid.macroareas),
Col(self, 'child_family_count', model_col=Languoid.child_family_count, sTitle='Sub-families'),
Col(self, 'child_language_count', model_col=Languoid.child_language_count, sTitle='Child languages'),
FamilyCol(self, 'top-level family'),
]
return [
Col(self, 'id', sTitle='Glottocode'),
NameCol(self, 'name'),
FamilyCol(self, 'top-level family'),
IsoCol(self, 'iso', sTitle='ISO-639-3'),
MacroareaCol(self, 'macro-area', model_col=Languoid.macroareas),
Col(self, 'child_dialect_count', model_col=Languoid.child_dialect_count, sTitle='Child dialects', sClass='right'),
Col(self, 'latitude'),
Col(self, 'longitude'),
]
def col_defs(self):
return [
IdCol(self, 'id'),
LinkCol(self, 'name'),
LinkToMapCol(self, 'm'),
Col(self,
'latitude',
sDescription='<small>The geographic latitude</small>'),
Col(self,
'longitude',
sDescription='<small>The geographic longitude</small>'),
]
def col_defs(self):
if self.type == 'families':
return [
NameCol(self, 'name'),
LevelCol(self, 'level'),
MacroareaCol(self, 'macro-area', model_col=Languoid.macroareas),
Col(self, 'child_family_count', model_col=Languoid.child_family_count, sTitle='Sub-families'),
Col(self, 'child_language_count', model_col=Languoid.child_language_count, sTitle='Child languages'),
FamilyCol(self, 'top-level family'),
]
return [
Col(self, 'id', sTitle='Glottocode'),
NameCol(self, 'name'),
FamilyCol(self, 'top-level family'),
IsoCol(self, 'iso', sTitle='ISO-639-3'),
MacroareaCol(self, 'macro-area', model_col=Languoid.macroareas),
Col(self, 'child_dialect_count', model_col=Languoid.child_dialect_count, sTitle='Child dialects', sClass='right'),
Col(self, 'latitude'),
Col(self, 'longitude'),
]
if self.type == 'families':
return [
NameCol(self, 'name'),
LevelCol(self, 'level'),
MacroareaCol(self, 'macro-area', model_col=Languoid.macroareas),
Col(self, 'child_family_count', model_col=Languoid.child_family_count, sTitle='Sub-families'),
Col(self, 'child_language_count', model_col=Languoid.child_language_count, sTitle='Child languages'),
FamilyCol(self, 'top-level family'),
]
return [
Col(self, 'id', sTitle='Glottocode'),
NameCol(self, 'name'),
FamilyCol(self, 'top-level family'),
IsoCol(self, 'iso', sTitle='ISO-639-3'),
MacroareaCol(self, 'macro-area', model_col=Languoid.macroareas),
Col(self, 'child_dialect_count', model_col=Languoid.child_dialect_count, sTitle='Child dialects', sClass='right'),
Col(self, 'latitude'),
Col(self, 'longitude'),
]
def col_defs(self):
return [
Col(self, 'id', bSortable=False, input_size='mini'),
LinkCol(self, 'name', sTitle='Primary text', sClass="object-language"),
TsvCol(self, 'analyzed', sTitle='Analyzed text'),
TsvCol(self, 'gloss', sClass="gloss"),
Col(self,
'description',
sTitle=self.req.translate('Translation'),
sClass="translation"),
TypeCol(self, 'type'),
LinkCol(
self,
'language',
model_col=Language.name,
get_obj=lambda i: i.language,
bSortable=not self.language,
bSearchable=not self.language),
DetailsRowLinkCol(self, 'd'),
cols = [DetailsRowLinkCol(self, 'd', button_text='citation')]
if self.provider:
cols.append(BibkeyCol(self, 'key'))
cols.extend([
LinkCol(self, 'name'),
Col(self,
'description',
sTitle='Title',
sType='string',
format=lambda i: HTML.span(i.description)),
FtsCol(self, 'fts', model_col=Ref.fts),
CaCol(self, 'ca_language'),
])
if not self.complexquery:
cols.append(Col(self, 'year', model_col=Source.year_int))
cols.append(Col(self, 'pages', model_col=Source.pages_int))
cols.append(DoctypeCol(self, 'doctype'))
cols.append(CaCol(self, 'ca_doctype'))
if not self.provider:
cols.append(ProviderCol(self, 'provider'))
if self.language:
cols.append(DirectAssignmentCol(
self, 'd',
sTitle='da',
sDescription="Signals whether the reference is directly assigned to this languoid "
"or inherited from daughter languoids.",
bSortable=False,
bSearchable=False))
return cols
"""Default DataTable for Sentence objects."""
from sqlalchemy import and_
from sqlalchemy.orm import joinedload
from clld.db.util import get_distinct_values
from clld.db.models.common import (
Language, Sentence, Parameter, ValueSentence, Value, ValueSet, Sentence_files,
)
from clld.web.datatables.base import (
DataTable, LinkCol, DetailsRowLinkCol, Col,
)
from clld.web.util.helpers import icon
class TypeCol(Col):
"""Render the type attribute of a Sentence."""
def __init__(self, dt, name, **kw):
kw.setdefault('sTitle', dt.req.translate('Type'))
kw.setdefault('choices', get_distinct_values(Sentence.type))
super(TypeCol, self).__init__(dt, name, **kw)
def search(self, qs):
return Sentence.type == qs
def format(self, item):
return item.type
def order(self):
return Sentence.type