Merge branch 'master' into 96-harvest-object-encoding-errors

This commit is contained in:
amercader 2014-05-15 15:52:13 +01:00
commit 2c6aaf5bb1
3 changed files with 33 additions and 10 deletions

View File

@ -88,11 +88,14 @@ class ViewController(BaseController):
redirect(h.url_for('{0}_admin'.format(DATASET_TYPE_NAME), id=id))
def show_object(self,id):
def show_object(self, id, ref_type='object'):
try:
context = {'model':model, 'user':c.user}
obj = p.toolkit.get_action('harvest_object_show')(context, {'id':id})
if ref_type == 'object':
obj = p.toolkit.get_action('harvest_object_show')(context, {'id': id})
elif ref_type == 'dataset':
obj = p.toolkit.get_action('harvest_object_show')(context, {'dataset_id': id})
# Check content type. It will probably be either XML or JSON
try:
@ -121,8 +124,8 @@ class ViewController(BaseController):
response.headers['Content-Length'] = len(content)
return content.encode('utf-8')
except p.toolkit.ObjectNotFound:
abort(404,_('Harvest object not found'))
except p.toolkit.ObjectNotFound, e:
abort(404,_(str(e)))
except p.toolkit.NotAuthorized:
abort(401,self.not_auth_message)
except Exception, e:

View File

@ -249,15 +249,34 @@ def harvest_job_list(context,data_dict):
@side_effect_free
def harvest_object_show(context,data_dict):
check_access('harvest_object_show',context,data_dict)
p.toolkit.check_access('harvest_object_show', context, data_dict)
id = data_dict.get('id')
attr = data_dict.get('attr',None)
obj = HarvestObject.get(id,attr=attr)
if not obj:
raise NotFound
dataset_id = data_dict.get('dataset_id')
return harvest_object_dictize(obj,context)
if id:
attr = data_dict.get('attr',None)
obj = HarvestObject.get(id,attr=attr)
elif dataset_id:
model = context['model']
pkg = model.Package.get(dataset_id)
if not pkg:
raise p.toolkit.ObjectNotFound('Dataset not found')
obj = model.Session.query(HarvestObject) \
.filter(HarvestObject.package_id == pkg.id) \
.filter(HarvestObject.current == True) \
.first()
else:
raise p.toolkit.ValidationError(
'Please provide either an "id" or a "dataset_id" parameter')
if not obj:
raise p.toolkit.ObjectNotFound('Harvest object not found')
return harvest_object_dictize(obj, context)
@side_effect_free
def harvest_object_list(context,data_dict):

View File

@ -210,6 +210,7 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm):
map.connect('harvest_job_show', '/' + DATASET_TYPE_NAME + '/{source}/job/{id}', controller=controller, action='show_job')
map.connect('harvest_object_show', '/' + DATASET_TYPE_NAME + '/object/:id', controller=controller, action='show_object')
map.connect('harvest_object_for_dataset_show', '/dataset/harvest_object/:id', controller=controller, action='show_object', ref_type='dataset')
org_controller = 'ckanext.harvest.controllers.organization:OrganizationController'
map.connect('{0}_org_list'.format(DATASET_TYPE_NAME), '/organization/' + DATASET_TYPE_NAME + '/' + '{id}', controller=org_controller, action='source_list')