From 22692ed4065a12a1f43c4a11a379680e436b0f28 Mon Sep 17 00:00:00 2001 From: William Dutton Date: Wed, 11 Dec 2024 13:31:05 +1000 Subject: [PATCH] chore: controller uses common function --- ckanext/validation/cli.py | 7 ++++--- ckanext/validation/controller.py | 36 ++++---------------------------- 2 files changed, 8 insertions(+), 35 deletions(-) diff --git a/ckanext/validation/cli.py b/ckanext/validation/cli.py index 5a68627d..290dcbf9 100644 --- a/ckanext/validation/cli.py +++ b/ckanext/validation/cli.py @@ -1,4 +1,4 @@ -import sys +# encoding: utf-8 import click @@ -11,11 +11,12 @@ def get_commands(): @click.group() def validation(): - """Harvests remotely mastered metadata.""" + """Validation management commands. + """ pass -@validation.command() +@validation.command(name='init-db') def init_db(): """ Initialize database tables. """ diff --git a/ckanext/validation/controller.py b/ckanext/validation/controller.py index 91224649..b4396a21 100644 --- a/ckanext/validation/controller.py +++ b/ckanext/validation/controller.py @@ -1,39 +1,11 @@ # encoding: utf-8 -from ckantoolkit import ( - BaseController, c, NotAuthorized, ObjectNotFound, - abort, _, render, get_action) +from ckantoolkit import BaseController + +from ckanext.validation import common class ValidationController(BaseController): def validation(self, resource_id): - - try: - validation = get_action(u'resource_validation_show')( - {u'user': c.user}, - {u'resource_id': resource_id}) - - resource = get_action(u'resource_show')( - {u'user': c.user}, - {u'id': resource_id}) - - dataset = get_action(u'package_show')( - {u'user': c.user}, - {u'id': resource[u'package_id']}) - - # Needed for core resource templates - c.package = c.pkg_dict = dataset - c.resource = resource - - return render(u'validation/validation_read.html', extra_vars={ - u'validation': validation, - u'resource': resource, - u'dataset': dataset, - }) - - except NotAuthorized: - abort(403, _(u'Unauthorized to read this validation report')) - except ObjectNotFound: - - abort(404, _(u'No validation report exists for this resource')) + return common.validation(resource_id)