Example #1
0
def get_vars(self, id, resource_id):
    PackageController.resource_read(self, id, resource_id)

    context = {'model': model, 'session': model.Session,
               'user': c.user or c.author,
               'auth_user_obj': c.userobj,
               'for_view': True}

    dataset_type = c.pkg.type or 'dataset'

    resource_views = get_action('resource_view_list')(
        context, {'id': resource_id})
    c.resource['has_views'] = len(resource_views) > 0

    current_resource_view = None
    view_id = request.GET.get('view_id')
    if c.resource['can_be_previewed'] and not view_id:
        current_resource_view = None
    elif c.resource['has_views']:
        if view_id:
            current_resource_view = [rv for rv in resource_views
                                     if rv['id'] == view_id]
            if len(current_resource_view) == 1:
                current_resource_view = current_resource_view[0]
            else:
                abort(404, _('Resource view not found'))
        else:
            current_resource_view = resource_views[0]

    vars = {'resource_views': resource_views,
            'current_resource_view': current_resource_view,
            'dataset_type': dataset_type}

    return vars
Example #2
0
 def _setup_template_variables(self, context, data_dict, package_type=None):
     PackageController._setup_template_variables(self, context, data_dict, package_type)
     #Add the dataset type tags to the template variables.
     try:
         dataset_types = get_action('tag_list')(context,
                                                  {'vocabulary_id': EDC_DATASET_TYPE_VOCAB})
         c.dataset_types = [tag for tag in dataset_types]
     except NotFound:
         c.dataset_types = []
Example #3
0
 def __before__(self, action, **env):
     PackageController.__before__(self, action, **env)
     check1 = request.params.get("ext_field-filters")
     ps = request.params.get("ext_field-filters-select")
     check2 = request.params.get("ext_field-actions")
     ac = request.params.get("ext_field-actions-select")
     if check1:
         c.process_state = ps
     if check2:
         c.action_multi = ac
Example #4
0
 def read(self, id):
     # We do not want to perform read operation on package id "new",
     # where it results in the package not being found
     if id != "new":
         org_id = self.get_package_org_id(id)
         if org_id:
             self._post_analytics(c.user, "Organization", "View", org_id)
     # If we simply return PackageController.read() or return w/o a
     # PackageController.new() operation, a blank page or error page will appear
     else:
         return PackageController.new(self)
     return PackageController.read(self, id)
 def read(self, id):
     # We do not want to perform read operation on package id "new",
     # where it results in the package not being found
     if id!="new":
         org_id = self.get_package_org_id(id)
         if org_id:
             self._post_analytics(c.user, "Organization", "View", org_id)
     # If we simply return PackageController.read() or return w/o a
     # PackageController.new() operation, a blank page or error page will appear
     else:
         return PackageController.new(self)
     return PackageController.read(self, id)
Example #6
0
    def _setup_template_variables(self, context, data_dict, package_type=None):
        PackageController._setup_template_variables(self, context, data_dict, package_type)
        #Add the dataset type tags to the template variables.
        try:
            dataset_types = get_action('tag_list')(context,
                                                     {'vocabulary_id': EDC_DATASET_TYPE_VOCAB})
            c.dataset_types = [tag for tag in dataset_types]
#             for key, value in data_dict.iteritems() :
#                 if key == 'state' :
#                     c.old_state = data_dict['state']
        except NotFound:
            c.dataset_types = []
Example #7
0
 def _setup_template_variables(self, context, data_dict, package_type=None):
     PackageController._setup_template_variables(self, context, data_dict,
                                                 package_type)
     #Add the dataset type tags to the template variables.
     try:
         dataset_types = get_action('tag_list')(
             context, {
                 'vocabulary_id': EDC_DATASET_TYPE_VOCAB
             })
         c.dataset_types = [tag for tag in dataset_types]
     except NotFound:
         c.dataset_types = []
Example #8
0
    def read_dataset(self, _id, _format=None):

        if not _format:
            _format = check_access_header()

        if not _format:
            return PackageController().read(_id)

        _profiles = toolkit.request.params.get('profiles')
        if _profiles:
            _profiles = _profiles.split(',')

        toolkit.response.headers.update(
            {'Content-type': CONTENT_TYPES[_format]})

        try:
            result = toolkit.get_action('dcat_dataset_show')(
                {}, {
                    'id': _id,
                    'format': _format,
                    'profiles': _profiles
                })
        except toolkit.ObjectNotFound:
            toolkit.abort(404)

        return result
    def resource_download(self, id, resource_id, filename=None):
        self._post_analytics(c.user, "Resource", "Download", resource_id, id)

        if is_using_cloudstorage:
            use_controller = StorageController
            use_class = StorageController()
        else:
            use_controller = PackageController
            use_class = PackageController()

        return use_controller.resource_download(use_class, id, resource_id,
                                                filename)
Example #10
0
 def new_metadata(self):
     """
     Process a dataset metadata submission and validate it. If valid, then proceed to add the dataset metadata and if not return the new_package_metadata page to display the errors so
     the user can try to fix his submission.
     """
     data = clean_dict(unflatten(tuplize_dict(parse_params(
         request.params))))
     result = toolkit.get_action('validate_dataset_metadata')(None, data)
     vars = {"data": data}
     if result['success'] == True:
         return PackageController().new_metadata(id=data['pkg_name'])
     else:
         vars["errors"] = result["errors"]
         return render('package/new_package_metadata.html', extra_vars=vars)
Example #11
0
def resource_download(context, data):
    
    check_and_bust('package_id', data)
    check_and_bust('id', data)
    
    # changing POST request to GET request
    # needed because only GET request can return file
    plugins.toolkit.request.environ['REQUEST_METHOD'] = 'GET'
    
    package_id = data.get('package_id')
    resource_id = data.get('id')

    rsc = get_action('resource_show')(context, {'id': resource_id})
    pkg = get_action('package_show')(context, {'id': package_id})

    return PackageController().resource_download(package_id, resource_id)
Example #12
0
    def read_dataset(self, _id, _format=None):
        log.debug('Leyendo dataset')
        if not _format:
            _format = check_access_header()

        if not _format:
            return PackageController().read(_id)

        toolkit.response.headers.update(
            {'Content-type': CONTENT_TYPES[_format]})

        try:
            result = toolkit.get_action('iaest_dataset_show')({}, {
                'id': _id,
                'format': _format
            })
        except toolkit.ObjectNotFound:
            toolkit.abort(404)

        return result
Example #13
0
 def resource_download(self, id, resource_id, filename=None):
     optional = {'filename':str(filename)}
     self._post_analytics(c.user, "Resource", "Download", resource_id,
      optional)
     return PackageController.resource_download(self, id, resource_id,
                                                filename)
Example #14
0
import json

from ckan import model
from ckan.plugins import toolkit

if toolkit.check_ckan_version(min_version='2.1'):
    BaseController = toolkit.BaseController
else:
    from ckan.lib.base import BaseController

if toolkit.check_ckan_version(max_version='2.8.99'):
    from ckan.controllers.package import PackageController
    from ckan.controllers.home import HomeController
    read_endpoint = PackageController().read
    index_endpoint = HomeController().index
else:
    from ckan.views.home import index as index_endpoint
    from ckan.views.dataset import read as read_endpoint

from ckanext.dcat.utils import CONTENT_TYPES, parse_accept_header
from ckanext.dcat.processors import RDFProfileException


def _get_package_type(id):
    """
    Given the id of a package this method will return the type of the
    package, or 'dataset' if no type is currently set
    """
    pkg = model.Package.get(id)
    if pkg:
        return pkg.type or u'dataset'
Example #15
0
 def resource_read(self, id, resource_id):
     org_id = self.get_package_org_id(id)
     if org_id:
         self._post_analytics(c.user, "Organization", "View", org_id)
     return PackageController.resource_read(self, id, resource_id)
 def resource_download(self, id, resource_id, filename=None):
     self._post_analytics(c.user, "Resource", "Download", resource_id)
     return PackageController.resource_download(self, id, resource_id,
                                                filename)
Example #17
0
    def new(self, ds_id, ds_type):
        new_payload = None

        if 'save' not in request.params:
            lc = ckanapi.LocalCKAN()
            pkg = lc.action.package_show(id=ds_id)
            pkg_id = pkg[PRODUCT_ID]

            parent_schema = scheming_get_dataset_schema(pkg['type'])

            new_payload = {
                'type': ds_type,
                'top_parent_id': pkg.get('top_parent_id', pkg_id) or pkg_id
            }

            id_payload = {
                'parentProductId': pkg['product_id_new'],
                'parentProduct': pkg['product_id_new'],
                'productType': str(
                    parent_schema['dataset_type_code']
                ),
                'productTypeCode': str(
                    parent_schema['dataset_type_code']
                )
            }

            if ds_type == 'format':
                new_payload['parent_id'] = pkg_id
            elif ds_type == 'issue':
                issue_number = next_issue_number(pkg_id)
                issue_id = u'{pid}{issue_number}'.format(
                    pid=pkg_id,
                    issue_number=issue_number
                )
                new_payload['product_type_code'] = pkg.get('product_type_code')
                new_payload['issue_number'] = issue_number
                new_payload['product_id_new'] = issue_id
                new_payload['name'] = u'issue-{issue_id}'.format(
                    issue_id=issue_id
                )
                pass
            elif ds_type == 'article':
                article_id = next_article_id(
                    pkg.get('top_parent_id', pkg_id) or pkg_id,
                    pkg.get('issue_number')
                )
                new_payload['product_type_code'] = pkg.get('product_type_code')
                new_payload['issue_number'] = pkg.get('issue_number')
                new_payload['product_id_new'] = article_id
                new_payload['name'] = u'article-{article_id}'.format(
                    article_id=article_id
                )
                pass
            elif ('non_data_product' in parent_schema and
                    parent_schema['non_data_product'] == True):
                if is_legacy_product(pkg[PRODUCT_ID]):
                    new_payload[PRODUCT_ID] = lc.action.GetNextLegacyProductId(
                        **id_payload
                    )
                else:
                    id_payload['subjectCode'] = pkg['subject_codes'][0]
                    new_payload[PRODUCT_ID] = lc.action.GetNextNonDataProductId(
                        **id_payload
                    )
            else:
                new_payload[PRODUCT_ID] = lc.action.GetNextProductId(
                    **id_payload
                )

        return PackageController().new(new_payload)
 def resource_download(self, id, resource_id, filename=None):
     self._post_analytics(c.user, "Resource", "Download", resource_id)
     return PackageController.resource_download(self, id, resource_id,
                                                filename)
 def resource_read(self, id, resource_id):
     org_id = self.get_package_org_id(id)
     if org_id:
         self._post_analytics(c.user, "Organization", "View", org_id)
     return PackageController.resource_read(self, id, resource_id)