From 9e790c0c032a8928f7fea528df7395b9438dbc44 Mon Sep 17 00:00:00 2001 From: tobes Date: Wed, 20 Feb 2013 16:52:16 +0000 Subject: [PATCH] Various cleanups --- ckanext/qa/plugin.py | 43 +++++-------------------------------------- ckanext/qa/reports.py | 7 ++++--- 2 files changed, 9 insertions(+), 41 deletions(-) diff --git a/ckanext/qa/plugin.py b/ckanext/qa/plugin.py index cd52b72c..0507f5ef 100644 --- a/ckanext/qa/plugin.py +++ b/ckanext/qa/plugin.py @@ -1,25 +1,21 @@ import json import datetime -from genshi.input import HTML -from genshi.filters import Transformer -from pylons import request, tmpl_context as c +import html +import reports + import ckan.lib.dictization.model_dictize as model_dictize import ckan.model as model import ckan.plugins as p -import ckan.lib.helpers as h import ckan.lib.celery_app as celery_app -from ckan.model.types import make_uuid -import html -import reports resource_dictize = model_dictize.resource_dictize send_task = celery_app.celery.send_task class QAPlugin(p.SingletonPlugin): + p.implements(p.IConfigurer, inherit=True) p.implements(p.IConfigurable) - p.implements(p.IGenshiStreamFilter) p.implements(p.IRoutes, inherit=True) p.implements(p.IDomainObjectModification, inherit=True) p.implements(p.IResourceUrlChange) @@ -128,7 +124,7 @@ def _create_task(self, resource): data = json.dumps(resource_dict) - task_id = make_uuid() + task_id = model.types.make_uuid() task_status = { 'entity_id': resource.id, 'entity_type': u'resource', @@ -146,35 +142,6 @@ def _create_task(self, resource): p.toolkit.get_action('task_status_update')(task_context, task_status) send_task('qa.update', args=[context, data], task_id=task_id) - def filter(self, stream): - routes = request.environ.get('pylons.routes_dict') - - site_url = h.url('/', locale='default') - stream = stream | Transformer('head').append( - HTML(html.HEAD_CODE % site_url) - ) - - if (routes.get('controller') == 'package' and - routes.get('action') == 'resource_read'): - - star_html = self.get_star_html(c.resource.get('id')) - if star_html: - stream = stream | Transformer('body//div[@class="quick-info"]//dl')\ - .append(HTML(html.DL_HTML % star_html)) - - if (routes.get('controller') == 'package' and - routes.get('action') == 'read' and - c.pkg.id): - - for resource in c.pkg_dict.get('resources', []): - resource_id = resource.get('id') - star_html = self.get_star_html(resource_id) - if star_html: - stream = stream | Transformer('body//div[@id="%s"]//p[@class="extra-links"]' % resource_id)\ - .append(HTML(star_html)) - - return stream - @classmethod def get_star_html(cls, resource_id): report = reports.resource_five_stars(resource_id) diff --git a/ckanext/qa/reports.py b/ckanext/qa/reports.py index 6e26f196..60203e2e 100644 --- a/ckanext/qa/reports.py +++ b/ckanext/qa/reports.py @@ -22,12 +22,13 @@ def five_stars(id=None): # take the maximum openness score among dataset resources to be the # overall dataset openness core query = model.Session.query(model.Package.name, model.Package.title, - func.max(model.TaskStatus.value).label('value'))\ + model.Resource.id, + model.TaskStatus.value.label('value'))\ .join(model.ResourceGroup, model.Package.id == model.ResourceGroup.package_id)\ .join(model.Resource)\ .join(model.TaskStatus, model.TaskStatus.entity_id == model.Resource.id)\ .filter(model.TaskStatus.key==u'openness_score')\ - .group_by(model.Package.name, model.Package.title)\ + .group_by(model.Package.name, model.Package.title, model.Resource.id, model.TaskStatus.value)\ .distinct() if id: @@ -37,7 +38,7 @@ def five_stars(id=None): for row in query: results.append({ 'name': row.name, - 'title': row.title, + 'title': row.title + u' ' + row.id, 'openness_score': row.value })