Return original document if present when requesting an object

This commit is contained in:
amercader 2012-11-13 12:06:36 +00:00
parent 820443d58f
commit 54ff0526bb
2 changed files with 15 additions and 4 deletions

View File

@ -252,7 +252,15 @@ class ViewController(BaseController):
# Check content type. It will probably be either XML or JSON
try:
content = re.sub('<\?xml(.*)\?>','', obj['content'])
if obj['content']:
content = obj['content']
elif 'original_document' in obj['extras']:
content = obj['extras']['original_document']
else:
abort(404,_('No content found'))
content = re.sub('<\?xml(.*)\?>','',content)
etree.fromstring(content)
response.content_type = 'application/xml'
except XMLSyntaxError:
@ -262,8 +270,8 @@ class ViewController(BaseController):
except ValueError:
pass
response.headers['Content-Length'] = len(obj['content'])
return obj['content']
response.headers['Content-Length'] = len(content)
return content
except NotFound:
abort(404,_('Harvest object not found'))
except NotAuthorized,e:

View File

@ -44,10 +44,13 @@ def harvest_object_dictize(obj, context):
out['package'] = obj.package.id
out['errors'] = []
for error in obj.errors:
out['errors'].append(error.as_dict())
out['extras'] = {}
for extra in obj.extras:
out['extras'][extra.key] = extra.value
return out
def _get_source_status(source, context):