Skip to content

Commit

Permalink
Merge branch 'master' into related-list-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nigel Babu committed Jan 10, 2014
2 parents 49de093 + 4bddcd8 commit 1b572e8
Show file tree
Hide file tree
Showing 35 changed files with 496 additions and 290 deletions.
2 changes: 1 addition & 1 deletion ckan/lib/cli.py
Expand Up @@ -697,7 +697,7 @@ class UserCmd(CkanCommand):
'''
summary = __doc__.split('\n')[0]
usage = __doc__
max_args = 4
max_args = None
min_args = 0

def command(self):
Expand Down
5 changes: 3 additions & 2 deletions ckan/lib/dictization/model_dictize.py
Expand Up @@ -90,8 +90,9 @@ def related_list_dictize(related_list, context):
for res in related_list:
related_dict = related_dictize(res, context)
result_list.append(related_dict)

return result_list
if context.get('sorted'):
return result_list
return sorted(result_list, key=lambda x: x["created"], reverse=True)


def extras_dict_dictize(extras_dict, context):
Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/helpers.py
Expand Up @@ -1713,7 +1713,7 @@ def get_group(id):

try:
out = logic.get_action(get_action)(context, data_dict)
except logic.ObjectNotFound:
except logic.NotFound:
return None
return out

Expand Down
53 changes: 31 additions & 22 deletions ckan/logic/action/create.py
Expand Up @@ -45,7 +45,8 @@ def package_create(context, data_dict):
for the new dataset, you must also be authorized to edit these groups.
Plugins may change the parameters of this function depending on the value
of the ``type`` parameter, see the ``IDatasetForm`` plugin interface.
of the ``type`` parameter, see the
:py:class:`~ckan.plugins.interfaces.IDatasetForm` plugin interface.
:param name: the name of the new dataset, must be between 2 and 100
characters long and contain only lowercase alphanumeric characters,
Expand All @@ -63,8 +64,9 @@ def package_create(context, data_dict):
:param maintainer_email: the email address of the dataset's maintainer
(optional)
:type maintainer_email: string
:param license_id: the id of the dataset's license, see ``license_list()``
for available values (optional)
:param license_id: the id of the dataset's license, see
:py:func:`~ckan.logic.action.get.license_list` for available values
(optional)
:type license_id: license id string
:param notes: a description of the dataset (optional)
:type notes: string
Expand All @@ -78,41 +80,45 @@ def package_create(context, data_dict):
authorized to change the state of the dataset (optional, default:
``'active'``)
:type state: string
:param type: the type of the dataset (optional), ``IDatasetForm`` plugins
:param type: the type of the dataset (optional),
:py:class:`~ckan.plugins.interfaces.IDatasetForm` plugins
associate themselves with different dataset types and provide custom
dataset handling behaviour for these types
:type type: string
:param resources: the dataset's resources, see ``resource_create()``
for the format of resource dictionaries (optional)
:param resources: the dataset's resources, see
:py:func:`resource_create` for the format of resource dictionaries
(optional)
:type resources: list of resource dictionaries
:param tags: the dataset's tags, see ``tag_create()`` for the format
:param tags: the dataset's tags, see :py:func:`tag_create` for the format
of tag dictionaries (optional)
:type tags: list of tag dictionaries
:param extras: the dataset's extras (optional), extras are arbitrary
(key: value) metadata items that can be added to datasets, each extra
dictionary should have keys ``'key'`` (a string), ``'value'`` (a
string)
:type extras: list of dataset extra dictionaries
:param relationships_as_object: see ``package_relationship_create()`` for
the format of relationship dictionaries (optional)
:param relationships_as_object: see :py:func:`package_relationship_create`
for the format of relationship dictionaries (optional)
:type relationships_as_object: list of relationship dictionaries
:param relationships_as_subject: see ``package_relationship_create()`` for
the format of relationship dictionaries (optional)
:param relationships_as_subject: see :py:func:`package_relationship_create`
for the format of relationship dictionaries (optional)
:type relationships_as_subject: list of relationship dictionaries
:param groups: the groups to which the dataset belongs (optional), each
group dictionary should have one or more of the following keys which
identify an existing group:
``'id'`` (the id of the group, string), ``'name'`` (the name of the
group, string), ``'title'`` (the title of the group, string), to see
which groups exist call ``group_list()``
which groups exist call :py:func:`~ckan.logic.action.get.group_list`
:type groups: list of dictionaries
:param owner_org: the id of the dataset's owning organization, see
``organization_list()`` or ``organization_list_for_user`` for
:py:func:`~ckan.logic.action.get.organization_list` or
:py:func:`~ckan.logic.action.get.organization_list_for_user` for
available values (optional)
:type owner_org: string
:returns: the newly created dataset (unless 'return_id_only' is set to True
in the context, in which case just the dataset id will be returned)
:returns: the newly created dataset (unless ``'return_id_only'`` is set to
``True`` in the context, in which case just the dataset id will
be returned)
:rtype: dictionary
'''
Expand Down Expand Up @@ -608,7 +614,8 @@ def group_create(context, data_dict):
You must be authorized to create groups.
Plugins may change the parameters of this function depending on the value
of the ``type`` parameter, see the ``IGroupForm`` plugin interface.
of the ``type`` parameter, see the
:py:class:`~ckan.plugins.interfaces.IGroupForm` plugin interface.
:param name: the name of the group, a string between 2 and 100 characters
long, containing only lowercase alphanumeric characters, ``-`` and
Expand All @@ -623,7 +630,8 @@ def group_create(context, data_dict):
:param image_url: the URL to an image to be displayed on the group's page
(optional)
:type image_url: string
:param type: the type of the group (optional), ``IGroupForm`` plugins
:param type: the type of the group (optional),
:py:class:`~ckan.plugins.interfaces.IGroupForm` plugins
associate themselves with different group types and provide custom
group handling behaviour for these types
Cannot be 'organization'
Expand Down Expand Up @@ -674,7 +682,8 @@ def organization_create(context, data_dict):
You must be authorized to create organizations.
Plugins may change the parameters of this function depending on the value
of the ``type`` parameter, see the ``IGroupForm`` plugin interface.
of the ``type`` parameter, see the
:py:class:`~ckan.plugins.interfaces.IGroupForm` plugin interface.
:param name: the name of the organization, a string between 2 and 100 characters
long, containing only lowercase alphanumeric characters, ``-`` and
Expand Down Expand Up @@ -953,7 +962,7 @@ def vocabulary_create(context, data_dict):
:param name: the name of the new vocabulary, e.g. ``'Genre'``
:type name: string
:param tags: the new tags to add to the new vocabulary, for the format of
tag dictionaries see ``tag_create()``
tag dictionaries see :py:func:`tag_create`
:type tags: list of tag dictionaries
:returns: the newly-created vocabulary
Expand Down Expand Up @@ -992,8 +1001,7 @@ def activity_create(context, activity_dict, **kw):
``'my_dataset'``
:param activity_type: the type of the activity, this must be an activity
type that CKAN knows how to render, e.g. ``'new package'``,
``'changed user'``, ``'deleted group'`` etc. (for a full list see
``activity_renderers`` in ``ckan/logic/action/get.py``
``'changed user'``, ``'deleted group'`` etc.
:type activity_type: string
:param data: any additional data about the activity
:type data: dictionary
Expand Down Expand Up @@ -1057,7 +1065,8 @@ def tag_create(context, data_dict):
You can only use this function to create tags that belong to a vocabulary,
not to create free tags. (To create a new free tag simply add the tag to
a package, e.g. using the ``package_update`` function.)
a package, e.g. using the
:py:func:`~ckan.logic.action.update.package_update` function.)
:param name: the name for the new tag, a string between 2 and 100
characters long containing only alphanumeric characters and ``-``,
Expand Down
44 changes: 23 additions & 21 deletions ckan/logic/action/get.py
Expand Up @@ -263,6 +263,7 @@ def related_list(context, data_dict=None):
if data_dict.get('featured', False):
related_list = related_list.filter(model.Related.featured == 1)
related_items = related_list.all()
context['sorted'] = True
else:
relateds = model.Related.get_for_dataset(dataset, status='active')
related_items = (r.related for r in relateds)
Expand Down Expand Up @@ -437,10 +438,10 @@ def group_list_authz(context, data_dict):
(optional, default: ``False``)
:type available_only: boolean
:param am_member: if True return only the groups the logged-in user is a
member of, otherwise return all groups that the user is authorized to
:param am_member: if ``True`` return only the groups the logged-in user is
a member of, otherwise return all groups that the user is authorized to
edit (for example, sysadmin users are authorized to edit all groups)
(optional, default: False)
(optional, default: ``False``)
:type am-member: boolean
:returns: list of dictized groups that the user is authorized to edit
Expand Down Expand Up @@ -732,8 +733,8 @@ def package_relationships_list(context, data_dict):
:param id2: the id or name of the second package
:type id: string
:param rel: relationship as string see
:func:`ckan.logic.action.create.package_relationship_create()` for the
relationship types (optional)
:py:func:`~ckan.logic.action.create.package_relationship_create` for
the relationship types (optional)
:rtype: list of dictionaries
Expand Down Expand Up @@ -1328,13 +1329,13 @@ def package_search(context, data_dict):
This action accepts a *subset* of solr's search query parameters:
:param q: the solr query. Optional. Default: `"*:*"`
:param q: the solr query. Optional. Default: ``"*:*"``
:type q: string
:param fq: any filter queries to apply. Note: `+site_id:{ckan_site_id}`
:param fq: any filter queries to apply. Note: ``+site_id:{ckan_site_id}``
is added to this string prior to the query being executed.
:type fq: string
:param sort: sorting of the search results. Optional. Default:
'relevance asc, metadata_modified desc'. As per the solr
``'relevance asc, metadata_modified desc'``. As per the solr
documentation, this is a comma-separated string of field names and
sort-orderings.
:type sort: string
Expand All @@ -1343,7 +1344,7 @@ def package_search(context, data_dict):
:param start: the offset in the complete result for where the set of
returned datasets should begin.
:type start: int
:param facet: whether to enable faceted results. Default: "true".
:param facet: whether to enable faceted results. Default: ``True``.
:type facet: string
:param facet.mincount: the minimum counts for facet fields should be
included in the results.
Expand Down Expand Up @@ -1618,7 +1619,7 @@ def resource_search(context, data_dict):
queries (rather than ValidationErrors).
:param query: The search criteria. See above for description.
:type query: string or list of strings of the form "{field}:{term1}"
:type query: string or list of strings of the form ``{field}:{term1}``
:param fields: Deprecated
:type fields: dict of fields to search terms.
:param order_by: A field on the Resource model that orders the results.
Expand Down Expand Up @@ -2667,11 +2668,12 @@ def followee_list(context, data_dict):
(optional)
:type q: string
:rtype: list of dictionaries, each with keys 'type' (e.g. 'user',
'dataset' or 'group'), 'display_name' (e.g. a user's display name,
or a package's title) and 'dict' (e.g. a dict representing the
followed user, package or group, the same as the dict that would be
returned by user_show, package_show or group_show)
:rtype: list of dictionaries, each with keys ``'type'`` (e.g. ``'user'``,
``'dataset'`` or ``'group'``), ``'display_name'`` (e.g. a user's
display name, or a package's title) and ``'dict'`` (e.g. a dict
representing the followed user, package or group, the same as the dict
that would be returned by :py:func:`user_show`,
:py:func:`package_show` or :py:func:`group_show`)
'''
_check_access('followee_list', context, data_dict)
Expand Down Expand Up @@ -2823,7 +2825,7 @@ def dashboard_activity_list(context, data_dict):
:type offset: int
:param limit: the maximum number of activities to return
(optional, default: 31, the default value is configurable via the
``ckan.activity_list_limit`` setting)
:ref:`ckan.activity_list_limit` setting)
:rtype: list of activity dictionaries
Expand Down Expand Up @@ -2940,12 +2942,12 @@ def _unpick_search(sort, allowed_fields=None, total=None):
def member_roles_list(context, data_dict):
'''Return the possible roles for members of groups and organizations.
:param group_type: the group type, either "group" or "organization"
(optional, default "organization")
:param group_type: the group type, either ``"group"`` or ``"organization"``
(optional, default ``"organization"``)
:type id: string
:returns: a list of dictionaries each with two keys: "text" (the display
name of the role, e.g. "Admin") and "value" (the internal name of the
role, e.g. "admin")
:returns: a list of dictionaries each with two keys: ``"text"`` (the
display name of the role, e.g. ``"Admin"``) and ``"value"`` (the
internal name of the role, e.g. ``"admin"``)
:rtype: list of dictionaries
'''
Expand Down

0 comments on commit 1b572e8

Please sign in to comment.