Skip to content

Commit

Permalink
Merge branch 'master' of github.com:okfn/ckan into 1462-reviewing-gui…
Browse files Browse the repository at this point in the history
…delines
  • Loading branch information
Sean Hammond committed Jan 27, 2014
2 parents 1198206 + bb70fc5 commit bd44fd5
Show file tree
Hide file tree
Showing 57 changed files with 636 additions and 371 deletions.
6 changes: 2 additions & 4 deletions ckan/config/deployment.ini_tmpl
Expand Up @@ -44,8 +44,6 @@ who.log_file = %(cache_dir)s/who_log.ini

## Database Settings
sqlalchemy.url = postgresql://ckan_default:pass@localhost/ckan_default
#sqlalchemy.url = sqlite:///
#sqlalchemy.url = sqlite:///%(here)s/somedb.db

#ckan.datastore.write_url = postgresql://ckan_default:pass@localhost/datastore_default
#ckan.datastore.read_url = postgresql://datastore_default:pass@localhost/datastore_default
Expand Down Expand Up @@ -130,8 +128,8 @@ ckan.feeds.author_link =

# Make sure you have set up the DataStore

ckan.datapusher.formats = csv
ckan.datapusher.url = http://datapusher.ckan.org/
#ckan.datapusher.formats =
#ckan.datapusher.url = http://127.0.0.1:8800/

## Activity Streams Settings

Expand Down
6 changes: 6 additions & 0 deletions ckan/config/middleware.py
Expand Up @@ -18,6 +18,7 @@
from routes.middleware import RoutesMiddleware
from repoze.who.config import WhoConfig
from repoze.who.middleware import PluggableAuthenticationMiddleware
from repoze.who.plugins.auth_tkt import make_plugin as auth_tkt_make_plugin
from fanstatic import Fanstatic

from ckan.plugins import PluginImplementations
Expand Down Expand Up @@ -183,6 +184,11 @@ def make_app(conf, full_stack=True, static_files=True, **app_conf):

return app

def ckan_auth_tkt_make_app(**kw):
if not len(kw.get('secret', '')) or kw.get('secret') == 'somesecret':
kw['secret'] = config['beaker.session.secret']
return auth_tkt_make_plugin(**kw)


class I18nMiddleware(object):
"""I18n Middleware selects the language based on the url
Expand Down
5 changes: 3 additions & 2 deletions ckan/config/who.ini
@@ -1,6 +1,7 @@
[plugin:auth_tkt]
use = repoze.who.plugins.auth_tkt:make_plugin
secret = somesecret
use = ckan.config.middleware:ckan_auth_tkt_make_app
# If no secret key is defined here, beaker.session.secret will be used
#secret = somesecret

[plugin:friendlyform]
use = repoze.who.plugins.friendlyform:FriendlyFormPlugin
Expand Down
15 changes: 5 additions & 10 deletions ckan/controllers/feed.py
Expand Up @@ -21,7 +21,6 @@
# TODO fix imports
import logging
import urlparse
from urllib import urlencode

import webhelpers.feedgenerator
from pylons import config
Expand Down Expand Up @@ -277,8 +276,6 @@ def custom(self):
search_params[param] = value
fq += ' %s:"%s"' % (param, value)

search_url_params = urlencode(search_params)

try:
page = int(request.params.get('page', 1))
except ValueError:
Expand Down Expand Up @@ -307,6 +304,9 @@ def custom(self):
controller='feed',
action='custom')

atom_url = h._url_with_params('/feeds/custom.atom',
search_params.items())

alternate_url = self._alternate_url(request.params)

return self.output_feed(results,
Expand All @@ -315,8 +315,7 @@ def custom(self):
' datasets on %s. Custom query: \'%s\'' %
(g.site_title, q),
feed_link=alternate_url,
feed_guid=_create_atom_id
(u'/feeds/custom.atom?%s' % search_url_params),
feed_guid=_create_atom_id(atom_url),
feed_url=feed_url,
navigation_urls=navigation_urls)

Expand Down Expand Up @@ -376,11 +375,7 @@ def _feed_url(self, query, controller, action, **kwargs):
parameters.
"""
path = h.url_for(controller=controller, action=action, **kwargs)
query = [(k, v.encode('utf-8') if isinstance(v, basestring)
else str(v)) for k, v in query.items()]

# a trailing '?' is valid.
return self.base_url + path + u'?' + urlencode(query)
return h._url_with_params(self.base_url + path, query.items())

def _navigation_urls(self, query, controller, action,
item_count, limit, **kwargs):
Expand Down
5 changes: 3 additions & 2 deletions ckan/controllers/group.py
Expand Up @@ -290,7 +290,7 @@ def pager_url(q=None, page=None):
'groups': _('Groups'),
'tags': _('Tags'),
'res_format': _('Formats'),
'license_id': _('License')}
'license_id': _('Licenses')}

for facet in g.facets:
if facet in default_facet_titles:
Expand Down Expand Up @@ -323,7 +323,8 @@ def pager_url(q=None, page=None):
'extras': search_extras
}

query = get_action('package_search')(context, data_dict)
context_ = dict((k, v) for (k, v) in context.items() if k != 'schema')
query = get_action('package_search')(context_, data_dict)

c.page = h.Page(
collection=query['results'],
Expand Down
2 changes: 1 addition & 1 deletion ckan/controllers/home.py
Expand Up @@ -71,7 +71,7 @@ def index(self):
'groups': _('Groups'),
'tags': _('Tags'),
'res_format': _('Formats'),
'license': _('License'),
'license': _('Licenses'),
}

data_dict = {'sort': 'packages', 'all_fields': 1}
Expand Down
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
8 changes: 7 additions & 1 deletion ckan/lib/dictization/__init__.py
Expand Up @@ -3,6 +3,12 @@
import sqlalchemy
from pylons import config

try:
RowProxy = sqlalchemy.engine.result.RowProxy
except AttributeError:
RowProxy = sqlalchemy.engine.base.RowProxy


# NOTE
# The functions in this file contain very generic methods for dictizing objects
# and saving dictized objects. If a specialised use is needed please do NOT extend
Expand All @@ -17,7 +23,7 @@ def table_dictize(obj, context, **kw):
model = context["model"]
session = model.Session

if isinstance(obj, sqlalchemy.engine.base.RowProxy):
if isinstance(obj, RowProxy):
fields = obj.keys()
else:
ModelClass = obj.__class__
Expand Down
8 changes: 5 additions & 3 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 Expand Up @@ -375,7 +376,8 @@ def group_dictize(group, context):
if include_datasets:
q['rows'] = 1000 # Only the first 1000 datasets are returned

search_results = logic.get_action('package_search')(context, q)
context_ = dict((k, v) for (k, v) in context.items() if k != 'schema')
search_results = logic.get_action('package_search')(context_, q)

if include_datasets:
result_dict['packages'] = search_results['results']
Expand Down
8 changes: 6 additions & 2 deletions ckan/lib/helpers.py
Expand Up @@ -38,6 +38,7 @@
import ckan.lib.datapreview as datapreview
import ckan.logic as logic
import ckan.lib.uploader as uploader
import ckan.new_authz as new_authz

from ckan.common import (
_, ungettext, g, c, request, session, json, OrderedDict
Expand Down Expand Up @@ -604,7 +605,7 @@ def get_facet_title(name):
'groups': _('Groups'),
'tags': _('Tags'),
'res_format': _('Formats'),
'license': _('License'), }
'license': _('Licenses'), }
return facet_titles.get(name, name.capitalize())


Expand Down Expand Up @@ -1713,7 +1714,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 Expand Up @@ -1753,6 +1754,8 @@ def get_site_statistics():

return stats

def check_config_permission(permission):
return new_authz.check_config_permission(permission)

# these are the functions that will end up in `h` template helpers
__allowed_functions__ = [
Expand Down Expand Up @@ -1855,4 +1858,5 @@ def get_site_statistics():
'get_featured_organizations',
'get_featured_groups',
'get_site_statistics',
'check_config_permission',
]
6 changes: 4 additions & 2 deletions ckan/logic/__init__.py
Expand Up @@ -402,7 +402,7 @@ def get_action(action):
def make_wrapped(_action, action_name):
def wrapped(context=None, data_dict=None, **kw):
if kw:
log.critical('%s was pass extra keywords %r'
log.critical('%s was passed extra keywords %r'
% (_action.__name__, kw))

context = _prepopulate_context(context)
Expand All @@ -423,7 +423,9 @@ def wrapped(context=None, data_dict=None, **kw):
if action_name not in new_authz.auth_functions_list():
log.debug('No auth function for %s' % action_name)
elif not getattr(_action, 'auth_audit_exempt', False):
raise Exception('Action Auth Audit: %s' % action_name)
raise Exception(
'Action function {0} did not call its auth function'
.format(action_name))
# remove from audit stack
context['__auth_audit'].pop()
except IndexError:
Expand Down
57 changes: 33 additions & 24 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 All @@ -1003,6 +1011,8 @@ def activity_create(context, activity_dict, **kw):
'''

_check_access('activity_create', context, activity_dict)

# this action had a ignore_auth param which has been removed
# removed in 2.2
if 'ignore_auth' in kw:
Expand All @@ -1023,8 +1033,6 @@ def activity_create(context, activity_dict, **kw):
else:
activity_dict['revision_id'] = None

_check_access('activity_create', context, activity_dict)

schema = context.get('schema') or ckan.logic.schema.default_create_activity_schema()
data, errors = _validate(activity_dict, schema, context)
if errors:
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

0 comments on commit bd44fd5

Please sign in to comment.