Skip to content

Commit

Permalink
[#1102] make package_dictize go through group_list_dictize, except ig…
Browse files Browse the repository at this point in the history
…nore package counts
  • Loading branch information
kindly committed Nov 28, 2013
1 parent b3e52b7 commit f075c67
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
5 changes: 1 addition & 4 deletions ckan/controllers/package.py
Expand Up @@ -1286,7 +1286,7 @@ def followers(self, id=None):
def groups(self, id):
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'for_view': True,
'auth_user_obj': c.userobj}
'auth_user_obj': c.userobj, 'use_cache': False}
data_dict = {'id': id}
try:
c.pkg_dict = get_action('package_show')(context, data_dict)
Expand Down Expand Up @@ -1335,11 +1335,8 @@ def groups(self, id):
group['id'] not in pkg_group_ids]

for group in c.pkg_dict.get('groups', []):
## this could be pushed back to package dictize
group['display_name'] = group.get('titile') or group.get('name')
group['user_member'] = (group['id'] in user_group_ids)


return render('package/group_list.html')

def activity(self, id):
Expand Down
38 changes: 23 additions & 15 deletions ckan/lib/dictization/model_dictize.py
Expand Up @@ -15,18 +15,18 @@
## package save

def group_list_dictize(obj_list, context,
sort_key=lambda x:x['display_name'], reverse=False):
sort_key=lambda x:x['display_name'], reverse=False,
with_package_counts=True):

active = context.get('active', True)
with_private = context.get('include_private_packages', False)

query = search.PackageSearchQuery()

q = {'q': '+capacity:public' if not with_private else '*:*',
'fl': 'groups', 'facet.field': ['groups', 'owner_org'],
'facet.limit': -1, 'rows': 1}

query.run(q)
if with_package_counts:
query = search.PackageSearchQuery()
q = {'q': '+capacity:public' if not with_private else '*:*',
'fl': 'groups', 'facet.field': ['groups', 'owner_org'],
'facet.limit': -1, 'rows': 1}
query.run(q)

result_list = []

Expand All @@ -40,7 +40,8 @@ def group_list_dictize(obj_list, context,
if active and obj.state not in ('active', 'pending'):
continue

group_dict['display_name'] = obj.display_name
group_dict['display_name'] = (group_dict.get('title') or
group_dict.get('name'))

image_url = group_dict.get('image_url')
group_dict['image_display_url'] = image_url
Expand All @@ -49,13 +50,16 @@ def group_list_dictize(obj_list, context,
#of potential vulnerability of dodgy api input
image_url = munge.munge_filename(image_url)
group_dict['image_display_url'] = h.url_for_static(
'uploads/group/%s' % group_dict.get('image_url')
'uploads/group/%s' % group_dict.get('image_url'),
qualified=True
)

if obj.is_organization:
group_dict['packages'] = query.facets['owner_org'].get(obj.id, 0)
else:
group_dict['packages'] = query.facets['groups'].get(obj.name, 0)
if with_package_counts:
facets = query.facets
if obj.is_organization:
group_dict['packages'] = facets['owner_org'].get(obj.id, 0)
else:
group_dict['packages'] = facets['groups'].get(obj.name, 0)

if context.get('for_view'):
if group_dict['is_organization']:
Expand Down Expand Up @@ -259,7 +263,11 @@ def package_dictize(pkg, context):
.where(member_rev.c.state == 'active') \
.where(group.c.is_organization == False)
result = _execute_with_revision(q, member_rev, context)
result_dict["groups"] = d.obj_list_dictize(result, context)
context['with_capacity'] = False
## no package counts as cannot fetch from search index at the same
## time as indexing to it.
result_dict["groups"] = group_list_dictize(result, context,
with_package_counts=False)
#owning organization
group_rev = model.group_revision_table
q = select([group_rev]
Expand Down
1 change: 1 addition & 0 deletions ckan/logic/schema.py
Expand Up @@ -223,6 +223,7 @@ def default_show_package_schema():

schema['groups'].update({
'description': [ignore_missing],
'image_display_url': [ignore_missing],
})

# Remove validators for several keys from the schema so validation doesn't
Expand Down
4 changes: 4 additions & 0 deletions ckan/tests/lib/test_dictization.py
Expand Up @@ -48,6 +48,8 @@ def setup_class(cls):
'name': u'david',
'capacity': 'public',
'image_url': u'',
'image_display_url': u'',
'display_name': u"Dave's books",
'type': u'group',
'state': u'active',
'is_organization': False,
Expand All @@ -57,6 +59,8 @@ def setup_class(cls):
'name': u'roger',
'capacity': 'public',
'image_url': u'',
'image_display_url': u'',
'display_name': u"Roger's books",
'type': u'group',
'state': u'active',
'is_organization': False,
Expand Down

0 comments on commit f075c67

Please sign in to comment.