Skip to content

Commit

Permalink
Merge pull request #1675 from OCHA-DAP/staging
Browse files Browse the repository at this point in the history
Stag into Prod
  • Loading branch information
danmihaila committed Nov 5, 2014
2 parents c6e9893 + 619bc23 commit 3bc80b7
Show file tree
Hide file tree
Showing 56 changed files with 1,076 additions and 459 deletions.
85 changes: 47 additions & 38 deletions ckan/controllers/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def drill_down_url(alternative_url=None, **by):

def remove_field(key, value=None, replace=None):
return h.remove_url_param(key, value=value, replace=replace,
controller='package', action='search')
controller='package', action='search')

c.remove_field = remove_field

Expand Down Expand Up @@ -222,12 +222,12 @@ def pager_url(q=None, page=None):
facets = OrderedDict()

default_facet_titles = {
'organization': _('Organizations'),
'groups': _('Groups'),
'tags': _('Tags'),
'res_format': _('Formats'),
'license_id': _('Licenses'),
}
'organization': _('Organizations'),
'groups': _('Groups'),
'tags': _('Tags'),
'res_format': _('Formats'),
'license_id': _('Licenses'),
}

for facet in g.facets:
if facet in default_facet_titles:
Expand Down Expand Up @@ -279,12 +279,12 @@ def pager_url(q=None, page=None):
abort(400, _('Parameter "{parameter_name}" is not '
'an integer').format(
parameter_name='_%s_limit' % facet
))
))
c.search_facets_limits[facet] = limit

maintain.deprecate_context_item(
'facets',
'Use `c.search_facets` instead.')
'facets',
'Use `c.search_facets` instead.')

self._setup_template_variables(context, {},
package_type=package_type)
Expand Down Expand Up @@ -402,7 +402,7 @@ def read(self, id, format='html'):
except ckan.lib.render.TemplateNotFound:
msg = _("Viewing {package_type} datasets in {format} format is "
"not supported (template file {file} not found).".format(
package_type=package_type, format=format, file=template))
package_type=package_type, format=format, file=template))
abort(404, msg)

assert False, "We should never get here"
Expand Down Expand Up @@ -581,15 +581,18 @@ def resource_edit(self, id, resource_id, data=None, errors=None,
pkg_dict = get_action('package_show')(context, {'id': id})
if pkg_dict['state'].startswith('draft'):
# dataset has not yet been fully created
resource_dict = get_action('resource_show')(context, {'id': resource_id})
fields = ['url', 'resource_type', 'format', 'name', 'description', 'id']
resource_dict = get_action('resource_show')(
context, {'id': resource_id})
fields = [
'url', 'resource_type', 'format', 'name', 'description', 'id']
data = {}
for field in fields:
data[field] = resource_dict[field]
return self.new_resource(id, data=data)
# resource is fully created
try:
resource_dict = get_action('resource_show')(context, {'id': resource_id})
resource_dict = get_action('resource_show')(
context, {'id': resource_id})
except NotFound:
abort(404, _('Resource not found'))
c.pkg_dict = pkg_dict
Expand Down Expand Up @@ -627,7 +630,7 @@ def new_resource(self, id, data=None, errors=None, error_summary=None):
data_provided = False
for key, value in data.iteritems():
if ((value or isinstance(value, cgi.FieldStorage))
and key != 'resource_type'):
and key != 'resource_type'):
data_provided = True
break

Expand All @@ -643,7 +646,7 @@ def new_resource(self, id, data=None, errors=None, error_summary=None):
abort(401, _('Unauthorized to update dataset'))
except NotFound:
abort(404,
_('The dataset {id} could not be found.').format(id=id))
_('The dataset {id} could not be found.').format(id=id))
if not len(data_dict['resources']):
# no data so keep on page
msg = _('You must add at least one data resource')
Expand Down Expand Up @@ -675,7 +678,7 @@ def new_resource(self, id, data=None, errors=None, error_summary=None):
abort(401, _('Unauthorized to create a resource'))
except NotFound:
abort(404,
_('The dataset {id} could not be found.').format(id=id))
_('The dataset {id} could not be found.').format(id=id))
if save_action == 'go-metadata':
# go to final stage of add dataset
redirect(h.url_for(controller='package',
Expand Down Expand Up @@ -962,7 +965,8 @@ def _save_new(self, context, package_type=None):
id=pkg_dict['name'])
redirect(url)

self._form_save_redirect(pkg_dict['name'], 'new', package_type=package_type)
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 Down Expand Up @@ -1013,7 +1017,8 @@ def _save_edit(self, name_or_id, context, package_type=None):
c.pkg = context['package']
c.pkg_dict = pkg

self._form_save_redirect(pkg['name'], 'edit', package_type=package_type)
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 Down Expand Up @@ -1045,7 +1050,8 @@ def _form_save_redirect(self, pkgname, action, package_type=None):
url = url.replace('<NAME>', pkgname)
else:
if package_type is None or package_type == 'dataset':
url = h.url_for(controller='package', action='read', id=pkgname)
url = h.url_for(
controller='package', action='read', id=pkgname)
else:
url = h.url_for('{0}_read'.format(package_type), id=pkgname)
redirect(url)
Expand Down Expand Up @@ -1088,7 +1094,8 @@ def delete(self, id):
def resource_delete(self, id, resource_id):

if 'cancel' in request.params:
h.redirect_to(controller='package', action='resource_edit', resource_id=resource_id, id=id)
h.redirect_to(
controller='package', action='resource_edit', resource_id=resource_id, id=id)

context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'auth_user_obj': c.userobj}
Expand All @@ -1103,7 +1110,8 @@ def resource_delete(self, id, resource_id):
get_action('resource_delete')(context, {'id': resource_id})
h.flash_notice(_('Resource has been deleted.'))
h.redirect_to(controller='package', action='read', id=id)
c.resource_dict = get_action('resource_show')(context, {'id': resource_id})
c.resource_dict = get_action('resource_show')(
context, {'id': resource_id})
c.pkg_id = id
except NotAuthorized:
abort(401, _('Unauthorized to delete resource %s') % '')
Expand Down Expand Up @@ -1196,7 +1204,8 @@ def resource_read(self, id, resource_id):
c.package['isopen'] = False

# TODO: find a nicer way of doing this
c.datastore_api = '%s/api/action' % config.get('ckan.site_url', '').rstrip('/')
c.datastore_api = '%s/api/action' % config.get(
'ckan.site_url', '').rstrip('/')

c.related_count = c.pkg.related_count

Expand Down Expand Up @@ -1231,11 +1240,12 @@ def resource_download(self, id, resource_id, filename=None):
filepath = upload.get_path(rsc['id'])
fileapp = paste.fileapp.FileApp(filepath)
try:
status, headers, app_iter = request.call_application(fileapp)
status, headers, app_iter = request.call_application(fileapp)
except OSError:
abort(404, _('Resource data not found'))
abort(404, _('Resource data not found'))
response.headers.update(dict(headers))
content_type, content_enc = mimetypes.guess_type(rsc.get('url',''))
content_type, content_enc = mimetypes.guess_type(
rsc.get('url', ''))
response.headers['Content-Type'] = content_type
response.status = status
return app_iter
Expand All @@ -1256,7 +1266,7 @@ def follow(self, id):
package_dict['title']))
except ValidationError as e:
error_message = (e.extra_msg or e.message or e.error_summary
or e.error_dict)
or e.error_dict)
h.flash_error(error_message)
except NotAuthorized as e:
h.flash_error(e.extra_msg)
Expand All @@ -1275,7 +1285,7 @@ def unfollow(self, id):
package_dict['title']))
except ValidationError as e:
error_message = (e.extra_msg or e.message or e.error_summary
or e.error_dict)
or e.error_dict)
h.flash_error(error_message)
except (NotFound, NotAuthorized) as e:
error_message = e.extra_msg or e.message
Expand All @@ -1292,7 +1302,7 @@ def followers(self, id=None):
c.pkg_dict = get_action('package_show')(context, data_dict)
c.pkg = context['package']
c.followers = get_action('dataset_follower_list')(context,
{'id': c.pkg_dict['id']})
{'id': c.pkg_dict['id']})

c.related_count = c.pkg.related_count
except NotFound:
Expand Down Expand Up @@ -1343,19 +1353,17 @@ def groups(self, id):
redirect(h.url_for(controller='package',
action='groups', id=id))



context['is_member'] = True
users_groups = get_action('group_list_authz')(context, data_dict)

pkg_group_ids = set(group['id'] for group
in c.pkg_dict.get('groups', []))
in c.pkg_dict.get('groups', []))
user_group_ids = set(group['id'] for group
in users_groups)
in users_groups)

c.group_dropdown = [[group['id'], group['display_name']]
for group in users_groups if
group['id'] not in pkg_group_ids]
for group in users_groups if
group['id'] not in pkg_group_ids]

for group in c.pkg_dict.get('groups', []):
group['user_member'] = (group['id'] in user_group_ids)
Expand All @@ -1373,8 +1381,8 @@ def activity(self, id):
c.pkg_dict = get_action('package_show')(context, data_dict)
c.pkg = context['package']
c.package_activity_stream = get_action(
'package_activity_list_html')(context,
{'id': c.pkg_dict['id']})
'package_activity_list_html')(context,
{'id': c.pkg_dict['id']})
c.related_count = c.pkg.related_count
except NotFound:
abort(404, _('Dataset not found'))
Expand Down Expand Up @@ -1445,7 +1453,8 @@ def _parse_recline_state(self, params):
# for data api url - see http://trac.ckan.org/ticket/2639
# fix by relocating this to url attribute which is the default location
if 'dataset' in recline_state and 'elasticsearch_url' in recline_state['dataset']:
recline_state['dataset']['url'] = recline_state['dataset']['elasticsearch_url']
recline_state['dataset']['url'] = recline_state[
'dataset']['elasticsearch_url']

# Ensure only the currentView is available
# default to grid view if none specified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,3 +612,33 @@ def _resource_preview(self, data_dict):
in datapreview.direct() + datapreview.loadable()
or datapreview.get_preview_plugin(
data_dict, return_first=True))

# copy from package.py:1094
def resource_delete(self, id, resource_id):

if 'cancel' in request.params:
h.redirect_to(
controller='package', action='resource_edit', resource_id=resource_id, id=id)

context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'auth_user_obj': c.userobj}

try:
check_access('package_delete', context, {'id': id})
except NotAuthorized:
abort(401, _('Unauthorized to delete package %s') % '')

try:
if request.method == 'POST':
get_action('resource_delete')(context, {'id': resource_id})
h.flash_notice(_('Resource has been deleted.'))
h.redirect_to(controller='package', action='resources',
id=id)
c.resource_dict = get_action('resource_show')(
context, {'id': resource_id})
c.pkg_id = id
except NotAuthorized:
abort(401, _('Unauthorized to delete resource %s') % '')
except NotFound:
abort(404, _('Resource not found'))
return render('package/confirm_delete_resource.html')
Loading

0 comments on commit 3bc80b7

Please sign in to comment.