Skip to content

Commit

Permalink
[#262] Fix helper import in controller package
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Jan 9, 2013
1 parent df8f8d0 commit b80cddf
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions ckan/controllers/package.py
Expand Up @@ -9,17 +9,15 @@
from paste.deploy.converters import asbool

from ckan.logic import get_action, check_access
from ckan.lib.helpers import date_str_to_datetime
from ckan.lib.base import (request,
render,
BaseController,
model,
abort, h, g, c)
abort, g, c)
from ckan.lib.base import response, redirect, gettext
import ckan.lib.maintain as maintain
from ckan.lib.package_saver import PackageSaver, ValidationException
from ckan.lib.navl.dictization_functions import DataError, unflatten, validate
from ckan.lib.helpers import json
from ckan.logic import NotFound, NotAuthorized, ValidationError
from ckan.logic import (tuplize_dict,
clean_dict,
Expand Down Expand Up @@ -323,7 +321,7 @@ def read(self, id, format='html'):
context['revision_id'] = revision_ref
else:
try:
date = date_str_to_datetime(revision_ref)
date = h.date_str_to_datetime(revision_ref)
context['revision_date'] = date
except TypeError, e:
abort(400, _('Invalid revision format: %r') % e.args)
Expand Down Expand Up @@ -478,7 +476,7 @@ def new(self, data=None, errors=None, error_summary=None):

data = data or clean_dict(unflatten(tuplize_dict(parse_params(
request.params, ignore_keys=CACHE_PARAMETERS))))
c.resources_json = json.dumps(data.get('resources', []))
c.resources_json = h.json.dumps(data.get('resources', []))
# convert tags if not supplied in data
if data and not data.get('tag_string'):
data['tag_string'] = ', '.join(
Expand All @@ -502,7 +500,7 @@ def new(self, data=None, errors=None, error_summary=None):
vars = {'data': data, 'errors': errors,
'error_summary': error_summary,
'action': 'new', 'stage': stage}
c.errors_json = json.dumps(errors)
c.errors_json = h.json.dumps(errors)

self._setup_template_variables(context, {},
package_type=package_type)
Expand Down Expand Up @@ -753,7 +751,7 @@ def edit(self, id, data=None, errors=None, error_summary=None):
error_summary=error_summary)

c.pkg = context.get("package")
c.resources_json = json.dumps(data.get('resources', []))
c.resources_json = h.json.dumps(data.get('resources', []))

try:
check_access('package_update', context)
Expand All @@ -766,7 +764,7 @@ def edit(self, id, data=None, errors=None, error_summary=None):
errors = errors or {}
vars = {'data': data, 'errors': errors,
'error_summary': error_summary, 'action': 'edit'}
c.errors_json = json.dumps(errors)
c.errors_json = h.json.dumps(errors)

self._setup_template_variables(context, {'id': id},
package_type=package_type)
Expand Down Expand Up @@ -814,7 +812,7 @@ def read_ajax(self, id, revision=None):
data.pop('tags')
data = flatten_to_string_key(data)
response.headers['Content-Type'] = 'application/json;charset=utf-8'
return json.dumps(data)
return h.json.dumps(data)

def history_ajax(self, id):

Expand Down Expand Up @@ -846,7 +844,7 @@ def history_ajax(self, id):
'current_approved': current_approved})

response.headers['Content-Type'] = 'application/json;charset=utf-8'
return json.dumps(data)
return h.json.dumps(data)

def _get_package_type(self, id):
"""
Expand Down Expand Up @@ -1303,7 +1301,7 @@ def resource_embedded_dataviewer(self, id, resource_id,
c.resource = get_action('resource_show')(context,
{'id': resource_id})
c.package = get_action('package_show')(context, {'id': id})
c.resource_json = json.dumps(c.resource)
c.resource_json = h.json.dumps(c.resource)

# double check that the resource belongs to the specified package
if not c.resource['id'] in [r['id']
Expand All @@ -1322,7 +1320,7 @@ def resource_embedded_dataviewer(self, id, resource_id,
abort(400, ('"state" parameter must be a valid recline '
'state (version %d)' % state_version))

c.recline_state = json.dumps(recline_state)
c.recline_state = h.json.dumps(recline_state)

c.width = max(int(request.params.get('width', width)), 100)
c.height = max(int(request.params.get('height', height)), 100)
Expand All @@ -1338,7 +1336,7 @@ def _parse_recline_state(self, params):
recline_state = {}
for k, v in request.params.items():
try:
v = json.loads(v)
v = h.json.loads(v)
except ValueError:
pass
recline_state[k] = v
Expand Down Expand Up @@ -1398,7 +1396,7 @@ def resource_datapreview(self, id, resource_id):
plugin = plugins_that_can_preview[0]
plugin.setup_template_variables(context, data_dict)

c.resource_json = json.dumps(c.resource)
c.resource_json = h.json.dumps(c.resource)

except NotFound:
abort(404, _('Resource not found'))
Expand Down

0 comments on commit b80cddf

Please sign in to comment.