Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for key, value in req.registry.settings.items():
if key.startswith('clld.publication.'):
md[key.split('clld.publication.', 1)[1]] = value
template = StringTemplate(md.get('template', """\
$authors. $year. $title.
In: $editors (eds.)
$sitetitle.
$place: $publisher.
Available online at $url
Accessed on $accessed.
"""))
return template.safe_substitute(**md)
@implementer(interfaces.IRepresentation)
class GeoJson(Renderable):
"""Base class for adapters which render geojson feature collections.
"""
extension = 'geojson'
mimetype = 'application/geojson'
send_mimetype = 'application/json'
def featurecollection_properties(self, ctx, req):
return {} # pragma: no cover
def feature_iterator(self, ctx, req):
return iter([]) # pragma: no cover
def feature_properties(self, ctx, req, feature):
return {} # pragma: no cover
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),
]
__version__ = "4.0.1"
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,
def register_resource_adapters(config, rsc):
name, interface = rsc.name, rsc.interface
config.register_adapter(
getattr(excel, rsc.plural.capitalize(), excel.ExcelAdapter), interface)
cls = type('Json%s' % rsc.model.__name__, (Json,), {})
config.register_adapter(
cls, interface, to_=interfaces.IRepresentation, name=Json.mimetype)
specs = []
if rsc.with_index:
specs.append((Index, 'application/atom+xml', 'atom', 'index_atom.mako', {}))
config.register_adapter(
getattr(csv, rsc.name.capitalize() + 's', csv.CsvAdapter),
interface,
interfaces.IIndex,
name=csv.CsvAdapter.mimetype)
config.register_adapter(
csv.CsvmJsonAdapter,
interface,
interfaces.IIndex,
name=csv.CsvmJsonAdapter.mimetype)
cls = type('JsonIndex%s' % rsc.model.__name__, (JsonIndex,), {})
@implementer(interfaces.IRepresentation, interfaces.IMetadata)
class ReferenceManager(MetadataFromRec):
"""Resource metadata in RIS format."""
name = 'RIS'
__label__ = 'RIS'
unapi = 'ris'
extension = 'md.ris'
mimetype = "application/x-research-info-systems"
def render(self, ctx, req):
return self.rec(ctx, req).format('ris')
@implementer(interfaces.IRepresentation, interfaces.IMetadata)
class TxtCitation(Metadata):
"""Resource metadata formatted as plain text citation."""
name = "Citation"
__label__ = 'Text'
extension = 'md.txt'
mimetype = 'text/plain'
def render(self, ctx, req):
if interfaces.IContribution.providedBy(ctx):
self.template = 'contribution/md_txt.mako'
else: # if interfaces.IDataset.providedBy(ctx):
self.template = 'dataset/md_txt.mako'
return super(TxtCitation, self).render(ctx, req)
IdNameDescriptionMixin,
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())
def render(self, ctx, req):
if interfaces.IContribution.providedBy(ctx):
self.template = 'contribution/md_txt.mako'
else: # if interfaces.IDataset.providedBy(ctx):
self.template = 'dataset/md_txt.mako'
return super(TxtCitation, self).render(ctx, req)
def get_rdf_dumps(req, model):
rdf_exts = [n.extension for n in rdf.FORMATS.values()]
for name, dl in req.registry.getUtilitiesFor(interfaces.IDownload):
if dl.model == model and dl.ext in rdf_exts:
yield dl
'Language', 'LanguageSource',
'IdentifierType', 'Identifier', 'LanguageIdentifier',
)
class Language_data(Base, Versioned, DataMixin):
"""Associated data mapper."""
class Language_files(Base, Versioned, FilesMixin):
"""Associated files mapper."""
@implementer(interfaces.ILanguage)
class Language(Base,
PolymorphicBaseMixin,
Versioned,
IdNameDescriptionMixin,
HasDataMixin,
HasFilesMixin):
"""Languages are the main objects of discourse.
We attach a geo-coordinate to them to be able to put them on maps.
"""
latitude = Column(
Float(),
CheckConstraint('-90 <= latitude and latitude <= 90'),
doc='geographical latitude in WGS84')
__version__ = "5.2.1.dev0"
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,