Skip to content

Commit

Permalink
chore: controller uses common function
Browse files Browse the repository at this point in the history
  • Loading branch information
duttonw committed Dec 11, 2024
1 parent 8755a78 commit 22692ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 35 deletions.
7 changes: 4 additions & 3 deletions ckanext/validation/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sys
# encoding: utf-8

import click

Expand All @@ -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.
"""
Expand Down
36 changes: 4 additions & 32 deletions ckanext/validation/controller.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 22692ed

Please sign in to comment.