Skip to content
Snippets Groups Projects
Commit 4959ec28 authored by Rainer Herzog's avatar Rainer Herzog
Browse files

Fixes 'KeyError', which occurs when harvester creates package with by-Licence...

Fixes 'KeyError', which occurs when harvester creates package with by-Licence without name attribution
parent 7ab2e9dc
No related branches found
No related tags found
No related merge requests found
...@@ -122,6 +122,7 @@ def validate_extra_date_factory(field, optional=False): ...@@ -122,6 +122,7 @@ def validate_extra_date_factory(field, optional=False):
return lambda key, data, errors, context: validate_extra_date(key, field, data, optional) return lambda key, data, errors, context: validate_extra_date(key, field, data, optional)
def validate_licenseAttributionByText(key, data, errors,context): def validate_licenseAttributionByText(key, data, errors,context):
log.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ")
register = model.Package.get_license_register() register = model.Package.get_license_register()
isByLicense=False isByLicense=False
for k in data: for k in data:
...@@ -141,10 +142,24 @@ def validate_licenseAttributionByText(key, data, errors,context): ...@@ -141,10 +142,24 @@ def validate_licenseAttributionByText(key, data, errors,context):
value = data[(k[0], k[1], 'value')] value = data[(k[0], k[1], 'value')]
hasAttribution = value != '' hasAttribution = value != ''
break break
if not hasAttribution:
current_indexes = [k[1] for k in data.keys()
if len(k) > 1 and k[0] == 'extras']
new_index = max(current_indexes) + 1 if current_indexes else 0
data[('extras', new_index, 'key')] = 'licenseAttributionByText'
data[('extras', new_index, 'value')] = ''
if isByLicense and not hasAttribution: if isByLicense and not hasAttribution:
errors['licenseAttributionByText'] = 'empty not allowed' raise toolkit.Invalid(
'licenseAttributionByText:licenseAttributionByText: empty not allowed')
# errors['licenseAttributionByText'] = 'empty not allowed'
if not isByLicense and hasAttribution: if not isByLicense and hasAttribution:
errors['licenseAttributionByText'] = 'text not allowed for this license' #errors['licenseAttributionByText'] = 'text not allowed for this license'
raise toolkit.Invalid(
'licenseAttributionByText: text not allowed for this license')
def known_spatial_uri(key, data, errors, context): def known_spatial_uri(key, data, errors, context):
value = _extract_value(data, 'spatial_uri') value = _extract_value(data, 'spatial_uri')
...@@ -190,7 +205,7 @@ def known_spatial_uri(key, data, errors, context): ...@@ -190,7 +205,7 @@ def known_spatial_uri(key, data, errors, context):
data[('extras', new_index+1, 'value')] = spatial data[('extras', new_index+1, 'value')] = spatial
def tag_name_validator(value, context): def tag_name_validator(value, context):
tagname_match = re.compile('[\w \-.\:\(\)äöüÄÖÜß\´\`]*$', re.UNICODE) tagname_match = re.compile('[\w \-.\:\(\)\´\`]*$', re.UNICODE)
if not tagname_match.match(value): if not tagname_match.match(value):
raise toolkit.Invalid(_('Tag "%s" must be alphanumeric ' raise toolkit.Invalid(_('Tag "%s" must be alphanumeric '
'characters or symbols: -_.:()') % (value)) 'characters or symbols: -_.:()') % (value))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment