Skip to content

Commit 83f7667

Browse files
authored
[Fixes #118] Port rndt to GeoNode 5 (#121)
* #118 initial porting to 5.0 * #118 GeoNode5: parser/storer cleanup * #118 GeoNode5: model and migrations * #118 GeoNode5: parser * #120 update fileIdentifier on group change * Renaming thesauri to avoid dots * Fix setting constraints_other in base resource * Fix setting constraints_other in base resource
1 parent 34716c5 commit 83f7667

34 files changed

+540
-872
lines changed

rndt/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = (4, 4, "1dev0")
1+
VERSION = (5, 0, "0dev0")
22
__version__ = ".".join([str(i) for i in VERSION])
33
__author__ = "geosolutions-it"
44
__email__ = "info@geosolutionsgroup.com"

rndt/apps.py

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ class RndtConfig(AppConfig):
88
name = "rndt"
99

1010
def ready(self):
11+
super(RndtConfig, self).ready()
12+
1113
"""Finalize setup"""
1214
run_setup_hooks()
13-
super(RndtConfig, self).ready()
15+
16+
from rndt.metadata.handler import init as metadata_init
17+
metadata_init()
18+
1419

1520

1621
def run_setup_hooks(*args, **kwargs):
@@ -22,37 +27,19 @@ def run_setup_hooks(*args, **kwargs):
2227

2328
settings.TEMPLATES[0]["DIRS"].insert(0, os.path.join(LOCAL_ROOT, "templates"))
2429

25-
settings.TEMPLATES[0]["OPTIONS"]["context_processors"].append("rndt.context_processors.rndt_tags")
30+
# settings.TEMPLATES[0]["OPTIONS"]["context_processors"].append("rndt.context_processors.rndt_tags")
2631

27-
rndt_exclude_fields = ["constraints_other", "restriction_code_type"]
28-
if hasattr(settings, "ADVANCED_EDIT_EXCLUDE_FIELD"):
29-
settings.ADVANCED_EDIT_EXCLUDE_FIELD += rndt_exclude_fields
30-
else:
31-
setattr(settings, "ADVANCED_EDIT_EXCLUDE_FIELD", rndt_exclude_fields)
32+
RNDT_PARSER_FUNCTION = "rndt.metadata.parser.rndt_parser"
3233

33-
rndt_parsers = ["__DEFAULT__", "rndt.layers.metadata.rndt_parser"]
34+
rndt_parsers = ["__DEFAULT__", RNDT_PARSER_FUNCTION]
3435
if not getattr(settings, "METADATA_PARSERS", None):
3536
setattr(settings, "METADATA_PARSERS", rndt_parsers)
36-
elif "rndt.layers.metadata.rndt_parser" not in settings.METADATA_PARSERS:
37-
settings.METADATA_PARSERS.extend(["rndt.layers.metadata.rndt_parser"])
37+
elif RNDT_PARSER_FUNCTION not in settings.METADATA_PARSERS:
38+
settings.METADATA_PARSERS.extend([RNDT_PARSER_FUNCTION])
3839
setattr(settings, "METADATA_PARSERS", settings.METADATA_PARSERS)
3940

40-
rndt_storers = ["rndt.layers.storer.rndt_storer"]
41-
if not getattr(settings, "METADATA_STORERS", None):
42-
setattr(settings, "METADATA_STORERS", rndt_storers)
43-
elif rndt_storers[0] not in settings.METADATA_STORERS:
44-
settings.METADATA_STORERS.extend(rndt_storers)
45-
setattr(settings, "METADATA_STORERS", settings.METADATA_STORERS)
46-
47-
rndt_required_fields = ["id_access_contraints", "id_use_constraints", "id_resolution", "id_accuracy"]
48-
if not hasattr(settings, "UI_DEFAULT_MANDATORY_FIELDS"):
49-
setattr(settings, "UI_DEFAULT_MANDATORY_FIELDS", rndt_required_fields)
50-
else:
51-
settings.UI_DEFAULT_MANDATORY_FIELDS.extend(rndt_required_fields)
52-
setattr(settings, "UI_DEFAULT_MANDATORY_FIELDS", settings.UI_DEFAULT_MANDATORY_FIELDS)
53-
5441
urlpatterns += [
5542
re_path(r"^", include("rndt.api.urls")),
5643
re_path(r"^catalogue/", include("rndt.catalogue.urls")),
57-
re_path(r"^datasets/", include("rndt.layers.urls")),
44+
# re_path(r"^datasets/", include("rndt.layers.urls")),
5845
]

rndt/context_processors.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

rndt/layers/forms.py

Lines changed: 0 additions & 63 deletions
This file was deleted.

rndt/layers/storer.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

rndt/layers/urls.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

rndt/layers/views.py

Lines changed: 0 additions & 83 deletions
This file was deleted.

rndt/locale/it/LC_MESSAGES/django.po

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,9 @@
22
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
33
# This file is distributed under the same license as the PACKAGE package.
44

5-
msgid "Data Constraints"
6-
msgstr "Vincoli sui dati"
7-
8-
msgid "Access constraints"
9-
msgstr "Vincoli di accesso"
10-
11-
msgid "Use constraints"
12-
msgstr "Vincoli di fruibilità"
13-
14-
msgid "Free text"
15-
msgstr "Testo Libero"
16-
17-
msgid "Resolution"
18-
msgstr "Risoluzione"
19-
205
msgid "Public Administration"
216
msgstr "Pubblica Amministrazione"
227

238
msgid "Additional info"
249
msgstr "Informazioni aggiuntive"
2510

26-
msgid "Positional Accuracy"
27-
msgstr "Accuratezza posizionale"

rndt/metadata/handler.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import json
2+
import logging
3+
import os
4+
5+
from geonode.base.models import ResourceBase
6+
from geonode.metadata.handlers.abstract import MetadataHandler
7+
from geonode.metadata.handlers.sparse import sparse_field_registry
8+
from geonode.metadata.manager import metadata_manager
9+
10+
logger = logging.getLogger(__name__)
11+
12+
CONTEXT_ID = "RNDT"
13+
14+
def load_schema_file():
15+
with open(os.path.join(os.path.dirname(__file__), "schemas", "rndt.json")) as f:
16+
schema_file = json.load(f)
17+
18+
return schema_file
19+
20+
21+
class RNDTSchemaHandler(MetadataHandler):
22+
23+
def __init__(self) -> None:
24+
super().__init__()
25+
self.otherRestrictions = None # lazy init
26+
27+
def update_schema(self, jsonschema, context, lang=None):
28+
29+
schema_file = load_schema_file()
30+
31+
# building the full schema using the external file
32+
for property_name, subschema in schema_file.items():
33+
self._localize_subschema_labels(context, subschema, lang, property_name)
34+
35+
if "geonode:handler" not in subschema:
36+
subschema["geonode:handler"] = "rndt"
37+
else:
38+
handler = subschema["geonode:handler"]
39+
if handler == "sparse":
40+
# fields has already been added to the sparsefield register
41+
continue
42+
43+
self._add_subschema(jsonschema, property_name, subschema)
44+
45+
# rndt_required_fields = ["id_access_contraints", "id_use_constraints", "id_resolution", "id_accuracy"]
46+
47+
# === remove unused fields
48+
exclude_fields = ["constraints_other", "restriction_code_type"]
49+
for field in exclude_fields:
50+
logger.debug(f"Removing field {field}")
51+
del jsonschema["properties"][field]
52+
53+
return jsonschema
54+
55+
def get_jsonschema_instance(
56+
self, resource: ResourceBase, field_name: str, context: dict, errors: dict, lang: str = None
57+
):
58+
raise Exception(f"Unhandled field {field_name}")
59+
60+
def update_resource(
61+
self, resource, field_name, json_instance, context, errors, **kwargs
62+
):
63+
raise Exception(f"Unhandled field {field_name}")
64+
65+
def pre_save(
66+
self, resource: ResourceBase, json_instance: dict, context: dict, errors: dict, **kwargs
67+
):
68+
# RNDT requires restriction_code_type to be "otherRestrictions"
69+
if not self.otherRestrictions:
70+
from geonode.base.models import RestrictionCodeType
71+
# see https://github.com/GeoNode/geonode/issues/12745
72+
self.otherRestrictions = RestrictionCodeType.objects.filter(identifier="otherRestrictions").first() or \
73+
RestrictionCodeType.objects.filter(description="otherRestrictions").first()
74+
75+
resource.restriction_code_type = self.otherRestrictions
76+
context.setdefault("base", {})["restriction_code_type"] = self.otherRestrictions
77+
78+
# Setting the ResourceBase field either as URL or freetext
79+
json_instance.get("rndt_ConditionsApplyingToAccessAndUse", {})
80+
if json_instance.get("inspire_url", False):
81+
val = json_instance.get("url", None)
82+
else:
83+
val = json_instance.get("freetext", None)
84+
val = val or "Missing value"
85+
resource.constraints_other = val
86+
context.setdefault("base", {})["constraints_other"] = val
87+
88+
def init():
89+
logger.info("Init RNDTSchema hooks")
90+
91+
# == Add json schema
92+
93+
# register sparse fields:
94+
for property_name, subschema in load_schema_file().items():
95+
if subschema.get("geonode:handler", None) == "sparse":
96+
sparse_field_registry.register(property_name, subschema)
97+
98+
metadata_manager.add_handler("rndt", RNDTSchemaHandler)
99+
100+
# TODO: check for mandatory thesauri

0 commit comments

Comments
 (0)