def includeme(config):
    config.register_resource("family", Family, IFamily, with_index=True)
    config.registry.settings["mako.directories"].append("clld_glottologfamily_plugin:templates")

    specs = [
        [Representation, "text/html", "html", "family/detail_html.mako", {}],
        [Index, "text/html", "html", "family/index_html.mako", {}],
        [
            RdfIndex,
            FORMATS["xml"].mimetype,
            FORMATS["xml"].extension,
            "index_rdf.mako",
            {"rdflibname": FORMATS["xml"].name},
        ],
    ]
    for fmt in FORMATS.values():
        specs.append(
            [
                Rdf,
                fmt.mimetype,
                fmt.extension,
                "family/rdf.mako",
                {"name": "RDF serialized as %s" % fmt.name, "rdflibname": fmt.name},
            ]
        )
    config.register_adapters([[IFamily] + spec for spec in specs])
    config.register_adapter(GeoJson, IFamily)
    config.register_map("family", Map)
    config.register_datatable("familys", Familys)
Example #2
0
def includeme(config):
    config.register_resource('family', Family, IFamily, with_index=True)
    config.registry.settings['mako.directories'].append(
        'clld_glottologfamily_plugin:templates')

    specs = [[
        Representation, 'text/html', 'html', 'family/detail_html.mako', {}
    ], [Index, 'text/html', 'html', 'family/index_html.mako', {}],
             [
                 RdfIndex, FORMATS['xml'].mimetype, FORMATS['xml'].extension,
                 'index_rdf.mako', {
                     'rdflibname': FORMATS['xml'].name
                 }
             ]]
    for fmt in FORMATS.values():
        specs.append([
            Rdf, fmt.mimetype, fmt.extension, 'family/rdf.mako', {
                'name': 'RDF serialized as %s' % fmt.name,
                'rdflibname': fmt.name
            }
        ])
    config.register_adapters([[IFamily] + spec for spec in specs])
    config.register_adapter(GeoJson, IFamily)
    config.register_map('family', Map)
    config.register_datatable('familys', Familys)
Example #3
0
 def __init__(self, model, pkg, **kw):
     if self.ext is None:
         self.ext = kw['ext']
     self.rdf = self.ext in [fmt.extension for fmt in FORMATS.values()]
     self.model = model
     self.pkg = pkg_name(pkg)
     for k, v in kw.items():
         setattr(self, k, v)
Example #4
0
 def __init__(self, model, pkg, **kw):
     if self.ext is None:
         self.ext = kw['ext']
     self.rdf = self.ext in [fmt.extension for fmt in FORMATS.values()]
     self.model = model
     self.pkg = pkg_name(pkg)
     for k, v in kw.items():
         setattr(self, k, v)
Example #5
0
 def __init__(self, model, pkg, **kw):
     if self.ext is None:
         self.ext = kw['ext']
     self.rdf = self.ext in [fmt.extension for fmt in FORMATS.values()]
     self.model = model
     self.pkg = pkg if isinstance(pkg, basestring) else pkg.__name__
     for k, v in kw.items():
         setattr(self, k, v)
Example #6
0
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, ), {})
        config.register_adapter(cls,
                                interface,
                                to_=interfaces.IIndex,
                                name=JsonIndex.mimetype)
        if template_exists(config, name + '/index_html.mako'):
            # ... as html index
            specs.append(
                (Index, 'text/html', 'html', name + '/index_html.mako', {}))

    # ... as RDF in various notations
    rdf_resource_template = name + '/rdf.mako'
    if not template_exists(config, rdf_resource_template):
        rdf_resource_template = 'resource_rdf.mako'

    for notation in RDF_NOTATIONS.values():
        specs.append((
            Rdf,
            notation.mimetype,
            notation.extension,
            rdf_resource_template,
            {
                'name': 'RDF serialized as %s' % notation.name,
                'rdflibname': notation.name
            },
        ))

    # ... as RDF collection index
    rdf_xml = RDF_NOTATIONS['xml']
    specs.append(
        (RdfIndex, rdf_xml.mimetype, rdf_xml.extension, 'index_rdf.mako', {
            'rdflibname': rdf_xml.name
        }))

    if template_exists(config, name + '/detail_html.mako'):
        # ... as html details page
        specs.append((Representation, 'text/html', 'html',
                      name + '/detail_html.mako', {}))
    if template_exists(config, name + '/snippet_html.mako'):
        # ... as html snippet (if the template exists)
        specs.append((Representation, 'application/vnd.clld.snippet+xml',
                      'snippet.html', name + '/snippet_html.mako', {
                          'rel': None
                      }))

    config.register_adapters([[interface] + list(spec) for spec in specs])
Example #7
0
def includeme(config):
    """register adapters
    """
    specs = []
    for rsc in RESOURCES:
        # each resource is available ...
        name, interface = rsc.name, rsc.interface

        # ... as json
        cls = type('Json%s' % rsc.model.mapper_name(), (Json, ), {})
        config.registry.registerAdapter(cls, (interface, ),
                                        interfaces.IRepresentation,
                                        name=Json.mimetype)

        if rsc.with_index:
            # ... as html index
            specs.append((interface, Index, 'text/html', 'html',
                          name + '/index_html.mako', {}))

        # ... as html details page
        specs.append((interface, Representation, 'text/html', 'html',
                      name + '/detail_html.mako', {}))
        # ... as html snippet (if the template exists)
        specs.append(
            (interface, Representation, 'application/vnd.clld.snippet+xml',
             'snippet.html', name + '/snippet_html.mako', {}))

        # ... as RDF in various notations
        for notation in RDF_NOTATIONS.values():
            specs.append((interface, Rdf, notation.mimetype,
                          notation.extension, name + '/rdf.mako', {
                              'rdflibname': notation.name
                          }))

        # ... as RDF collection index
        rdf_xml = RDF_NOTATIONS['xml']
        specs.append((interface, RdfIndex, rdf_xml.mimetype, rdf_xml.extension,
                      'index_rdf.mako', {
                          'rdflibname': rdf_xml.name
                      }))

    # citeable resources are available as html page listing available metadata formats:
    for _if in [interfaces.IContribution, interfaces.IDataset]:
        specs.append((_if, Representation, 'application/vnd.clld.md+xml',
                      'md.html', 'md_html.mako', {}))

    specs.extend([
        (interfaces.ILanguage, Index, 'application/vnd.google-earth.kml+xml',
         'kml', 'clld:web/templates/language/kml.mako', {
             'send_mimetype': 'application/xml'
         }),
        (interfaces.ILanguage, Representation,
         'application/vnd.google-earth.kml+xml', 'kml',
         'clld:web/templates/language/kml.pt', {
             'send_mimetype': 'application/xml'
         }),
        (interfaces.IContribution, Index, 'text/html', 'html',
         'contribution/index_html.mako', {}),
    ])

    for i, spec in enumerate(specs):
        interface, base, mimetype, extension, template, extra = spec
        extra.update(mimetype=mimetype, extension=extension, template=template)
        cls = type('Renderer%s' % i, (base, ), extra)
        config.registry.registerAdapter(cls, (interface, ),
                                        list(implementedBy(base))[0],
                                        name=mimetype)

    for cls in [BibTex, TxtCitation, ReferenceManager]:
        for if_ in [interfaces.IRepresentation, interfaces.IMetadata]:
            for adapts in [interfaces.IContribution, interfaces.IDataset]:
                config.registry.registerAdapter(cls, (adapts, ),
                                                if_,
                                                name=cls.mimetype)

    config.registry.registerAdapter(GeoJsonLanguages, (interfaces.ILanguage, ),
                                    interfaces.IIndex,
                                    name=GeoJson.mimetype)
    config.registry.registerAdapter(GeoJsonParameter,
                                    (interfaces.IParameter, ),
                                    interfaces.IRepresentation,
                                    name=GeoJson.mimetype)

    config.include(biblio)
Example #8
0
def includeme(config):
    """register adapters
    """
    specs = []
    for rsc in RESOURCES:
        # each resource is available ...
        name, interface = rsc.name, rsc.interface

        # ... as json
        cls = type('Json%s' % rsc.model.mapper_name(), (Json,), {})
        config.registry.registerAdapter(
            cls, (interface,), interfaces.IRepresentation, name=Json.mimetype)
        cls = type('Solr%s' % rsc.model.mapper_name(), (SolrDoc,), {})
        config.registry.registerAdapter(
            cls, (interface,), interfaces.IRepresentation, name=SolrDoc.mimetype)

        if rsc.with_index:
            # ... as html index
            specs.append(
                (interface, Index, 'text/html', 'html', name + '/index_html.mako', {}))
            specs.append(
                (interface, Index, 'application/atom+xml', 'atom', 'index_atom.mako', {}))

        # ... as html details page
        specs.append(
            (interface, Representation, 'text/html', 'html', name + '/detail_html.mako',
             {}))
        # ... as html snippet (if the template exists)
        specs.append(
            (interface, Representation, 'application/vnd.clld.snippet+xml',
             'snippet.html', name + '/snippet_html.mako', {'rel': None}))

        # ... as RDF in various notations
        for notation in RDF_NOTATIONS.values():
            specs.append((
                interface,
                Rdf,
                notation.mimetype,
                notation.extension,
                name + '/rdf.mako',
                {
                    'name': 'RDF serialized as %s' % notation.name,
                    'rdflibname': notation.name}))

        # ... as RDF collection index
        rdf_xml = RDF_NOTATIONS['xml']
        specs.append((
            interface,
            RdfIndex,
            rdf_xml.mimetype,
            rdf_xml.extension,
            'index_rdf.mako', {'rdflibname': rdf_xml.name}))

    # citeable resources are available as html page listing available metadata formats:
    for _if in [interfaces.IContribution, interfaces.IDataset]:
        specs.append((
            _if,
            Representation,
            'application/vnd.clld.md+xml',
            'md.html',
            'md_html.mako',
            {'rel': 'describedby'}))

    specs.append((
        interfaces.ILanguage, Index,
        'application/vnd.google-earth.kml+xml',
        'kml',
        'clld:web/templates/language/kml.mako',
        {'send_mimetype': 'application/xml'}))

    for i, spec in enumerate(specs):
        interface, base, mimetype, extension, template, extra = spec
        extra.update(mimetype=mimetype, extension=extension, template=template)
        cls = type('Renderer%s' % i, (base,), extra)
        config.registry.registerAdapter(
            cls, (interface,), list(implementedBy(base))[0], name=mimetype)

    for cls in [BibTex, TxtCitation, ReferenceManager]:
        for if_ in [interfaces.IRepresentation, interfaces.IMetadata]:
            for adapts in [interfaces.IContribution, interfaces.IDataset]:
                config.registry.registerAdapter(
                    cls,
                    (adapts,),
                    if_,
                    name=cls.mimetype)

    config.registry.registerAdapter(
        GeoJsonLanguages,
        (interfaces.ILanguage,),
        interfaces.IIndex,
        name=GeoJson.mimetype)
    config.registry.registerAdapter(
        GeoJsonParameter,
        (interfaces.IParameter,),
        interfaces.IRepresentation,
        name=GeoJson.mimetype)
    config.registry.registerAdapter(
        GeoJsonParameterFlatProperties,
        (interfaces.IParameter,),
        interfaces.IRepresentation,
        name=GeoJsonParameterFlatProperties.mimetype)

    config.include(biblio)
Example #9
0
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)
    cls = type('Solr%s' % rsc.model.__name__, (SolrDoc,), {})
    config.register_adapter(
        cls, interface, to_=interfaces.IRepresentation, name=SolrDoc.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,), {})
        config.register_adapter(
            cls, interface, to_=interfaces.IIndex, name=JsonIndex.mimetype)
        if template_exists(config, name + '/index_html.mako'):
            # ... as html index
            specs.append((Index, 'text/html', 'html', name + '/index_html.mako', {}))

    # ... as RDF in various notations
    rdf_resource_template = name + '/rdf.mako'
    if not template_exists(config, rdf_resource_template):
        rdf_resource_template = 'resource_rdf.mako'

    for notation in RDF_NOTATIONS.values():
        specs.append((
            Rdf,
            notation.mimetype,
            notation.extension,
            rdf_resource_template,
            {'name': 'RDF serialized as %s' % notation.name, 'rdflibname': notation.name},
        ))

    # ... as RDF collection index
    rdf_xml = RDF_NOTATIONS['xml']
    specs.append((
        RdfIndex,
        rdf_xml.mimetype,
        rdf_xml.extension,
        'index_rdf.mako',
        {'rdflibname': rdf_xml.name}))

    if template_exists(config, name + '/detail_html.mako'):
        # ... as html details page
        specs.append(
            (Representation, 'text/html', 'html', name + '/detail_html.mako', {}))
    if template_exists(config, name + '/snippet_html.mako'):
        # ... as html snippet (if the template exists)
        specs.append((
            Representation,
            'application/vnd.clld.snippet+xml',
            'snippet.html',
            name + '/snippet_html.mako',
            {'rel': None}))

    config.register_adapters([[interface] + list(spec) for spec in specs])