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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open-Data
ckanext-odsh
Commits
31e43061
Commit
31e43061
authored
6 years ago
by
anonymous
Browse files
Options
Downloads
Patches
Plain Diff
allows some more special characters for tags
parent
bec62e3f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
ckanext/odsh/harvesters/statistikamtnordharvester.py
+8
-1
8 additions, 1 deletion
ckanext/odsh/harvesters/statistikamtnordharvester.py
ckanext/odsh/plugin.py
+43
-3
43 additions, 3 deletions
ckanext/odsh/plugin.py
with
51 additions
and
4 deletions
ckanext/odsh/harvesters/statistikamtnordharvester.py
+
8
−
1
View file @
31e43061
...
...
@@ -133,6 +133,13 @@ class StatistikamtNordHarvester(ODSHBaseHarvester):
schema
.
update
({
'
temporal_end
'
:
[
toolkit
.
get_validator
(
'
ignore_empty
'
),
toolkit
.
get_converter
(
'
convert_to_extras
'
)]})
schema
.
update
({
'
issued
'
:
[
toolkit
.
get_validator
(
'
ignore_missing
'
),
toolkit
.
get_validator
(
'
ignore_empty
'
),
toolkit
.
get_converter
(
'
convert_to_extras
'
)]})
for
i
,
item
in
enumerate
(
schema
[
'
tags
'
][
'
name
'
]):
if
item
==
toolkit
.
get_validator
(
'
tag_name_validator
'
):
schema
[
'
tags
'
][
'
name
'
][
i
]
=
toolkit
.
get_validator
(
'
odsh_tag_name_validator
'
)
def
map_fields
(
self
,
context
,
harvest_object
):
values
=
json
.
loads
(
harvest_object
.
content
)
...
...
@@ -163,7 +170,7 @@ class StatistikamtNordHarvester(ODSHBaseHarvester):
package_dict
.
update
({
'
temporal_end
'
:
values
[
'
ZeitraumBis
'
]})
package_dict
.
update
({
'
spatial_uri
'
:
'
http://dcat-ap.de/def/politicalGeocoding/stateKey/01
'
})
# issued sollte noch geliefert werden!
package_dict
.
update
({
'
issued
'
:
datetime
.
datetime
.
now
()})
#
package_dict.update({'issued': datetime.datetime.now()})
self
.
add_ressources
(
package_dict
,
values
)
self
.
add_tags
(
package_dict
,
values
)
...
...
This diff is collapsed.
Click to expand it.
ckanext/odsh/plugin.py
+
43
−
3
View file @
31e43061
...
...
@@ -3,14 +3,18 @@ import ckan.plugins as plugins
import
ckan.plugins.toolkit
as
toolkit
from
ckan.lib.plugins
import
DefaultTranslation
from
ckan.lib.plugins
import
DefaultDatasetForm
from
ckan.logic.validators
import
tag_string_convert
from
ckan.common
import
OrderedDict
from
ckanext.odsh.lib.uploader
import
ODSHResourceUpload
import
ckan.lib.helpers
as
helpers
import
helpers
as
odsh_helpers
from
itertools
import
count
from
routes.mapper
import
SubMapper
from
pylons
import
config
import
urllib2
import
csv
import
re
import
logging
...
...
@@ -98,6 +102,34 @@ def known_spatial_uri(key, data, errors, context):
data
[(
'
extras
'
,
new_index
+
1
,
'
key
'
)]
=
'
spatial
'
data
[(
'
extras
'
,
new_index
+
1
,
'
value
'
)]
=
spatial
def
odsh_tag_name_validator
(
value
,
context
):
tagname_match
=
re
.
compile
(
'
[\w \-.\:\(\)]*$
'
,
re
.
UNICODE
)
if
not
tagname_match
.
match
(
value
):
raise
toolkit
.
Invalid
(
_
(
'
Tag
"
%s
"
must be alphanumeric
'
'
characters or symbols: -_.:()
'
)
%
(
value
))
return
value
def
odsh_tag_string_convert
(
key
,
data
,
errors
,
context
):
'''
Takes a list of tags that is a comma-separated string (in data[key])
and parses tag names. These are added to the data dict, enumerated. They
are also validated.
'''
if
isinstance
(
data
[
key
],
basestring
):
tags
=
[
tag
.
strip
()
\
for
tag
in
data
[
key
].
split
(
'
,
'
)
\
if
tag
.
strip
()]
else
:
tags
=
data
[
key
]
current_index
=
max
(
[
int
(
k
[
1
])
for
k
in
data
.
keys
()
if
len
(
k
)
==
3
and
k
[
0
]
==
'
tags
'
]
+
[
-
1
]
)
for
num
,
tag
in
zip
(
count
(
current_index
+
1
),
tags
):
data
[(
'
tags
'
,
num
,
'
name
'
)]
=
tag
for
tag
in
tags
:
toolkit
.
get_validator
(
'
tag_length_validator
'
)(
tag
,
context
)
odsh_tag_name_validator
(
tag
,
context
)
class
OdshIcapPlugin
(
plugins
.
SingletonPlugin
):
plugins
.
implements
(
plugins
.
IUploader
,
inherit
=
True
)
...
...
@@ -224,6 +256,13 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
for
field
in
self
.
_fields
():
schema
.
update
({
field
:
[
toolkit
.
get_converter
(
'
not_empty
'
)]})
for
i
,
item
in
enumerate
(
schema
[
'
tags
'
][
'
name
'
]):
if
item
==
toolkit
.
get_validator
(
'
tag_name_validator
'
):
schema
[
'
tags
'
][
'
name
'
][
i
]
=
toolkit
.
get_validator
(
'
odsh_tag_name_validator
'
)
for
i
,
item
in
enumerate
(
schema
[
'
tag_string
'
]):
if
item
==
tag_string_convert
:
schema
[
'
tag_string
'
][
i
]
=
odsh_tag_string_convert
schema
[
'
resources
'
].
update
({
'
url
'
:
[
toolkit
.
get_converter
(
'
not_empty
'
)
]
})
...
...
@@ -258,5 +297,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
def
get_validators
(
self
):
return
{
'
odsh_convert_groups_string
'
:
odsh_convert_groups_string
,
'
known_spatial_uri
'
:
known_spatial_uri
}
'
known_spatial_uri
'
:
known_spatial_uri
,
'
odsh_tag_name_validator
'
:
odsh_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