Skip to content
Snippets Groups Projects
Commit 07b25f4b authored by anonymous's avatar anonymous
Browse files

ODPSH-368: fix validation

parent 9c8beaa1
No related branches found
No related tags found
No related merge requests found
......@@ -162,11 +162,9 @@ def odsh_extract_error(key, errors, field='extras'):
if 'key' in item:
for error in item['key']:
if error.startswith(key):
return error.replace(key+':', '')
return error
def odsh_extract_error_new(key, errors):
print('ERRORS')
print(errors)
if not errors or not ('__extras' in errors):
return None
error = errors['__extras'][0].get(key,None)
......
No preview for this file type
......@@ -171,10 +171,10 @@ msgstr "Dateien"
msgid "Spatial uri"
msgstr "Raumbezug"
msgid "odsh_spatial_uri_unknown_error_label"
msgid "spatial_uri: uri unknown"
msgstr "Der räumliche Bezug is ungültig"
msgid "odsh_spatial_uri_error_label"
msgid "spatial_uri: empty not allowed"
msgstr "Bitte geben Sie einen räumlichen Bezug an"
msgid "odsh_temporal_start_error_label"
......
......@@ -59,7 +59,7 @@ is_required=true,placeholder=_('Enter title')) }}
<!-- field license -->
{% set error_missing_attr = h.odsh_extract_error_new('licenseAttributionByText', errors) %}
{% set error_missing_attr = h.odsh_extract_error('licenseAttributionByText', errors) %}
<label class="control-label" for="field-license">
{{ _("License") }}:
<span title="{{ _("This field is required") }}" class="control-required">*</span>
......
......@@ -95,30 +95,6 @@ def validate_extra_date_new(key, field, data, optional, errors):
pass
errors[field] = 'not a valid date'
def validate_extra_date(key, field, data, optional=False):
value = _extract_value(data, field)
if not value:
if optional:
return
# Statistikamt Nord does not always provide temporal_start/end,
# but their datasets have to be accepted as they are.
if not ('id',) in data or data[('id',)][:7] != 'StaNord':
raise toolkit.Invalid(field+':odsh_'+field+'_error_label')
else:
if re.match(r'\d\d\d\d-\d\d-\d\d', value):
try:
dt=parse(value)
_set_value(data, field, dt.isoformat())
return
except ValueError:
pass
raise toolkit.Invalid(field+':odsh_'+field+'_not_date_error_label')
def validate_extra_date_factory(field, optional=False):
return lambda key, data, errors, context: validate_extra_date(key, field, data, optional)
def validate_licenseAttributionByText(key, data, errors,context):
register = model.Package.get_license_register()
isByLicense=False
......@@ -148,11 +124,9 @@ def validate_licenseAttributionByText(key, data, errors,context):
if isByLicense and not hasAttribution:
raise toolkit.Invalid(
'licenseAttributionByText:licenseAttributionByText: empty not allowed')
'licenseAttributionByText: empty not allowed')
# errors['licenseAttributionByText'] = 'empty not allowed'
if not isByLicense and hasAttribution:
#errors['licenseAttributionByText'] = 'text not allowed for this license'
raise toolkit.Invalid(
'licenseAttributionByText: text not allowed for this license')
......@@ -164,7 +138,7 @@ def known_spatial_uri(key, data, errors, context):
# some harvesters might import a polygon directly...
poly = _extract_value(data, 'spatial')
if not poly:
raise toolkit.Invalid('spatial_uri:odsh_spatial_uri_error_label')
raise toolkit.Invalid('spatial_uri: empty not allowed')
else:
return
......@@ -187,7 +161,7 @@ def known_spatial_uri(key, data, errors, context):
break
if not_found:
raise toolkit.Invalid(
'spatial_uri:odsh_spatial_uri_unknown_error_label')
'spatial_uri: uri unknown')
# Get the current extras index
current_indexes = [k[1] for k in data.keys()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment