Skip to content

Commit 7130189

Browse files
etjgiohappy
authored andcommitted
[Fixes #13777] Multilang: error on non-null fields
1 parent 6761e67 commit 7130189

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

geonode/metadata/handlers/multilang.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#########################################################################
1919

2020
import logging
21+
from copy import deepcopy
2122

2223
from django.conf import settings
2324

@@ -54,12 +55,24 @@ def init_func(field_name, subschema, jsonschema, req_lang):
5455
parent_name = subschema["geonode:multilang-group"]
5556
parent_schema = jsonschema["properties"][parent_name]
5657
subschema_lang = subschema["geonode:multilang-lang"]
57-
main = " !" if subschema_lang == multi.get_default_language() else ""
58+
59+
main_lang = subschema_lang == multi.get_default_language()
60+
5861
subschema["title"] = (
59-
f"{parent_schema.get('title', '')} [{subschema_lang.upper()}]{main}" # parent title should already be localized
62+
f"{parent_schema.get('title', '')} [{subschema_lang.upper()}]{' !' if main_lang else ''}" # parent title should already be localized
6063
)
64+
65+
if main_lang:
66+
# this is the multilang entry for the main language
67+
for ann in (
68+
"geonode:required",
69+
"description",
70+
):
71+
if ann in parent_schema:
72+
subschema[ann] = parent_schema[ann]
73+
6174
if "ui:options" in parent_schema:
62-
subschema["ui:options"] = parent_schema["ui:options"]
75+
subschema["ui:options"] = deepcopy(parent_schema["ui:options"])
6376

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

88+
if "ui:options" in parent_schema:
89+
parent_schema["ui:options"]["widget"] = "hidden"
90+
else:
91+
parent_schema["ui:widget"] = "hidden"
92+
7593
return jsonschema
7694

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

109127
def_lang_pname = multi.get_multilang_field_name(property_name, multi.get_default_language())
110128
def_lang_value = instance.get(def_lang_pname, "")
111-
instance[property_name] = def_lang_value
129+
if def_lang_value:
130+
instance[property_name] = def_lang_value
131+
else:
132+
logger.info(f"Not copying empty value to base multilang field '{property_name}'")
133+
112134
if partial:
113135
partial.add(property_name)
114136

0 commit comments

Comments
 (0)