Skip to content

Commit

Permalink
Fix counts that are including private datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjones committed May 1, 2012
1 parent 8c4715c commit ea19469
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion ckan/controllers/group.py
Expand Up @@ -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}

Expand Down
3 changes: 2 additions & 1 deletion ckan/controllers/home.py
Expand Up @@ -31,7 +31,7 @@ def __before__(self, action, **env):
# TODO: send an email to the admin person (#1285)
else:
raise


def index(self):
try:
Expand All @@ -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']
Expand Down
5 changes: 3 additions & 2 deletions ckan/lib/dictization/model_dictize.py
Expand Up @@ -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:
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions ckan/logic/action/get.py
Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions ckan/model/group.py
Expand Up @@ -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
Expand Down

0 comments on commit ea19469

Please sign in to comment.