Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
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
Transparenzportal
ckanext-odsh
Commits
4e7db85f
Commit
4e7db85f
authored
6 years ago
by
Dennis
Browse files
Options
Downloads
Patches
Plain Diff
ODPSH-151: gets values for spatial_text and spatial for given spatial_uri
parent
f02163c8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ckanext/odsh/plugin.py
+54
-10
54 additions, 10 deletions
ckanext/odsh/plugin.py
with
54 additions
and
10 deletions
ckanext/odsh/plugin.py
+
54
−
10
View file @
4e7db85f
...
@@ -8,6 +8,9 @@ from ckanext.odsh.lib.uploader import ODSHResourceUpload
...
@@ -8,6 +8,9 @@ from ckanext.odsh.lib.uploader import ODSHResourceUpload
import
ckan.lib.helpers
as
helpers
import
ckan.lib.helpers
as
helpers
import
helpers
as
odsh_helpers
import
helpers
as
odsh_helpers
from
routes.mapper
import
SubMapper
from
routes.mapper
import
SubMapper
from
pylons
import
config
import
urllib2
import
csv
import
logging
import
logging
...
@@ -52,6 +55,7 @@ def odsh_convert_groups_string(value,context):
...
@@ -52,6 +55,7 @@ def odsh_convert_groups_string(value,context):
def
odsh_now
():
def
odsh_now
():
return
helpers
.
render_datetime
(
datetime
.
datetime
.
now
(),
"
%Y-%m-%d
"
)
return
helpers
.
render_datetime
(
datetime
.
datetime
.
now
(),
"
%Y-%m-%d
"
)
def
odsh_group_id_selected
(
selected
,
group_id
):
def
odsh_group_id_selected
(
selected
,
group_id
):
if
type
(
selected
)
is
not
list
:
if
type
(
selected
)
is
not
list
:
selected
=
[
selected
]
selected
=
[
selected
]
...
@@ -62,6 +66,38 @@ def odsh_group_id_selected(selected, group_id):
...
@@ -62,6 +66,38 @@ def odsh_group_id_selected(selected, group_id):
return
False
return
False
def
known_spatial_uri
(
key
,
data
,
errors
,
context
):
mapping_file
=
config
.
get
(
'
ckanext.odsh.spatial.mapping
'
)
try
:
mapping_file
=
urllib2
.
urlopen
(
mapping_file
)
except
Exception
:
print
(
'
Could not load spatial mapping file!
'
)
not_found
=
True
spatial_text
=
str
()
spatial
=
str
()
cr
=
csv
.
reader
(
mapping_file
,
delimiter
=
"
\t
"
)
for
row
in
cr
:
if
row
[
0
]
==
data
[
key
]:
not_found
=
False
spatial_text
=
row
[
1
]
spatial
=
row
[
2
]
break
if
not_found
:
raise
toolkit
.
Invalid
(
"
The specified URI is not known.
"
)
# Get the current extras index
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
'
)]
=
'
spatial_text
'
data
[(
'
extras
'
,
new_index
,
'
value
'
)]
=
spatial_text
data
[(
'
extras
'
,
new_index
+
1
,
'
key
'
)]
=
'
spatial
'
data
[(
'
extras
'
,
new_index
+
1
,
'
value
'
)]
=
spatial
class
OdshIcapPlugin
(
plugins
.
SingletonPlugin
):
class
OdshIcapPlugin
(
plugins
.
SingletonPlugin
):
plugins
.
implements
(
plugins
.
IUploader
,
inherit
=
True
)
plugins
.
implements
(
plugins
.
IUploader
,
inherit
=
True
)
...
@@ -170,6 +206,13 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
...
@@ -170,6 +206,13 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
def
_update_schema
(
self
,
schema
):
def
_update_schema
(
self
,
schema
):
for
field
in
self
.
_extraFields
():
for
field
in
self
.
_extraFields
():
if
field
==
'
spatial_uri
'
:
schema
.
update
({
field
:
[
toolkit
.
get_converter
(
'
not_empty
'
),
toolkit
.
get_validator
(
'
ignore_missing
'
),
toolkit
.
get_validator
(
'
known_spatial_uri
'
),
toolkit
.
get_converter
(
'
convert_to_extras
'
)]})
else
:
schema
.
update
({
field
:
[
schema
.
update
({
field
:
[
toolkit
.
get_converter
(
'
not_empty
'
),
toolkit
.
get_converter
(
'
not_empty
'
),
toolkit
.
get_validator
(
'
ignore_missing
'
),
toolkit
.
get_validator
(
'
ignore_missing
'
),
...
@@ -214,5 +257,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
...
@@ -214,5 +257,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
return
[]
return
[]
def
get_validators
(
self
):
def
get_validators
(
self
):
return
{
'
odsh_convert_groups_string
'
:
odsh_convert_groups_string
}
return
{
'
odsh_convert_groups_string
'
:
odsh_convert_groups_string
,
'
known_spatial_uri
'
:
known_spatial_uri
}
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