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
9edcd4d9
Commit
9edcd4d9
authored
6 years ago
by
anonymous
Browse files
Options
Downloads
Patches
Plain Diff
extend dcatde profile
parent
0e7c7fc5
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
ckanext/odsh/plugin.py
+0
-7
0 additions, 7 deletions
ckanext/odsh/plugin.py
ckanext/odsh/profiles.py
+82
-2
82 additions, 2 deletions
ckanext/odsh/profiles.py
ckanext/odsh/validation.py
+13
-6
13 additions, 6 deletions
ckanext/odsh/validation.py
setup.py
+1
-0
1 addition, 0 deletions
setup.py
with
96 additions
and
15 deletions
ckanext/odsh/plugin.py
+
0
−
7
View file @
9edcd4d9
...
...
@@ -232,12 +232,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
for
field
in
[
'
title
'
,
'
notes
'
,
'
license_id
'
]:
schema
.
update
({
field
:
[
toolkit
.
get_converter
(
'
not_empty
'
)]})
##schema.update({'group_string': [toolkit.get_converter('odsh_group_string_convert')]})
# for i, item in enumerate(schema['groups']):
#schema['id'].update({'id': schema['groups']['id']+[toolkit.get_converter('odsh_group_convert')]})
##schema['groups'].update({'id': schema['groups']['id']})
## schema.update({'groups': [toolkit.get_converter('empty')]})
for
i
,
item
in
enumerate
(
schema
[
'
tags
'
][
'
name
'
]):
if
item
==
toolkit
.
get_validator
(
'
tag_name_validator
'
):
schema
[
'
tags
'
][
'
name
'
][
i
]
=
toolkit
.
get_validator
(
...
...
@@ -256,7 +250,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
toolkit
.
get_converter
(
'
odsh_validate_temporal_start
'
),
toolkit
.
get_converter
(
'
odsh_validate_temporal_end
'
),
toolkit
.
get_converter
(
'
known_spatial_uri
'
),
toolkit
.
get_converter
(
'
licenseAttributionByText
'
)
]
})
##schema.update({'title': [toolkit.get_converter('odsh_validate_extras')]+ schema['title']})
...
...
This diff is collapsed.
Click to expand it.
ckanext/odsh/profiles.py
+
82
−
2
View file @
9edcd4d9
from
ckanext.dcatde.profiles
import
DCATdeProfile
from
ckanext.dcatde.profiles
import
DCATdeProfile
,
DCATDE
,
DCAT
,
VCARD
,
dcat_theme_prefix
from
ckanext.dcat.utils
import
resource_uri
from
ckanext.dcat.profiles
import
EuropeanDCATAPProfile
,
DCT
from
ckan.model.license
import
LicenseRegister
import
ckanext.dcatde.dataset_utils
as
ds_utils
class
ODSHDCAT
de
Profile
(
EuropeanDCATAPProfile
):
class
ODSH
European
DCAT
AP
Profile
(
EuropeanDCATAPProfile
):
def
_license
(
self
,
dataset_ref
):
if
self
.
_licenceregister_cache
is
not
None
:
...
...
@@ -28,3 +30,81 @@ class ODSHDCATdeProfile(EuropeanDCATAPProfile):
if
license_id
:
return
license_id
return
''
class
ODSHDCATdeProfile
(
DCATdeProfile
):
def
parse_dataset
(
self
,
dataset_dict
,
dataset_ref
):
"""
Transforms DCAT-AP.de-Data to CKAN-Dictionary
"""
# Simple additional fields
for
key
,
predicate
in
(
(
'
qualityProcessURI
'
,
DCATDE
.
qualityProcessURI
),
(
'
metadata_original_html
'
,
DCAT
.
landingPage
),
(
'
politicalGeocodingLevelURI
'
,
DCATDE
.
politicalGeocodingLevelURI
),
):
value
=
self
.
_object_value
(
dataset_ref
,
predicate
)
if
value
:
ds_utils
.
insert_new_extras_field
(
dataset_dict
,
key
,
value
)
# List fields
for
key
,
predicate
,
in
(
(
'
contributorID
'
,
DCATDE
.
contributorID
),
(
'
politicalGeocodingURI
'
,
DCATDE
.
politicalGeocodingURI
),
(
'
legalbasisText
'
,
DCATDE
.
legalbasisText
),
(
'
geocodingText
'
,
DCATDE
.
geocodingText
),
):
values
=
self
.
_object_value_list
(
dataset_ref
,
predicate
)
if
values
:
ds_utils
.
insert_new_extras_field
(
dataset_dict
,
key
,
json
.
dumps
(
values
))
self
.
_parse_contact
(
dataset_dict
,
dataset_ref
,
DCATDE
.
originator
,
'
originator
'
,
True
)
self
.
_parse_contact
(
dataset_dict
,
dataset_ref
,
DCATDE
.
maintainer
,
'
maintainer
'
,
False
)
self
.
_parse_contact
(
dataset_dict
,
dataset_ref
,
DCT
.
contributor
,
'
contributor
'
,
True
)
self
.
_parse_contact
(
dataset_dict
,
dataset_ref
,
DCT
.
creator
,
'
author
'
,
False
)
# dcat:contactPoint
# TODO: dcat-ap adds the values to extras.contact_... . Maybe better than maintainer?
contact
=
self
.
_object
(
dataset_ref
,
DCAT
.
contactPoint
)
self
.
_add_maintainer_field
(
dataset_dict
,
contact
,
'
url
'
,
VCARD
.
hasURL
)
contact_tel
=
self
.
_object_value
(
contact
,
VCARD
.
hasTelephone
)
if
contact_tel
:
ds_utils
.
insert
(
dataset_dict
,
'
maintainer_tel
'
,
self
.
_without_tel
(
contact_tel
),
True
)
self
.
_add_maintainer_field
(
dataset_dict
,
contact
,
'
street
'
,
VCARD
.
hasStreetAddress
)
self
.
_add_maintainer_field
(
dataset_dict
,
contact
,
'
city
'
,
VCARD
.
hasLocality
)
self
.
_add_maintainer_field
(
dataset_dict
,
contact
,
'
zip
'
,
VCARD
.
hasPostalCode
)
self
.
_add_maintainer_field
(
dataset_dict
,
contact
,
'
country
'
,
VCARD
.
hasCountryName
)
# Groups
groups
=
self
.
_get_dataset_value
(
dataset_dict
,
'
groups
'
)
if
not
groups
:
groups
=
[]
for
obj
in
self
.
g
.
objects
(
dataset_ref
,
DCAT
.
theme
):
current_theme
=
unicode
(
obj
)
if
current_theme
.
startswith
(
dcat_theme_prefix
):
group
=
current_theme
.
replace
(
dcat_theme_prefix
,
''
).
lower
()
groups
.
append
({
'
id
'
:
group
,
'
name
'
:
group
})
dataset_dict
[
'
groups
'
]
=
groups
# Add additional distribution fields
hasAttr
=
False
for
distribution
in
self
.
g
.
objects
(
dataset_ref
,
DCAT
.
distribution
):
for
resource_dict
in
dataset_dict
.
get
(
'
resources
'
,
[]):
# Match distribution in graph and distribution in ckan-dict
if
unicode
(
distribution
)
==
resource_uri
(
resource_dict
):
for
key
,
predicate
in
(
(
'
licenseAttributionByText
'
,
DCATDE
.
licenseAttributionByText
),
(
'
plannedAvailability
'
,
DCATDE
.
plannedAvailability
)
):
value
=
self
.
_object_value
(
distribution
,
predicate
)
if
value
:
ds_utils
.
insert_resource_extra
(
resource_dict
,
key
,
value
)
if
not
hasAttr
and
key
==
'
licenseAttributionByText
'
:
ds_utils
.
insert_new_extras_field
(
dataset_dict
,
key
,
value
)
hasAttr
=
True
return
dataset_dict
\ No newline at end of file
This diff is collapsed.
Click to expand it.
ckanext/odsh/validation.py
+
13
−
6
View file @
9edcd4d9
...
...
@@ -21,9 +21,11 @@ def _extract_value(data, field):
return
None
return
data
[(
key
[
0
],
key
[
1
],
'
value
'
)]
def
validate_extra_groups
(
data
):
def
validate_extra_groups
(
data
,
requireAtLeastOne
):
value
=
_extract_value
(
data
,
'
groups
'
)
if
not
value
:
if
not
requireAtLeastOne
:
return
None
return
'
at least one group needed
'
groups
=
[
g
.
strip
()
for
g
in
value
.
split
(
'
,
'
)
if
value
.
strip
()]
...
...
@@ -32,6 +34,8 @@ def validate_extra_groups(data):
data
[
k
]
=
''
# del data[k]
if
len
(
groups
)
==
0
:
if
not
requireAtLeastOne
:
return
None
return
'
at least one group needed
'
for
num
,
tag
in
zip
(
range
(
len
(
groups
)),
groups
):
...
...
@@ -40,7 +44,7 @@ def validate_extra_groups(data):
def
validate_extras
(
key
,
data
,
errors
,
context
):
pass
extra_errors
=
{}
error
=
validate_extra_groups
(
data
)
error
=
validate_extra_groups
(
data
,
False
)
if
error
:
extra_errors
[
'
groups
'
]
=
error
...
...
@@ -48,6 +52,10 @@ def validate_extras(key, data, errors, context):
if
error
:
extra_errors
[
'
issued
'
]
=
error
error
=
validate_licenseAttributionByText
(
data
)
if
error
:
extra_errors
[
'
licenseAttributionByText
'
]
=
error
if
extra_errors
:
raise
toolkit
.
Invalid
(
extra_errors
)
...
...
@@ -105,7 +113,7 @@ def validate_extra_date(key, field, data, optional=False):
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
):
def
validate_licenseAttributionByText
(
data
):
register
=
model
.
Package
.
get_license_register
()
isByLicense
=
False
for
k
in
data
:
...
...
@@ -125,9 +133,9 @@ def validate_licenseAttributionByText(key, data, errors, context):
hasAttribution
=
value
!=
''
break
if
isByLicense
and
not
hasAttribution
:
r
aise
toolkit
.
Invalid
(
'
licenseAttributionByText:odsh_licence_text_missing_error_label
'
)
r
eturn
'
empty not allowed
'
if
not
isByLicense
and
hasAttribution
:
r
aise
toolkit
.
Invalid
(
'
licenseAttributionByText:odsh_licence_text_
not
_
allowed
_error_label
'
)
r
eturn
'
text
not
allowed
for this license
'
def
known_spatial_uri
(
key
,
data
,
errors
,
context
):
value
=
_extract_value
(
data
,
'
spatial_uri
'
)
...
...
@@ -201,7 +209,6 @@ def tag_string_convert(key, data, errors, context):
def
get_validators
():
return
{
'
licenseAttributionByText
'
:
validate_licenseAttributionByText
,
'
known_spatial_uri
'
:
known_spatial_uri
,
'
odsh_validate_temporal_start
'
:
validate_extra_date_factory
(
'
temporal_start
'
),
'
odsh_validate_temporal_end
'
:
validate_extra_date_factory
(
'
temporal_end
'
,
True
),
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
0
View file @
9edcd4d9
...
...
@@ -92,6 +92,7 @@ setup(
ckan = ckan.lib.extract:extract_ckan
[ckan.rdf.profiles]
odsheuro_dcat_ap=ckanext.odsh.profiles:ODSHEuropeanDCATAPProfile
odshdcatap_de=ckanext.odsh.profiles:ODSHDCATdeProfile
'''
,
...
...
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