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))
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 False 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 = tk.url_for(controller='package', action='resource_datapreview', resource_id=resource['id'], id=package['id'], qualified=True) else: return False return h.snippet("dataviewer/snippets/data_preview.html", embed=directly, resource_url=url, raw_resource_url=https_load(resource.get('url')))
def datapreview(package_type, id, resource_id): """ Embedded page for a resource data-preview. Depending on the type, different previews are loaded. This could be an img tag where the image is loaded directly or an iframe that embeds a webpage, or a recline preview. """ context = { u'model': model, u'session': model.Session, u'user': g.user, u'auth_user_obj': g.userobj } try: resource = get_action(u'resource_show')(context, {u'id': resource_id}) package = get_action(u'package_show')(context, {u'id': id}) data_dict = {u'resource': resource, u'package': package} preview_plugin = lib_datapreview.get_preview_plugin(data_dict) if preview_plugin is None: return base.abort(409, _(u'No preview has been defined.')) preview_plugin.setup_template_variables(context, data_dict) resource_json = json.dumps(resource) dataset_type = package[u'type'] or package_type # TODO: remove g.resource = resource g.package = package g.resource_json = resource_json except (NotFound, NotAuthorized): return base.abort(404, _(u'Resource not found')) else: return base.render( preview_plugin.preview_template(context, data_dict), { u'dataset_type': dataset_type, u'resource': resource, u'package': package, u'resource_json': resource_json } )
def resource_datapreview(self, id, resource_id): ''' Embedded page for a resource data-preview. Depending on the type, different previews are loaded. This could be an img tag where the image is loaded directly or an iframe that embeds a webpage, or a recline preview. ''' context = { 'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj } try: c.resource = get_action('resource_show')(context, {'id': resource_id}) # removes the host to make it relative if config.get('ckan.upload_file_url'): url = c.resource['url'] if config.get('ckan.upload_file_url') in url: url = url.split(config.get('ckan.upload_file_url')) c.resource['url'] = url[1] c.package = get_action('package_show')(context, {'id': id}) data_dict = {'resource': c.resource, 'package': c.package} preview_plugin = datapreview.get_preview_plugin(data_dict) if preview_plugin is None: abort(409, _('No preview has been defined.')) preview_plugin.setup_template_variables(context, data_dict) c.resource_json = json.dumps(c.resource) dataset_type = c.package['type'] or 'dataset' except NotFound: abort(404, _('Resource not found')) except NotAuthorized: abort(401, _('Unauthorized to read resource %s') % id) else: return render(preview_plugin.preview_template(context, data_dict), extra_vars={'dataset_type': dataset_type})
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_datapreview(self, resource_id, id, language): ''' Embeded page for a resource data-preview. Depending on the type, different previews are loaded. This could be an img tag where the image is loaded directly or an iframe that embeds a webpage, recline or a pdf preview. ''' context = { 'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj } try: resource = toolkit.get_action('resource_show')(context,{'id': resource_id}) c.package = toolkit.get_action('package_show')(context, {'id': id}) resource.update({'package_name':c.package.get('name')}) c.resource = resource c.resource_language = language data_dict = {'resource': c.resource, 'package': c.package} preview_plugin = datapreview.get_preview_plugin(data_dict) if preview_plugin is None: abort(409, _('No preview has been defined.')) #preview_plugin.setup_template_variables(context, data_dict) c.resource_json = json.dumps(c.resource) except NotFound: abort(404, _('Resource not found')) except NotAuthorized: abort(401, _('Unauthorized to read resource %s') % id) else: #return render(preview_plugin.preview_template(context, data_dict)) return render('recline_translate_edit.html')
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))
def _resource_preview(self, data_dict): '''Deprecated in 2.3''' return bool( datapreview.get_preview_plugin(data_dict, return_first=True))