Skip to content

Commit

Permalink
[#56] Don't mess with field keys if using scheming
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Jun 6, 2024
1 parent 1790404 commit 73523d6
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions ckanext/dcat/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@
I18N_DIR = os.path.join(HERE, u"../i18n")


def _get_dataset_schema(dataset_type="dataset"):
schema = None
try:
schema_show = p.toolkit.get_action("scheming_dataset_schema_show")
try:
schema = schema_show({}, {"type": dataset_type})
except p.toolkit.ObjectNotFound:
pass
except KeyError:
pass
return schema


class DCATPlugin(p.SingletonPlugin, DefaultTranslation):

p.implements(p.IConfigurer, inherit=True)
Expand Down Expand Up @@ -120,8 +133,15 @@ def before_index(self, dataset_dict):
# CKAN >= 2.10 hooks
def after_dataset_show(self, context, data_dict):

schema = _get_dataset_schema(data_dict["type"])
# check if config is enabled to translate keys (default: True)
if not p.toolkit.asbool(config.get(TRANSLATE_KEYS_CONFIG, True)):
# skip if scheming is enabled, as this will be handled there
translate_keys = (
p.toolkit.asbool(config.get(TRANSLATE_KEYS_CONFIG, True))
and not schema
)

if not translate_keys:
return data_dict

if context.get('for_view'):
Expand All @@ -143,16 +163,7 @@ def set_titles(object_dict):
return data_dict

def before_dataset_index(self, dataset_dict):
schema = None
try:
schema_show = p.toolkit.get_action("scheming_dataset_schema_show")
try:
schema = schema_show({}, {"type": dataset_dict["type"]})
except p.toolkit.ObjectNotFound:
pass
except KeyError:
pass

schema = _get_dataset_schema(dataset_dict["type"])
spatial = None
if schema:
for field in schema['dataset_fields']:
Expand Down

0 comments on commit 73523d6

Please sign in to comment.