How to use the idutils.to_url function in idutils

To help you get started, we’ve selected a few idutils 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 zenodo / zenodo / zenodo / modules / records / serializers / fields / doi.py View on Github external
def _serialize(self, value, attr, obj):
        if value is None:
            return None
        return idutils.to_url(value, 'doi', 'https')
github zenodo / zenodo / zenodo / modules / records / views.py View on Github external
def apply_rule(item, rule):
        r = copy.deepcopy(rule)
        r['link'] = idutils.to_url(item['identifier'], item['scheme'], 'https')
        return r
github zenodo / zenodo / zenodo / modules / records / serializers / schemas / common.py View on Github external
def _dump_common_links(self, obj):
        """Dump common links for deposits and records."""
        links = {}
        m = obj.get('metadata', {})

        doi = m.get('doi')
        if doi:
            links['badge'] = ui_link_for('badge', doi=quote(doi))
            links['doi'] = idutils.to_url(doi, 'doi', 'https')

        conceptdoi = m.get('conceptdoi')
        if conceptdoi:
            links['conceptbadge'] = ui_link_for('badge', doi=quote(conceptdoi))
            links['conceptdoi'] = idutils.to_url(conceptdoi, 'doi', 'https')

        files = m.get('_files', [])
        for f in files:
            if f.get('type') in thumbnail_exts:
                try:
                    # First previewable image is used for preview.
                    links['thumbs'] = self._thumbnail_urls(m.get('recid'))
                    links['thumb250'] = self._thumbnail_url(f, 250)
                except RuntimeError:
                    pass
                break
github zenodo / zenodo / zenodo / modules / records / serializers / schemas / schemaorg.py View on Github external
def _serialize_identifiers(ids, relations=None):
    """Serialize related and alternate identifiers to URLs.

    :param ids: List of related_identifier or alternate_identifier objects.
    :param relations: if not None, will only select IDs of specific relation
    :returns: List of identifiers in schema.org format.
    :rtype dict:
    """
    relations = relations or []
    ids = [{'@type': 'CreativeWork',
             '@id': idutils.to_url(i['identifier'], i['scheme'], 'https')}
            for i in ids if (not relations or i['relation'] in relations) and 'scheme' in i]
    return [id_ for id_ in ids if id_['@id']]
github zenodo / zenodo / zenodo / modules / records / serializers / schemas / schemaorg.py View on Github external
def _serialize_subjects(ids):
    """Serialize subjects to URLs."""
    return [{'@type': 'CreativeWork',
             '@id': idutils.to_url(i['identifier'], i['scheme'], 'https')}
            for i in ids if 'scheme' in i]
github zenodo / zenodo / zenodo / modules / records / serializers / schemas / schemaorg.py View on Github external
def get_id(self, obj):
        """Get URL for the person's ORCID or GND."""
        orcid = obj.get('orcid')
        gnd = obj.get('gnd')
        if orcid:
            return idutils.to_url(orcid, 'orcid', 'https')
        if gnd:
            return idutils.to_url(gnd, 'gnd', 'https')
        return missing
github zenodo / zenodo / zenodo / modules / records / views.py View on Github external
def pid_url(identifier, scheme=None, url_scheme='https'):
    """Convert persistent identifier into a link."""
    if scheme is None:
        try:
            scheme = idutils.detect_identifier_schemes(identifier)[0]
        except IndexError:
            scheme = None
    try:
        if scheme and identifier:
            return idutils.to_url(identifier, scheme, url_scheme=url_scheme)
    except Exception:
        current_app.logger.warning('URL generation for identifier {0} failed.'
                                   .format(identifier), exc_info=True)
    return ''