def _resource_preview(self, data_dict):
     if 'format' not in data_dict['resource'] or not data_dict['resource']['format']:
         return False
     return bool(datapreview.res_format(data_dict['resource'])
                 in datapreview.direct() + datapreview.loadable()
                 or datapreview.get_preview_plugin(
                     data_dict, return_first=True))
Beispiel #2
0
def hdx_resource_preview(resource, package):
    ## COPY OF THE DEFAULT HELPER BY THE SAME NAME BUT FORCES URLS OVER HTTPS
    '''
    Returns a rendered snippet for a embedded resource preview.

    Depending on the type, different previews are loadeSd.
    This could be an img tag where the image is loaded directly or an iframe
    that embeds a web page, recline or a pdf preview.
    '''

    if not resource['url']:
        return h.snippet("dataviewer/snippets/no_preview.html",
                       resource_type=format_lower,
                       reason=_(u'The resource url is not specified.'))

    format_lower = datapreview.res_format(resource)
    directly = False
    data_dict = {'resource': resource, 'package': package}

    if datapreview.get_preview_plugin(data_dict, return_first=True):
        url = h.url_for(controller='package', action='resource_datapreview',
                      resource_id=resource['id'], id=package['id'], qualified=True)
    elif format_lower in datapreview.direct():
        directly = True
        url = resource['url']
    elif format_lower in datapreview.loadable():
        url = resource['url']
    else:
        reason = None
        if format_lower:
            log.info(
                _(u'No preview handler for resource of type {0}'.format(
                    format_lower))
            )
        else:
            reason = _(u'The resource format is not specified.')
        return h.snippet("dataviewer/snippets/no_preview.html",
                       reason=reason,
                       resource_type=format_lower)

    return h.snippet("dataviewer/snippets/data_preview.html",
                   embed=directly,
                   resource_url=url,
                   raw_resource_url=https_load(resource.get('url')))
def _resource_preview(data_dict):
    return bool(
        datapreview.res_format(data_dict['resource'])
        in datapreview.direct() + datapreview.loadable()
        or datapreview.get_preview_plugin(data_dict, return_first=True))
def _resource_preview(data_dict):
    return bool(datapreview.res_format(data_dict['resource'])
                    in datapreview.direct() + datapreview.loadable()
                    or datapreview.get_preview_plugin(
                        data_dict, return_first=True))