Skip to content

Commit

Permalink
[#3194] Consolidate some further redirect calls
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Aug 19, 2016
1 parent dae599a commit e34f74f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
45 changes: 19 additions & 26 deletions ckan/controllers/package.py
Expand Up @@ -30,7 +30,6 @@

render = base.render
abort = base.abort
redirect = h.redirect_to

NotFound = logic.NotFound
NotAuthorized = logic.NotAuthorized
Expand Down Expand Up @@ -573,8 +572,8 @@ def resource_edit(self, id, resource_id, data=None, errors=None,
errors, error_summary)
except NotAuthorized:
abort(403, _('Unauthorized to edit this resource'))
redirect(h.url_for(controller='package', action='resource_read',
id=id, resource_id=resource_id))
h.redirect_to(controller='package', action='resource_read', id=id,
resource_id=resource_id)

context = {'model': model, 'session': model.Session,
'api_version': 3, 'for_edit': True,
Expand Down Expand Up @@ -643,8 +642,7 @@ def new_resource(self, id, data=None, errors=None, error_summary=None):
if not data_provided and save_action != "go-dataset-complete":
if save_action == 'go-dataset':
# go to final stage of adddataset
redirect(h.url_for(controller='package',
action='edit', id=id))
h.redirect_to(controller='package', action='edit', id=id)
# see if we have added any resources
try:
data_dict = get_action('package_show')(context, {'id': id})
Expand All @@ -659,8 +657,8 @@ def new_resource(self, id, data=None, errors=None, error_summary=None):
# On new templates do not use flash message
if g.legacy_templates:
h.flash_error(msg)
redirect(h.url_for(controller='package',
action='new_resource', id=id))
h.redirect_to(controller='package',
action='new_resource', id=id)
else:
errors = {}
error_summary = {_('Error'): msg}
Expand All @@ -671,8 +669,7 @@ def new_resource(self, id, data=None, errors=None, error_summary=None):
get_action('package_update')(
dict(context, allow_state_change=True),
dict(data_dict, state='active'))
redirect(h.url_for(controller='package',
action='read', id=id))
h.redirect_to(controller='package', action='read', id=id)

data['package_id'] = id
try:
Expand All @@ -696,20 +693,17 @@ def new_resource(self, id, data=None, errors=None, error_summary=None):
get_action('package_update')(
dict(context, allow_state_change=True),
dict(data_dict, state='active'))
redirect(h.url_for(controller='package',
action='read', id=id))
h.redirect_to(controller='package', action='read', id=id)
elif save_action == 'go-dataset':
# go to first stage of add dataset
redirect(h.url_for(controller='package',
action='edit', id=id))
h.redirect_to(controller='package', action='edit', id=id)
elif save_action == 'go-dataset-complete':
# go to first stage of add dataset
redirect(h.url_for(controller='package',
action='read', id=id))
h.redirect_to(controller='package', action='read', id=id)
else:
# add more resources
redirect(h.url_for(controller='package',
action='new_resource', id=id))
h.redirect_to(controller='package', action='new_resource',
id=id)

# get resources for sidebar
context = {'model': model, 'session': model.Session,
Expand Down Expand Up @@ -904,7 +898,7 @@ def _save_new(self, context, package_type=None):
url = h.url_for(controller='package',
action='new_resource',
id=pkg_dict['name'])
redirect(url)
h.redirect_to(url)
# Make sure we don't index this dataset
if request.params['save'] not in ['go-resource',
'go-metadata']:
Expand All @@ -921,7 +915,7 @@ def _save_new(self, context, package_type=None):
url = h.url_for(controller='package',
action='new_resource',
id=pkg_dict['name'])
redirect(url)
h.redirect_to(url)

self._form_save_redirect(pkg_dict['name'], 'new',
package_type=package_type)
Expand Down Expand Up @@ -1008,7 +1002,7 @@ def _form_save_redirect(self, pkgname, action, package_type=None):
id=pkgname)
else:
url = h.url_for('{0}_read'.format(package_type), id=pkgname)
redirect(url)
h.redirect_to(url)

def delete(self, id):

Expand Down Expand Up @@ -1163,7 +1157,7 @@ def resource_download(self, id, resource_id, filename=None):
return app_iter
elif not 'url' in rsc:
abort(404, _('No download is available'))
redirect(rsc['url'])
h.redirect_to(rsc['url'])

def follow(self, id):
'''Start following this dataset.'''
Expand Down Expand Up @@ -1262,8 +1256,7 @@ def groups(self, id):
get_action('member_delete')(context, data_dict)
except NotFound:
abort(404, _('Group not found'))
redirect(h.url_for(controller='package',
action='groups', id=id))
h.redirect_to(controller='package', action='groups', id=id)

context['is_member'] = True
users_groups = get_action('group_list_authz')(context, data_dict)
Expand Down Expand Up @@ -1475,9 +1468,9 @@ def edit_view(self, id, resource_id, view_id=None):
abort(403, _('Unauthorized to edit resource'))
else:
if not to_preview:
redirect(h.url_for(controller='package',
action='resource_views',
id=id, resource_id=resource_id))
h.redirect_to(controller='package',
action='resource_views',
id=id, resource_id=resource_id)

## view_id exists only when updating
if view_id:
Expand Down
4 changes: 2 additions & 2 deletions ckanext/datapusher/plugin.py
Expand Up @@ -41,11 +41,11 @@ def resource_data(self, id, resource_id):
except logic.ValidationError:
pass

base.redirect(core_helpers.url_for(
core_helpers.redirect_to(
controller='ckanext.datapusher.plugin:ResourceDataController',
action='resource_data',
id=id,
resource_id=resource_id)
resource_id=resource_id
)

try:
Expand Down

0 comments on commit e34f74f

Please sign in to comment.