Skip to content

Commit

Permalink
chore: decommission unused endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
brunopacheco1 committed Apr 16, 2024
1 parent 1548207 commit 69455ec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 118 deletions.
124 changes: 8 additions & 116 deletions ckanext/gdi_userportal/logic/action/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,134 +13,26 @@
from ckanext.gdi_userportal.logic.action.translation_utils import (
collect_values_to_translate,
get_translations,
replace_package,
replace_search_facets,
)
from ckanext.gdi_userportal.logic.action.translation_utils import replace_package, replace_search_facets
from typing import Dict

log = logging.getLogger(__name__)


@toolkit.side_effect_free
def scheming_package_show(context, data_dict):
"""
Function made to be called on Dataplatform Portal. It provides an alternative for package_show,
returning information in a format that is fitted to what the Dataplatform Portal needs
:param context
:param data_dict
:param include_labels: If set to True will replace the value of the field,
with a dictionary with 2 keys 'value' and 'labels' a dictionary which
contains all the labels for that value in all languages.(default: `False`)
:type include_labels: bool
"""

pkg_dict = toolkit.get_action("package_show")(context, data_dict)
schema = toolkit.get_action("scheming_dataset_schema_show")(context, data_dict)
dataset_fields = schema["dataset_fields"]

new_pkg_dict = {}
fields_not_in_schema_that_should_be_visible = [
{
"name": "metadata_created",
"label": {
"en": "Metadata Created",
"nl": "Gecreëerd",
"sv": "Metadata skapad",
},
},
{
"name": "metadata_modified",
"label": {
"en": "Metadata Modified",
"nl": "Laatst gewijzigd",
"sv": "Metadata modifierad",
},
},
{
"name": "organization",
"label": {"en": "Organization", "nl": "Organisatie", "sv": "Organization"},
},
{
"name": "license_title",
"label": {"en": "License", "nl": "Licentie", "sv": "Licens"},
},
]
fields_in_schema_that_should_not_be_visible = ["owner_org"]

for field in dataset_fields:
field_name = field["field_name"]
try:
value = pkg_dict[field_name]
except KeyError:
continue

# Add Visibility to be showed in the Portal
# Default visibility is True
# If display_snippet = hidden.html or null OR part of the exceptions list then visible false

if (
"display_snippet" in field
and field["display_snippet"] in [None, "hidden.html"]
) or field_name in fields_in_schema_that_should_not_be_visible:
visible = False
else:
visible = True

field_label = field.get("label", None)
choices = toolkit.h.scheming_field_choices(field)

if choices is None:
new_pkg_dict[field_name] = {
"value": value,
"value_label": None,
"field_label": field_label,
"visible": visible,
}
del pkg_dict[field_name]
continue

for choice in choices:
if choice["value"] == value:
new_pkg_dict[field_name] = {
"value": value,
"value_label": choice["label"],
"field_label": field_label,
"visible": visible,
}
del pkg_dict[field_name]
break

for fieldname in pkg_dict:
field_label = None
visible = any(
fieldname in field_dict["name"]
for field_dict in fields_not_in_schema_that_should_be_visible
)
if visible:
for field_dict in fields_not_in_schema_that_should_be_visible:
if field_dict["name"] == fieldname:
field_label = field_dict["label"]

default_field_dict = {
"value": pkg_dict[fieldname],
"value_label": None,
"field_label": field_label,
"visible": visible,
}
new_pkg_dict[fieldname] = default_field_dict

return new_pkg_dict


@toolkit.side_effect_free
def enhanced_package_search(context, data_dict) -> Dict:
result = toolkit.get_action("package_search")(context, data_dict)
values_to_translate = collect_values_to_translate(result)
translations = get_translations(values_to_translate)
result["results"] = [replace_package(package, translations) for package in result["results"]]
result["results"] = [
replace_package(package, translations) for package in result["results"]
]
if "search_facets" in result.keys():
result["search_facets"] = replace_search_facets(result["search_facets"], translations)
result["search_facets"] = replace_search_facets(
result["search_facets"], translations
)
return result


Expand Down
2 changes: 0 additions & 2 deletions ckanext/gdi_userportal/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
from ckanext.gdi_userportal.logic.action.get import (
scheming_package_show,
enhanced_package_search,
enhanced_package_show,
)
Expand Down Expand Up @@ -73,7 +72,6 @@ def get_auth_functions(self):

def get_actions(self):
return {
"scheming_package_show": scheming_package_show,
"enhanced_package_search": enhanced_package_search,
"enhanced_package_show": enhanced_package_show,
}
Expand Down

0 comments on commit 69455ec

Please sign in to comment.