From ea19469809efa739d9c8bce21bc7dec8df4ea9ab Mon Sep 17 00:00:00 2001 From: Ross Jones Date: Tue, 1 May 2012 14:25:24 +0100 Subject: [PATCH] Fix counts that are including private datasets --- ckan/controllers/group.py | 3 ++- ckan/controllers/home.py | 3 ++- ckan/lib/dictization/model_dictize.py | 5 +++-- ckan/logic/action/get.py | 6 +++--- ckan/model/group.py | 11 ++++++++--- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/ckan/controllers/group.py b/ckan/controllers/group.py index 95a4597ad70..30e48253a1f 100644 --- a/ckan/controllers/group.py +++ b/ckan/controllers/group.py @@ -72,7 +72,8 @@ def index(self): group_type = self._guess_group_type() context = {'model': model, 'session': model.Session, - 'user': c.user or c.author, 'for_view': True} + 'user': c.user or c.author, 'for_view': True, + 'with_private': False} data_dict = {'all_fields': True} diff --git a/ckan/controllers/home.py b/ckan/controllers/home.py index a675826af44..cfa139c9829 100644 --- a/ckan/controllers/home.py +++ b/ckan/controllers/home.py @@ -31,7 +31,7 @@ def __before__(self, action, **env): # TODO: send an email to the admin person (#1285) else: raise - + def index(self): try: @@ -43,6 +43,7 @@ def index(self): 'facet.field':g.facets, 'rows':0, 'start':0, + 'fq': 'capacity:"public"' } query = ckan.logic.get_action('package_search')(context,data_dict) c.package_count = query['count'] diff --git a/ckan/lib/dictization/model_dictize.py b/ckan/lib/dictization/model_dictize.py index 75fe85ec14d..74aa8b78877 100644 --- a/ckan/lib/dictization/model_dictize.py +++ b/ckan/lib/dictization/model_dictize.py @@ -15,7 +15,7 @@ def group_list_dictize(obj_list, context, sort_key=lambda x:x['display_name'], reverse=False): active = context.get('active', True) - + with_private = context.get('include_private_packages', False) result_list = [] for obj in obj_list: @@ -30,7 +30,8 @@ def group_list_dictize(obj_list, context, group_dict['display_name'] = obj.display_name - group_dict['packages'] = len(obj.active_packages().all()) + group_dict['packages'] = \ + len(obj.active_packages(with_private=with_private).all()) if context.get('for_view'): for item in plugins.PluginImplementations( diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py index fd0ce25ad57..b2afe947171 100644 --- a/ckan/logic/action/get.py +++ b/ckan/logic/action/get.py @@ -491,9 +491,9 @@ def resource_status_show(context, data_dict): check_access('resource_status_show', context, data_dict) # needs to be text query as celery tables are not in our model - q = text("""select status, date_done, traceback, task_status.* - from task_status left join celery_taskmeta - on task_status.value = celery_taskmeta.task_id and key = 'celery_task_id' + q = text("""select status, date_done, traceback, task_status.* + from task_status left join celery_taskmeta + on task_status.value = celery_taskmeta.task_id and key = 'celery_task_id' where entity_id = :entity_id """) result = model.Session.connection().execute(q, entity_id=id) diff --git a/ckan/model/group.py b/ckan/model/group.py index f622a7aa63e..de2e4cd1a53 100644 --- a/ckan/model/group.py +++ b/ckan/model/group.py @@ -166,13 +166,18 @@ def get_children_groups(self, type='group'): from_statement(HIERARCHY_CTE).params(id=self.id, type=type).all() return [ { "id":idf, "name": name, "title": title } for idf,name,title in results ] - def active_packages(self, load_eager=True): + def active_packages(self, load_eager=True, with_private=False): query = Session.query(Package).\ filter_by(state=vdm.sqlalchemy.State.ACTIVE).\ filter(group_table.c.id == self.id).\ - filter(member_table.c.state == 'active').\ - join(member_table, member_table.c.table_id == Package.id).\ + filter(member_table.c.state == 'active') + + if not with_private: + query = query.filter(member_table.c.capacity == 'public') + + query = query.join(member_table, member_table.c.table_id == Package.id).\ join(group_table, group_table.c.id == member_table.c.group_id) + return query @classmethod