Skip to content

Commit

Permalink
[#3022] Redirect to the dataset type view page after create or edit
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Nov 28, 2012
1 parent a744035 commit 4c8f83d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions ckan/controllers/package.py
Expand Up @@ -713,7 +713,7 @@ def edit(self, id, data=None, errors=None, error_summary=None):
'pending': True}

if context['save'] and not data:
return self._save_edit(id, context)
return self._save_edit(id, context, package_type=package_type)
try:
c.pkg_dict = get_action('package_show')(context, {'id': id})
context['for_edit'] = True
Expand Down Expand Up @@ -905,7 +905,7 @@ def _save_new(self, context, package_type=None):
id=pkg_dict['name'])
redirect(url)

self._form_save_redirect(pkg_dict['name'], 'new')
self._form_save_redirect(pkg_dict['name'], 'new', package_type=package_type)
except NotAuthorized:
abort(401, _('Unauthorized to read package %s') % '')
except NotFound, e:
Expand All @@ -931,7 +931,7 @@ def _save_new(self, context, package_type=None):
data_dict['state'] = 'none'
return self.new(data_dict, errors, error_summary)

def _save_edit(self, name_or_id, context):
def _save_edit(self, name_or_id, context, package_type=None):
from ckan.lib.search import SearchIndexError
log.debug('Package save request name: %s POST: %r',
name_or_id, request.POST)
Expand All @@ -957,7 +957,7 @@ def _save_edit(self, name_or_id, context):
c.pkg = context['package']
c.pkg_dict = pkg

self._form_save_redirect(pkg['name'], 'edit')
self._form_save_redirect(pkg['name'], 'edit', package_type=package_type)
except NotAuthorized:
abort(401, _('Unauthorized to read package %s') % id)
except NotFound, e:
Expand All @@ -975,7 +975,7 @@ def _save_edit(self, name_or_id, context):
error_summary = e.error_summary
return self.edit(name_or_id, data_dict, errors, error_summary)

def _form_save_redirect(self, pkgname, action):
def _form_save_redirect(self, pkgname, action, package_type=None):
'''This redirects the user to the CKAN package/read page,
unless there is request parameter giving an alternate location,
perhaps an external website.
Expand All @@ -988,7 +988,10 @@ def _form_save_redirect(self, pkgname, action):
if url:
url = url.replace('<NAME>', pkgname)
else:
url = h.url_for(controller='package', action='read', id=pkgname)
if package_type:
url = h.url_for('{0}_read'.format(package_type), id=pkgname)
else:
url = h.url_for(controller='package', action='read', id=pkgname)
redirect(url)

def _adjust_license_id_options(self, pkg, fs):
Expand Down

0 comments on commit 4c8f83d

Please sign in to comment.