Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ckanext-odsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open-Data
ckanext-odsh
Commits
7198dba3
Commit
7198dba3
authored
1 year ago
by
Thorge Petersen
Browse files
Options
Downloads
Patches
Plain Diff
Code formatting
parent
8e011e05
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ckanext/odsh/validation.py
+26
-17
26 additions, 17 deletions
ckanext/odsh/validation.py
with
26 additions
and
17 deletions
ckanext/odsh/validation.py
+
26
−
17
View file @
7198dba3
...
...
@@ -2,7 +2,9 @@
import
logging
import
csv
import
re
import
urllib.request
,
urllib
.
error
,
urllib
.
parse
import
urllib.request
import
urllib.error
import
urllib.parse
import
json
import
ckan.logic
as
logic
...
...
@@ -69,27 +71,28 @@ def validate_extra_groups(data, requireAtLeastOne, errors):
def
validate_extras
(
key
,
data
,
errors
,
context
):
log
.
debug
(
"
Validating extras
"
)
extra_errors
=
{}
isStaNord
=
(
'
id
'
,)
in
data
and
data
[(
'
id
'
,)][:
7
]
==
'
StaNord
'
harvesting
=
(
'
ignore_auth
'
in
context
)
and
(
context
[
'
ignore_auth
'
]
==
True
)
harvesting
=
(
'
ignore_auth
'
in
context
)
and
(
context
[
'
ignore_auth
'
]
==
True
)
owner_org
=
data
[(
'
owner_org
'
,)]
lenient_with
=
tk
.
config
.
get
(
'
ckanext.odsh.lenient_with
'
,
''
)
lenient_with
=
tk
.
config
.
get
(
'
ckanext.odsh.lenient_with
'
,
''
)
is_optional_temporal_start
=
toolkit
.
asbool
(
tk
.
config
.
get
(
'
ckanext.odsh.is_optional_temporal_start
'
,
False
)
)
or
(
harvesting
and
(
owner_org
in
lenient_with
)
)
)
or
(
harvesting
and
(
owner_org
in
lenient_with
))
require_at_least_one_category
=
toolkit
.
asbool
(
tk
.
config
.
get
(
'
ckanext.odsh.require_at_least_one_category
'
,
False
)
)
validate_extra_groups
(
data
=
data
,
requireAtLeastOne
=
require_at_least_one_category
,
data
=
data
,
requireAtLeastOne
=
require_at_least_one_category
,
errors
=
extra_errors
)
is_date_start_before_date_end
(
data
,
extra_errors
)
validate_extra_date_new
(
key
=
key
,
field
=
'
issued
'
,
...
...
@@ -101,7 +104,7 @@ def validate_extras(key, data, errors, context):
key
=
key
,
field
=
'
temporal_start
'
,
data
=
data
,
optional
=
is_optional_temporal_start
,
optional
=
is_optional_temporal_start
,
errors
=
extra_errors
)
validate_extra_date_new
(
...
...
@@ -115,6 +118,7 @@ def validate_extras(key, data, errors, context):
if
len
(
list
(
extra_errors
.
values
())):
raise
toolkit
.
Invalid
(
extra_errors
)
def
is_date_start_before_date_end
(
data
,
extra_errors
):
start_date
=
_extract_value
(
data
,
'
temporal_start
'
)
end_date
=
_extract_value
(
data
,
'
temporal_end
'
)
...
...
@@ -122,6 +126,7 @@ def is_date_start_before_date_end(data, extra_errors):
if
start_date
>
end_date
:
extra_errors
[
'
temporal_start
'
]
=
extra_errors
[
'
temporal_end
'
]
=
'
Please enter a valid period of time.
'
def
_set_value
(
data
,
field
,
value
):
key
=
None
for
k
in
list
(
data
.
keys
()):
...
...
@@ -209,7 +214,7 @@ def known_spatial_uri(key, data, errors, context):
poly
=
pkg
.
extras
.
get
(
'
spatial
'
,
None
)
if
(
not
poly
)
and
require_spatial_uri
:
raise
toolkit
.
Invalid
(
error_message_spatial_uri_empty
)
#if has_old_uri and require_spatial_uri:
#
if has_old_uri and require_spatial_uri:
# raise toolkit.Invalid(error_message_spatial_uri_empty)
else
:
if
poly
:
...
...
@@ -219,7 +224,8 @@ def known_spatial_uri(key, data, errors, context):
return
extension_path
=
pkg_resources
.
resource_filename
(
'
ckanext.odsh
'
,
''
)
mapping_path
=
tk
.
config
.
get
(
'
ckanext.odsh.spatial.mapping
'
,
extension_path
+
'
/resources/schleswig-holstein_geojson.csv
'
)
mapping_path
=
tk
.
config
.
get
(
'
ckanext.odsh.spatial.mapping
'
,
extension_path
+
'
/resources/schleswig-holstein_geojson.csv
'
)
not_found
=
True
spatial_text
=
str
()
...
...
@@ -265,7 +271,7 @@ def _copy_spatial_uri_temp_to_extras(data):
data
[(
'
extras
'
,
next_index
,
'
value
'
)]
=
spatial_uri
else
:
_set_value
(
data
,
'
spatial_uri
'
,
spatial_uri
)
def
next_extra_index
(
data
):
current_indexes
=
[
k
[
1
]
for
k
in
list
(
data
.
keys
())
...
...
@@ -279,7 +285,8 @@ def validate_relatedPackage(data):
try
:
get_package_dict
(
data
)
except
logic
.
NotFound
:
raise
toolkit
.
Invalid
(
"
relatedPackage: package
'
{}
'
not found
"
.
format
(
data
))
raise
toolkit
.
Invalid
(
"
relatedPackage: package
'
{}
'
not found
"
.
format
(
data
))
def
validate_formats
(
data
,
errors
):
...
...
@@ -287,7 +294,8 @@ def validate_formats(data, errors):
raise
toolkit
.
Invalid
(
'
Missing format.
'
)
if
not
any
(
data
.
upper
()
==
obj
[
'
key
'
]
for
obj
in
odsh_resource_formats
()):
raise
toolkit
.
Invalid
(
_
(
'
Only formats on the list of the EU Publications Office are allowed.
'
))
raise
toolkit
.
Invalid
(
_
(
'
Only formats on the list of the EU Publications Office are allowed.
'
))
return
data
...
...
@@ -297,7 +305,8 @@ def tag_name_validator(value, context):
"""
tagname_match
=
re
.
compile
(
r
'
^(?=.*[^\n])[^\n]*$
'
,
re
.
UNICODE
)
if
not
tagname_match
.
match
(
value
):
raise
toolkit
.
Invalid
(
_
(
'
Invalid tag:
"
%s
"
. Tags cannot contain line breaks.
'
)
%
(
value
))
raise
toolkit
.
Invalid
(
_
(
'
Invalid tag:
"
%s
"
. Tags cannot contain line breaks.
'
)
%
(
value
))
return
value
...
...
@@ -306,7 +315,7 @@ def get_validators():
'
known_spatial_uri
'
:
known_spatial_uri
,
'
odsh_validate_extras
'
:
validate_extras
,
'
validate_licenseAttributionByText
'
:
validate_licenseAttributionByText
,
'
validate_relatedPackage
'
:
validate_relatedPackage
,
'
validate_relatedPackage
'
:
validate_relatedPackage
,
'
odsh_validate_format
'
:
validate_formats
,
'
tag_name_validator
'
:
tag_name_validator
,
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment