def delete(self, id):
        """Provide a delete ('withdraw') action, but only for UKLP datasets"""
        from ckan.lib.search import SearchIndexError
        context = {
            'model': model,
            'session': model.Session,
            'user': c.user,
        }

        try:
            pkg_dict = get_action('package_show')(context, {
                'id': id
            })  # has side-effect of populating context.get('package')
        except NotAuthorized:
            abort(401, 'Not authorized to delete package')
        except ObjectNotFound:
            abort(404, 'Dataset not found')

        if request.params:  # POST
            if 'cancel' in request.params:
                h.redirect_to(controller='package', action='read', id=id)
            elif 'delete' in request.params:
                try:
                    package_name = pkg_dict['name']
                    get_action('package_delete')(context, {'id': id})
                    is_uklp = get_from_flat_dict(pkg_dict['extras'],
                                                 'UKLP') == 'True'
                    if is_uklp:
                        action = 'withdrawn'
                        resource_type = get_from_flat_dict(
                            pkg_dict['extras'], 'resource-type') + ' record'
                    else:
                        action = 'deleted'
                        resource_type = 'dataset'
                    h.flash_success('Successfully %s %s.' \
                                    % (action, resource_type))
                    self._form_save_redirect(package_name, 'edit')
                except NotAuthorized:
                    abort(401, _('Unauthorized to delete package %s') % id)
                except ObjectNotFound, e:
                    abort(404, _('Package not found'))
                except DataError:
                    abort(400, _(u'Integrity Error'))
                except SearchIndexError, e:
                    abort(500,
                          _(u'Unable to update search index.') + repr(e.args))
Exemple #2
0
    def delete(self, id):
        """Provide a delete ('withdraw') action, but only for UKLP datasets"""
        from ckan.lib.search import SearchIndexError
        context = {
            'model': model,
            'session': model.Session,
            'user': c.user,
        }

        try:
            pkg_dict = get_action('package_show')(context, {'id':id}) # has side-effect of populating context.get('package')
        except NotAuthorized:
            abort(401, 'Not authorized to delete package')
        except ObjectNotFound:
            abort(404, 'Dataset not found')

        if request.params: # POST
            if 'cancel' in request.params:
                h.redirect_to(controller='package', action='read', id=id)
            elif 'delete' in request.params:
                try:
                    package_name = pkg_dict['name']
                    get_action('package_delete')(context, {'id':id})
                    is_uklp = get_from_flat_dict(pkg_dict['extras'], 'UKLP') == 'True'
                    if is_uklp:
                        action = 'withdrawn'
                        resource_type = get_from_flat_dict(pkg_dict['extras'], 'resource-type') + ' record'
                    else:
                        action = 'deleted'
                        resource_type = 'dataset'
                    h.flash_success('Successfully %s %s.' \
                                    % (action, resource_type))
                    self._form_save_redirect(package_name, 'edit')
                except NotAuthorized:
                    abort(401, _('Unauthorized to delete package %s') % id)
                except ObjectNotFound, e:
                    abort(404, _('Package not found'))
                except DataError:
                    abort(400, _(u'Integrity Error'))
                except SearchIndexError, e:
                    abort(500, _(u'Unable to update search index.') + repr(e.args))
Exemple #3
0
    def delete(self, id):
        """Provide a delete ('withdraw') action, but only for UKLP datasets"""
        from ckan.lib.search import SearchIndexError

        context = {"model": model, "session": model.Session, "user": c.user}

        try:
            pkg_dict = get_action("package_show")(
                context, {"id": id}
            )  # has side-effect of populating context.get('package')
        except NotAuthorized:
            abort(401, "Not authorized to delete package")

        if request.params:  # POST
            if "cancel" in request.params:
                h.redirect_to(controller="package", action="read", id=id)
            elif "delete" in request.params:
                try:
                    package_name = pkg_dict["name"]
                    get_action("package_delete")(context, {"id": id})
                    is_uklp = get_from_flat_dict(pkg_dict["extras"], "UKLP") == "True"
                    if is_uklp:
                        action = "withdrawn"
                        resource_type = get_from_flat_dict(pkg_dict["extras"], "resource-type") + " record"
                    else:
                        action = "deleted"
                        resource_type = "dataset"
                    h.flash_success("Successfully %s %s." % (action, resource_type))
                    self._form_save_redirect(package_name, "edit")
                except NotAuthorized:
                    abort(401, _("Unauthorized to delete package %s") % id)
                except ObjectNotFound, e:
                    abort(404, _("Package not found"))
                except DataError:
                    abort(400, _(u"Integrity Error"))
                except SearchIndexError, e:
                    abort(500, _(u"Unable to update search index.") + repr(e.args))