def dataset_export_dcat(context, data_dict): '''Export a dataset to RDF XML using GeoDCAT XSLT. :param id: the name or id of the dataset to be exported. :type id: string rtype: dict ''' pkg = _get_action('package_show')(context, data_dict) dtype = pkg.get('dataset_type') obj = pkg.get(dtype) if dtype else None cached_metadata = get_cache('metadata') result = None if obj: # Get a proper serializer xser = xml_serializer_for(obj) xser.target_namespace = pylons.config.get('ckan.site_url') name = '%(name)s@%(revision_id)s.dcat' % (pkg) cached = cached_metadata.get( name, createfunc=lambda: _transform_dcat(xser.to_xml())) link = toolkit.url_for( controller='ckanext.publicamundi.controllers.files:Controller', action='download_file', object_type='metadata', name_or_id=name, filename=('%(name)s.xml' % (pkg))) result = dict(url=link) return result
def dataset_export_dcat(context, data_dict): '''Export a dataset to RDF XML using GeoDCAT XSLT. :param id: the name or id of the dataset to be exported. :type id: string rtype: dict ''' pkg = _get_action('package_show')(context, data_dict) dtype = pkg.get('dataset_type') obj = pkg.get(dtype) if dtype else None cached_metadata = get_cache('metadata') result = None if obj: # Get a proper serializer xser = xml_serializer_for(obj) xser.target_namespace = pylons.config.get('ckan.site_url') name = '%(name)s@%(revision_id)s.dcat' % (pkg) cached = cached_metadata.get(name, createfunc=lambda: _transform_dcat(xser.to_xml())) link = toolkit.url_for( controller='ckanext.publicamundi.controllers.files:Controller', action='download_file', object_type='metadata', name_or_id=name, filename=('%(name)s.xml' % (pkg))) result = dict(url=link) return result
def dataset_export(context, data_dict): '''Export a dataset to XML. :param id: the name or id of the dataset to be exported. :type id: string rtype: string ''' _check_access('package_show', context, data_dict) pkg = _get_action('package_show')(context, data_dict) dtype = pkg.get('dataset_type') obj = pkg.get(dtype) if dtype else None cached_metadata = get_cache('metadata') result = None if obj: # Get a proper serializer xser = xml_serializer_for(obj) xser.target_namespace = config.get('ckan.site_url') # Persist exported XML data and wrap into a URL name = '%(name)s@%(revision_id)s' % (pkg) cached = cached_metadata.get(name, createfunc=xser.dumps) link = toolkit.url_for( controller='ckanext.publicamundi.controllers.files:Controller', action='download_file', object_type='metadata', name_or_id=name, filename=('%(name)s.xml' % (pkg))) result = dict(url=link) return result
def download_file(self, object_type, name_or_id, filename=None): '''Download file from CKAN's filestore, grouped under `object_type` and identified by `name_or_id` inside this group. ''' filepath = None if object_type == 'resources': up = uploader.ResourceUpload(resource={}) filepath = up.get_path(name_or_id) app = fileapp.FileApp(filepath) elif object_type == 'source-metadata': up = uploader.MetadataUpload() filepath = up.get_path(name_or_id) app = fileapp.FileApp(filepath) elif object_type == 'metadata': val = get_cache('metadata').get(name_or_id) app = fileapp.DataApp(val, content_type='application/xml; charset=utf-8') else: abort(404, 'Unknown object-type') # Retreive file try: status, headers, app_it = request.call_application(app) except: abort(404, 'Not Found') response.headers.update(dict(headers)) response.status = status # Dump return app_it
def download_file(self, object_type, name_or_id, filename=None): '''Download file from CKAN's filestore, grouped under `object_type` and identified by `name_or_id` inside this group. ''' filepath = None if object_type == 'resources': up = uploader.ResourceUpload(resource={}) filepath = up.get_path(name_or_id) app = fileapp.FileApp(filepath) elif object_type == 'source-metadata': up = uploader.MetadataUpload() filepath = up.get_path(name_or_id) app = fileapp.FileApp(filepath) elif object_type == 'metadata': val = get_cache('metadata').get(name_or_id) app = fileapp.DataApp(val, content_type='application/xml; charset=utf-8') else: abort(404, 'Unknown object-type') # Retreive file try: status, headers, app_it = request.call_application(app) except: abort(404, 'Not Found') response.headers.update(dict(headers)) response.status = status # Dump return app_it
def test_cache(self): from ckanext.publicamundi.cache_manager import get_cache cache1 = get_cache('test') def compute(): log1.info(' ** i compute something **') return 42 val = cache1.get('foo', createfunc=compute) assert False
def test_cache(self): from ckanext.publicamundi.cache_manager import get_cache cache1 = get_cache('test') def compute(): log1.info(' ** i compute something **') return 42 val = cache1.get('foo', createfunc=compute) assert False