Commit cc828322 authored by Marko Kuder's avatar Marko Kuder
Browse files

handle cases where resource archival attribute is string instead of dict

parent 28361089
......@@ -64,7 +64,7 @@ def is_resource_broken(resource):
archival = resource.get('archiver')
if not archival:
return None # don't know
if isinstance(archival, basestring):
if is_string(archival):
log.warn("Resource " + resource.get('id') + " has an incorrect string archival content!")
return True
#archival = json.loads(archival.replace("\'", "\""))
......@@ -643,7 +643,7 @@ def render_qa_info_for_resource(resource_dict):
return u'Ocenjevanje odprtosti ni nameščeno'
# Archiver holds details of whether the link is broken
archival = resource_dict.get('archiver')
reason_list = [archival['status'], archival['reason']] if archival else []
reason_list = [archival['status'], archival['reason']] if (archival and not is_string(archival)) else []
# QA holds details of openness score
qa = resource_dict.get('qa')
if not (qa or archival):
......@@ -2771,7 +2771,7 @@ def human_size(num):
return '{:.1f} YB'
def get_resource_size_formatted(resource_dict):
if resource_dict and resource_dict.get('archiver') and resource_dict['archiver'].get('size'):
if resource_dict and resource_dict.get('archiver') and not is_string(resource_dict['archiver']) and resource_dict['archiver'].get('size'):
try:
size = int(resource_dict['archiver'].get('size'))
except ValueError:
......
......@@ -230,8 +230,8 @@ class SearchIndexing(object):
def add_field__openness(cls, pkg_dict):
'''Add the openness score (stars) to the search index'''
archival = pkg_dict.get('archiver')
if not archival:
log.warning('No Archiver info for package %s', pkg_dict['name'])
if not archival or dgu_helpers.is_string(archival):
log.warning('No Archiver info for package %s, is string: %s', pkg_dict['name'], str(dgu_helpers.is_string(archival)))
return
qa = pkg_dict.get('qa')
if not qa:
......
......@@ -314,7 +314,7 @@
{% with %}
{% set is_location_data = h.is_location_data(c.pkg_dict) %}
{% set is_harvest_metadata = res.get('gemini',False) or res.get('is_harvest_metadata',False) %} {# i.e. the gemini metadata links, shown as resources #}
{% set archiver_format = res.get('archiver', {})['format'] or '' %}
{% set archiver_format = '' if h.is_string(res.get('archiver', {})) else res.get('archiver', {})['format'] or '' %}
{% set resource_size = h.get_resource_size_formatted(res) %}
{% set is_download = not is_location_data and res.get('resource_type') != 'api' and (res.format or '').upper() not in non_download_formats and archiver_format not in non_download_formats %}
{% set is_html = not is_download and (res.format and res.format.upper() == 'HTML' or archiver_format.upper() == 'HTML') %}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment