Skip to content

Commit

Permalink
Merge branch 'master' into 262-improve-helper-imports
Browse files Browse the repository at this point in the history
Conflicts:
	ckan/controllers/home.py
	ckan/controllers/revision.py
	ckan/controllers/tag.py

    - minor import fixes (trivial)
  • Loading branch information
tobes committed Feb 26, 2013
2 parents 128a400 + e481cf6 commit eaff7b9
Show file tree
Hide file tree
Showing 152 changed files with 2,339 additions and 2,531 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
@@ -1,5 +1,6 @@
language: python
python:
- "2.6"
- "2.7"
before_install:
- sudo apt-get update -qq
Expand All @@ -23,9 +24,8 @@ before_script:
- sudo cp ckan/config/solr/schema-2.0.xml /etc/solr/conf/schema.xml
- sudo service jetty restart
- paster --plugin=ckan db init
- sed -i -e 's/ -W//g' ckanext/datastore/bin/datastore_setup.py
- paster datastore set-permissions postgres
script: "nosetests --ckan ckan && nosetests --ckan --with-pylons=test-core.ini --nologcapture --cover-package=ckanext.datastore ckanext/datastore/tests -x"
script: "nosetests --ckan --with-pylons=test-core.ini --nologcapture ckan ckanext"
notifications:
irc:
channels:
Expand Down
10 changes: 5 additions & 5 deletions ckan/config/middleware.py
Expand Up @@ -27,10 +27,10 @@
import ckan.lib.app_globals as app_globals


def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
def make_app(conf, full_stack=True, static_files=True, **app_conf):
"""Create a Pylons WSGI application and return it
``global_conf``
``conf``
The inherited configuration for this application. Normally from
the [DEFAULT] section of the Paste ini file.
Expand All @@ -51,7 +51,7 @@ def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
"""
# Configure the Pylons environment
load_environment(global_conf, app_conf)
load_environment(conf, app_conf)

# The Pylons WSGI app
app = PylonsApp()
Expand Down Expand Up @@ -90,7 +90,7 @@ def make_app(global_conf, full_stack=True, static_files=True, **app_conf):

if asbool(full_stack):
# Handle Python exceptions
app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
app = ErrorHandler(app, conf, **config['pylons.errorware'])

# Display error documents for 401, 403, 404 status codes (and
# 500 when debug is disabled)
Expand All @@ -100,7 +100,7 @@ def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
app = StatusCodeRedirect(app, [400, 404, 500])

# Initialize repoze.who
who_parser = WhoConfig(global_conf['here'])
who_parser = WhoConfig(conf['here'])
who_parser.parse(open(app_conf['who.config_file']))

if asbool(config.get('openid_enabled', 'true')):
Expand Down
15 changes: 10 additions & 5 deletions ckan/config/routing.py
Expand Up @@ -197,8 +197,8 @@ def make_map():
action='delete')
m.connect('related_list', '/dataset/{id}/related', action='list',
ckan_icon='picture')
m.connect('related_read', '/apps/{id}', action='read')
m.connect('related_dashboard', '/apps', action='dashboard')
m.connect('related_read', '/related/{id}', action='read')
m.connect('related_dashboard', '/related', action='dashboard')

with SubMapper(map, controller='package') as m:
m.connect('search', '/dataset', action='search',
Expand Down Expand Up @@ -329,12 +329,14 @@ def make_map():
m.connect('user_activity_stream', '/user/activity/{id}',
action='activity', ckan_icon='time')
m.connect('/dashboard/{offset}', action='dashboard')
m.connect('/dashboard', action='dashboard')
m.connect('user_dashboard', '/dashboard', action='dashboard',
ckan_icon='list')
m.connect('user_follow', '/user/follow/{id}', action='follow')
m.connect('/user/unfollow/{id}', action='unfollow')
m.connect('user_followers', '/user/followers/{id:.*}',
action='followers', ckan_icon='group')
m.connect('/user/edit/{id:.*}', action='edit')
m.connect('user_edit', '/user/edit/{id:.*}', action='edit',
ckan_icon='cog')
m.connect('/user/reset/{id:.*}', action='perform_reset')
m.connect('register', '/user/register', action='register')
m.connect('login', '/user/login', action='login')
Expand Down Expand Up @@ -363,7 +365,10 @@ def make_map():
m.connect('/feeds/dataset.atom', action='general')
m.connect('/feeds/custom.atom', action='custom')

map.connect('ckanadmin_index', '/ckan-admin', controller='admin', action='index')
map.connect('ckanadmin_index', '/ckan-admin', controller='admin',
action='index', ckan_icon='legal')
map.connect('ckanadmin_config', '/ckan-admin/config', controller='admin',
action='config', ckan_icon='check')
map.connect('ckanadmin', '/ckan-admin/{action}', controller='admin')

# Storage routes
Expand Down
17 changes: 10 additions & 7 deletions ckan/controllers/group.py
Expand Up @@ -148,7 +148,7 @@ def read(self, id):
context = {'model': model, 'session': model.Session,
'user': c.user or c.author,
'schema': self._db_to_form_schema(group_type=group_type),
'for_view': True, 'extras_as_string': True}
'for_view': True}
data_dict = {'id': id}
# unicode format (decoded from utf8)
q = c.q = request.params.get('q', '')
Expand Down Expand Up @@ -290,7 +290,7 @@ def new(self, data=None, errors=None, error_summary=None):
data['type'] = group_type

context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'extras_as_string': True,
'user': c.user or c.author,
'save': 'save' in request.params,
'parent': request.params.get('parent', None)}
try:
Expand All @@ -315,7 +315,7 @@ def new(self, data=None, errors=None, error_summary=None):
def edit(self, id, data=None, errors=None, error_summary=None):
group_type = self._get_group_type(id.split('@')[0])
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'extras_as_string': True,
'user': c.user or c.author,
'save': 'save' in request.params,
'for_edit': True,
'parent': request.params.get('parent', None)
Expand Down Expand Up @@ -552,8 +552,7 @@ def history(self, id):

context = {'model': model, 'session': model.Session,
'user': c.user or c.author,
'schema': self._form_to_db_schema(),
'extras_as_string': True}
'schema': self._form_to_db_schema()}
data_dict = {'id': id}
try:
c.group_dict = self._action('group_show')(context, data_dict)
Expand Down Expand Up @@ -643,7 +642,9 @@ def follow(self, id):
data_dict = {'id': id}
try:
get_action('follow_group')(context, data_dict)
h.flash_success(_("You are now following {0}").format(id))
group_dict = get_action('group_show')(context, data_dict)
h.flash_success(_("You are now following {0}").format(
group_dict['title']))
except ValidationError as e:
error_message = (e.extra_msg or e.message or e.error_summary
or e.error_dict)
Expand All @@ -660,7 +661,9 @@ def unfollow(self, id):
data_dict = {'id': id}
try:
get_action('unfollow_group')(context, data_dict)
h.flash_success(_("You are no longer following {0}").format(id))
group_dict = get_action('group_show')(context, data_dict)
h.flash_success(_("You are no longer following {0}").format(
group_dict['title']))
except ValidationError as e:
error_message = (e.extra_msg or e.message or e.error_summary
or e.error_dict)
Expand Down
40 changes: 20 additions & 20 deletions ckan/controllers/home.py
@@ -1,37 +1,37 @@
import random

from pylons.i18n import set_lang
from pylons.i18n import _
from pylons import g, c, config, cache
import sqlalchemy.exc

import ckan.logic
import ckan.logic as logic
import ckan.lib.maintain as maintain
from ckan.lib.search import SearchError
from ckan.lib.base import *
import ckan.lib.search as search
import ckan.lib.base as base
import ckan.model as model
import ckan.lib.helpers as h

CACHE_PARAMETERS = ['__cache', '__no_cache__']

# horrible hack
dirty_cached_group_stuff = None

class HomeController(BaseController):
class HomeController(base.BaseController):
repo = model.repo

def __before__(self, action, **env):
try:
BaseController.__before__(self, action, **env)
base.BaseController.__before__(self, action, **env)
context = {'model': model, 'user': c.user or c.author}
ckan.logic.check_access('site_read', context)
except ckan.logic.NotAuthorized:
abort(401, _('Not authorized to see this page'))
logic.check_access('site_read', context)
except logic.NotAuthorized:
base.abort(401, _('Not authorized to see this page'))
except (sqlalchemy.exc.ProgrammingError,
sqlalchemy.exc.OperationalError), e:
# postgres and sqlite errors for missing tables
msg = str(e)
if ('relation' in msg and 'does not exist' in msg) or \
('no such table' in msg):
# table missing, major database problem
abort(503, _('This site is currently off-line. Database '
base.abort(503, _('This site is currently off-line. Database '
'is not initialised.'))
# TODO: send an email to the admin person (#1285)
else:
Expand All @@ -50,7 +50,7 @@ def index(self):
'sort': 'views_recent desc',
'fq': 'capacity:"public"'
}
query = ckan.logic.get_action('package_search')(
query = logic.get_action('package_search')(
context, data_dict)
c.search_facets = query['search_facets']
c.package_count = query['count']
Expand All @@ -74,8 +74,8 @@ def index(self):
if 'groups' in c.search_facets:
data_dict['groups'] = [ item['name'] for item in
c.search_facets['groups']['items'] ]
c.groups = ckan.logic.get_action('group_list')(context, data_dict)
except SearchError, se:
c.groups = logic.get_action('group_list')(context, data_dict)
except search.SearchError, se:
c.package_count = 0
c.groups = []

Expand Down Expand Up @@ -130,8 +130,8 @@ def db_to_form_schema(group_type=None):
data_dict = {'id': id}

try:
group_dict = ckan.logic.get_action('group_show')(context, data_dict)
except ckan.logic.NotFound:
group_dict = logic.get_action('group_show')(context, data_dict)
except logic.NotFound:
return None

return {'group_dict' :group_dict}
Expand Down Expand Up @@ -172,13 +172,13 @@ def db_to_form_schema(group_type=None):

# END OF DIRTYNESS

return render('home/index.html', cache_force=True)
return base.render('home/index.html', cache_force=True)

def license(self):
return render('home/license.html')
return base.render('home/license.html')

def about(self):
return render('home/about.html')
return base.render('home/about.html')

def cache(self, id):
'''Manual way to clear the caches'''
Expand Down
38 changes: 18 additions & 20 deletions ckan/controllers/package.py
Expand Up @@ -309,8 +309,7 @@ def read(self, id, format='html'):

package_type = self._get_package_type(id.split('@')[0])
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'extras_as_string': True,
'for_view': True}
'user': c.user or c.author, 'for_view': True}
data_dict = {'id': id}

# interpret @<revision_id> or @<date> suffix
Expand Down Expand Up @@ -357,7 +356,7 @@ def read(self, id, format='html'):
def comments(self, id):
package_type = self._get_package_type(id)
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'extras_as_string': True}
'user': c.user or c.author}

#check if package exists
try:
Expand Down Expand Up @@ -394,8 +393,7 @@ def history(self, id):
h.redirect_to(controller='revision', action='diff', **params)

context = {'model': model, 'session': model.Session,
'user': c.user or c.author,
'extras_as_string': True}
'user': c.user or c.author}
data_dict = {'id': id}
try:
c.pkg_dict = get_action('package_show')(context, data_dict)
Expand Down Expand Up @@ -461,7 +459,7 @@ def new(self, data=None, errors=None, error_summary=None):
package_type = self._guess_package_type(True)

context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'extras_as_string': True,
'user': c.user or c.author,
'save': 'save' in request.params}

# Package needs to have a organization group in the call to
Expand Down Expand Up @@ -525,8 +523,7 @@ def resource_edit(self, id, resource_id, data=None, errors=None,

context = {'model': model, 'session': model.Session,
'api_version': 3,
'user': c.user or c.author,
'extras_as_string': True}
'user': c.user or c.author}

data['package_id'] = id
try:
Expand Down Expand Up @@ -592,8 +589,7 @@ def new_resource(self, id, data=None, errors=None, error_summary=None):
del data['id']

context = {'model': model, 'session': model.Session,
'user': c.user or c.author,
'extras_as_string': True}
'user': c.user or c.author}

# see if we have any data that we are trying to save
data_provided = False
Expand Down Expand Up @@ -657,7 +653,7 @@ def new_resource(self, id, data=None, errors=None, error_summary=None):
vars['pkg_name'] = id
# get resources for sidebar
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'extras_as_string': True,}
'user': c.user or c.author}
pkg_dict = get_action('package_show')(context, {'id': id})
# required for nav menu
vars['pkg_dict'] = pkg_dict
Expand All @@ -677,8 +673,8 @@ def new_metadata(self, id, data=None, errors=None, error_summary=None):
# we don't want to include save as it is part of the form
del data['save']
context = {'model': model, 'session': model.Session,
'user': c.user or c.author,
'extras_as_string': True}
'user': c.user or c.author}

data_dict = get_action('package_show')(context, {'id': id})

data_dict['id'] = id
Expand Down Expand Up @@ -712,7 +708,7 @@ def new_metadata(self, id, data=None, errors=None, error_summary=None):

if not data:
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'extras_as_string': True,}
'user': c.user or c.author}
data = get_action('package_show')(context, {'id': id})
errors = errors or {}
error_summary = error_summary or {}
Expand All @@ -728,7 +724,7 @@ def new_metadata(self, id, data=None, errors=None, error_summary=None):
def edit(self, id, data=None, errors=None, error_summary=None):
package_type = self._get_package_type(id)
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'extras_as_string': True,
'user': c.user or c.author,
'save': 'save' in request.params,
'moderated': config.get('moderated'),
'pending': True}
Expand Down Expand Up @@ -795,7 +791,6 @@ def read_ajax(self, id, revision=None):
package_type = self._get_package_type(id)
context = {'model': model, 'session': model.Session,
'user': c.user or c.author,
'extras_as_string': True,
'schema': self._form_to_db_schema(
package_type=package_type),
'revision_id': revision}
Expand All @@ -820,8 +815,7 @@ def read_ajax(self, id, revision=None):
def history_ajax(self, id):

context = {'model': model, 'session': model.Session,
'user': c.user or c.author,
'extras_as_string': True}
'user': c.user or c.author}
data_dict = {'id': id}
try:
pkg_revisions = get_action('package_revision_list')(
Expand Down Expand Up @@ -1220,7 +1214,9 @@ def follow(self, id):
data_dict = {'id': id}
try:
get_action('follow_dataset')(context, data_dict)
h.flash_success(_("You are now following {0}").format(id))
package_dict = get_action('package_show')(context, data_dict)
h.flash_success(_("You are now following {0}").format(
package_dict['title']))
except ValidationError as e:
error_message = (e.extra_msg or e.message or e.error_summary
or e.error_dict)
Expand All @@ -1237,7 +1233,9 @@ def unfollow(self, id):
data_dict = {'id': id}
try:
get_action('unfollow_dataset')(context, data_dict)
h.flash_success(_("You are no longer following {0}").format(id))
package_dict = get_action('package_show')(context, data_dict)
h.flash_success(_("You are no longer following {0}").format(
package_dict['title']))
except ValidationError as e:
error_message = (e.extra_msg or e.message or e.error_summary
or e.error_dict)
Expand Down

0 comments on commit eaff7b9

Please sign in to comment.