Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions geonode/metadata/handlers/multilang.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#########################################################################

import logging
from copy import deepcopy

from django.conf import settings

Expand Down Expand Up @@ -54,12 +55,24 @@ def init_func(field_name, subschema, jsonschema, req_lang):
parent_name = subschema["geonode:multilang-group"]
parent_schema = jsonschema["properties"][parent_name]
subschema_lang = subschema["geonode:multilang-lang"]
main = " !" if subschema_lang == multi.get_default_language() else ""

main_lang = subschema_lang == multi.get_default_language()

subschema["title"] = (
f"{parent_schema.get('title', '')} [{subschema_lang.upper()}]{main}" # parent title should already be localized
f"{parent_schema.get('title', '')} [{subschema_lang.upper()}]{' !' if main_lang else ''}" # parent title should already be localized
)

if main_lang:
# this is the multilang entry for the main language
for ann in (
"geonode:required",
"description",
):
if ann in parent_schema:
subschema[ann] = parent_schema[ann]
Comment on lines +67 to +72
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This loop iterates over a tuple of string literals ('geonode:required', 'description'). To improve maintainability and avoid 'magic strings', it's good practice to define these as a constant at the module level (e.g., _ANNOTATIONS_TO_COPY). This makes the code's intent clearer and simplifies future updates if these values change or are used elsewhere.


if "ui:options" in parent_schema:
subschema["ui:options"] = parent_schema["ui:options"]
subschema["ui:options"] = deepcopy(parent_schema["ui:options"])

def update_schema(self, jsonschema, context, lang=None):
for property_name in settings.MULTILANG_FIELDS:
Expand All @@ -72,6 +85,11 @@ def update_schema(self, jsonschema, context, lang=None):
parent_schema["geonode:multilang"] = True # mark the main field as lead multilang
parent_schema["readOnly"] = True # lock the main field (we'll update its content later)

if "ui:options" in parent_schema:
parent_schema["ui:options"]["widget"] = "hidden"
else:
parent_schema["ui:widget"] = "hidden"

return jsonschema

def _create_ml_subschema(self, parent_name, lang):
Expand Down Expand Up @@ -108,7 +126,11 @@ def pre_deserialization(self, resource, jsonschema: dict, instance: dict, partia

def_lang_pname = multi.get_multilang_field_name(property_name, multi.get_default_language())
def_lang_value = instance.get(def_lang_pname, "")
instance[property_name] = def_lang_value
if def_lang_value:
instance[property_name] = def_lang_value
else:
logger.info(f"Not copying empty value to base multilang field '{property_name}'")

if partial:
partial.add(property_name)

Expand Down
Loading