Skip to content

Commit

Permalink
Merge branch 'master' into 2733-feature-datastore
Browse files Browse the repository at this point in the history
  • Loading branch information
kindly committed Aug 7, 2012
2 parents 2fc489d + 36e30ad commit b609677
Show file tree
Hide file tree
Showing 15 changed files with 367 additions and 972 deletions.
6 changes: 3 additions & 3 deletions LICENSE.txt
Expand Up @@ -22,9 +22,9 @@ Note
====

CKAN is sometimes packaged directly with other software (listed in
requires/lucid_conflict.txt). In these cases, we are required to list the
licenses of the packaged softare too. They are all AGPL compatible and read as
follows in the next sections.
pip-requirements.txt, pip-requirements-test.txt and pip-requirements-docs.txt).
In these cases, we are required to list the licenses of the packaged softare
too. They are all AGPL compatible and read as follows in the next sections.

WebHelpers
----------
Expand Down
6 changes: 3 additions & 3 deletions ckan/lib/cli.py
Expand Up @@ -977,13 +977,13 @@ def update_tracking(self, engine, summary_date):
FROM tracking_summary t2
WHERE t1.url = t2.url
AND t2.tracking_date <= t1.tracking_date
) + t1.count
)
,recent_views = (
SELECT sum(count)
FROM tracking_summary t2
WHERE t1.url = t2.url
AND t2.tracking_date <= t1.tracking_date AND t2.tracking_date >= t1.tracking_date - 14
) + t1.count
)
WHERE t1.running_total = 0 AND tracking_type = 'resource';'''
engine.execute(sql)

Expand All @@ -1000,7 +1000,7 @@ def update_tracking(self, engine, summary_date):
FROM tracking_summary t2
WHERE t1.package_id = t2.package_id
AND t2.tracking_date <= t1.tracking_date AND t2.tracking_date >= t1.tracking_date - 14
) + t1.count
)
WHERE t1.running_total = 0 AND tracking_type = 'page'
AND t1.package_id IS NOT NULL
AND t1.package_id != '~~not~found~~';'''
Expand Down
4 changes: 2 additions & 2 deletions ckan/lib/create_test_data.py
Expand Up @@ -397,8 +397,8 @@ def create(cls, auth_profile="", package_type=None):
)
model.Session.add(pr1)
model.Session.add(pr2)
pkg1.resources.append(pr1)
pkg1.resources.append(pr2)
pkg1.resource_groups_all[0].resources_all.append(pr1)
pkg1.resource_groups_all[0].resources_all.append(pr2)
pkg1.notes = u'''Some test notes
### A 3rd level heading
Expand Down
1 change: 1 addition & 0 deletions ckan/lib/helpers.py
Expand Up @@ -928,6 +928,7 @@ def render_markdown(data):
'dashboard_activity_stream',
'get_request_param',
'render_markdown',
# imported into ckan.lib.helpers
'literal',
'link_to',
'get_available_locales',
Expand Down
69 changes: 55 additions & 14 deletions ckan/logic/action/get.py
Expand Up @@ -266,8 +266,12 @@ def group_list(context, data_dict):
'''Return a list of the names of the site's groups.
:param order_by: the field to sort the list by, must be ``'name'`` or
``'packages'`` (optional, default: ``'name'``)
``'packages'`` (optional, default: ``'name'``) Deprecated use sort.
:type order_by: string
:param sort: sorting of the search results. Optional. Default:
"name asc" string of field name and sort-order. The allowed fields are
'name' and 'packages'
:type sort: string
:param groups: a list of names of the groups to return, if given only
groups whose names are in this list will be returned (optional)
:type groups: list of strings
Expand All @@ -278,14 +282,30 @@ def group_list(context, data_dict):
:rtype: list of strings
'''

model = context['model']
api = context.get('api_version')
groups = data_dict.get('groups')
ref_group_by = 'id' if api == 2 else 'name';
order_by = data_dict.get('order_by', 'name')
if order_by not in set(('name', 'packages')):
raise logic.ParameterError('"order_by" value %r not implemented.' % order_by)
all_fields = data_dict.get('all_fields',None)

sort = data_dict.get('sort', 'name')
# order_by deprecated in ckan 1.8
# if it is supplied and sort isn't use order_by and raise a warning
order_by = data_dict.get('order_by')
if order_by:
log.warn('`order_by` deprecated please use `sort`')
if not data_dict.get('sort'):
sort = order_by
# if the sort is packages and no sort direction is supplied we want to do a
# reverse sort to maintain compatibility.
if sort.strip() == 'packages':
sort = 'packages desc'

sort_info = _unpick_search(sort,
allowed_fields=['name', 'packages'],
total=1)

all_fields = data_dict.get('all_fields', None)

_check_access('group_list', context, data_dict)

Expand All @@ -295,16 +315,10 @@ def group_list(context, data_dict):
if groups:
query = query.filter(model.GroupRevision.name.in_(groups))

if order_by == 'name':
sort_by, reverse = 'name', False

groups = query.all()

if order_by == 'packages':
sort_by, reverse = 'packages', True

group_list = model_dictize.group_list_dictize(groups, context,
lambda x:x[sort_by], reverse)
lambda x:x[sort_info[0][0]],
sort_info[0][1] == 'desc')

if not all_fields:
group_list = [group[ref_group_by] for group in group_list]
Expand Down Expand Up @@ -1009,7 +1023,7 @@ def package_search(context, data_dict):
returned datasets should begin.
:type start: int
:param qf: the dismax query fields to search within, including boosts. See
the `Solr Dismax Documentation
the `Solr Dismax Documentation
<http://wiki.apache.org/solr/DisMaxQParserPlugin#qf_.28Query_Fields.29>`_
for further details.
:type qf: string
Expand Down Expand Up @@ -2219,3 +2233,30 @@ def dashboard_activity_list_html(context, data_dict):
'''
activity_stream = dashboard_activity_list(context, data_dict)
return _activity_list_to_html(context, activity_stream)


def _unpick_search(sort, allowed_fields=None, total=None):
''' This is a helper function that takes a sort string
eg 'name asc, last_modified desc' and returns a list of
split field order eg [('name', 'asc'), ('last_modified', 'desc')]
allowed_fields can limit which field names are ok.
total controls how many sorts can be specifed '''
sorts = []
split_sort = sort.split(',')
for part in split_sort:
split_part = part.strip().split()
field = split_part[0]
if len(split_part) > 1:
order = split_part[1].lower()
else:
order = 'asc'
if allowed_fields:
if field not in allowed_fields:
raise logic.ParameterError('Cannot sort by field `%s`' % field)
if order not in ['asc', 'desc']:
raise logic.ParameterError('Invalid sort direction `%s`' % order)
sorts.append((field, order))
if total and len(sorts) > total:
raise logic.ParameterError(
'Too many sort criteria provided only %s allowed' % total)
return sorts
3 changes: 2 additions & 1 deletion ckan/model/authz.py
Expand Up @@ -3,6 +3,7 @@
'''
import simplejson as json
import weakref

from sqlalchemy import orm, types, Column, Table, ForeignKey
from pylons import config
Expand Down Expand Up @@ -413,7 +414,7 @@ def give_all_packages_default_user_roles():
}

global _default_user_roles_cache
_default_user_roles_cache = {}
_default_user_roles_cache = weakref.WeakKeyDictionary()

def get_default_user_roles(_domain_object):
# TODO: Should this func go in lib rather than model now?
Expand Down

0 comments on commit b609677

Please sign in to comment.