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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Transparenzportal
ckanext-odsh
Commits
94c5163e
Commit
94c5163e
authored
Apr 14, 2020
by
Benjamin Becker
Browse files
Options
Downloads
Patches
Plain Diff
refactoring: extracts method get_collection_info from get_collection
preparation for use in controller.py
parent
d7318f56
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/collection/helpers.py
+34
-26
34 additions, 26 deletions
ckanext/odsh/collection/helpers.py
with
34 additions
and
26 deletions
ckanext/odsh/collection/helpers.py
+
34
−
26
View file @
94c5163e
...
...
@@ -10,14 +10,18 @@ from profilehooks import timecall, profile
def
get_collection
(
dataset_dict
):
collection_id
=
get_collection_id
(
dataset_dict
)
if
collection_id
:
return
get_collection_info
(
collection_id
,
dataset_dict
)
return
None
def
get_collection_info
(
collection_id
,
dataset_dict
=
None
):
collection_dict
=
get_package_dict
(
collection_id
)
dataset_names
=
get_dataset_names
(
collection_dict
)
datasets_in_collection
=
get_datasets_from_solr
(
dataset_names
)
collection_info
=
gather_collection_info
(
collection_dict
,
dataset_dict
,
datasets_in_collection
)
collection_info
=
gather_collection_info
(
collection_dict
,
datasets_in_collection
,
dataset_dict
)
return
collection_info
return
None
@timecall
(
immediate
=
True
)
def
get_collection_id
(
dataset_dict
):
...
...
@@ -67,23 +71,9 @@ def get_datasets_from_solr(dataset_names):
return
datasets_found
def
gather_collection_info
(
collection_dict
,
dataset
_dict
,
datasets_in_collecti
on
):
def
gather_collection_info
(
collection_dict
,
dataset
s_in_collection
,
dataset_dict
=
N
on
e
):
url_from_id
=
lambda
id
:
helpers
.
url_for
(
controller
=
'
package
'
,
action
=
'
read
'
,
id
=
id
)
name_current_dataset
=
dataset_dict
.
get
(
'
name
'
)
dataset_names
=
[
d
.
get
(
'
name
'
)
for
d
in
datasets_in_collection
]
def
get_predecessor
():
id_current
=
dataset_names
.
index
(
name_current_dataset
)
if
id_current
>
0
:
return
dataset_names
[
id_current
-
1
]
return
None
def
get_successor
():
id_current
=
dataset_names
.
index
(
name_current_dataset
)
if
id_current
<
len
(
dataset_names
)
-
1
:
return
dataset_names
[
id_current
+
1
]
return
None
name_first_dataset
=
datasets_in_collection
[
0
].
get
(
'
name
'
)
url_first_dataset
=
url_from_id
(
name_first_dataset
)
...
...
@@ -98,11 +88,29 @@ def gather_collection_info(collection_dict, dataset_dict, datasets_in_collection
id
=
name_collection
)
if
dataset_dict
:
name_current_dataset
=
dataset_dict
.
get
(
'
name
'
)
dataset_names
=
[
d
.
get
(
'
name
'
)
for
d
in
datasets_in_collection
]
def
get_predecessor
():
id_current
=
dataset_names
.
index
(
name_current_dataset
)
if
id_current
and
id_current
>
0
:
return
dataset_names
[
id_current
-
1
]
return
None
def
get_successor
():
id_current
=
dataset_names
.
index
(
name_current_dataset
)
if
id_current
and
id_current
<
len
(
dataset_names
)
-
1
:
return
dataset_names
[
id_current
+
1
]
return
None
name_predecessor
=
get_predecessor
()
url_predecessor
=
url_from_id
(
name_predecessor
)
if
name_predecessor
else
None
name_successor
=
get_successor
()
url_successor
=
url_from_id
(
name_successor
)
if
name_successor
else
None
else
:
url_predecessor
=
url_successor
=
None
return
{
'
title
'
:
collection_dict
.
get
(
'
title
'
),
...
...
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