Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion rndt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = (4, 4, "1dev0")
VERSION = (5, 0, "0dev0")
__version__ = ".".join([str(i) for i in VERSION])
__author__ = "geosolutions-it"
__email__ = "info@geosolutionsgroup.com"
Expand Down
37 changes: 12 additions & 25 deletions rndt/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ class RndtConfig(AppConfig):
name = "rndt"

def ready(self):
super(RndtConfig, self).ready()

"""Finalize setup"""
run_setup_hooks()
super(RndtConfig, self).ready()

from rndt.metadata.handler import init as metadata_init
metadata_init()



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

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

settings.TEMPLATES[0]["OPTIONS"]["context_processors"].append("rndt.context_processors.rndt_tags")
# settings.TEMPLATES[0]["OPTIONS"]["context_processors"].append("rndt.context_processors.rndt_tags")

rndt_exclude_fields = ["constraints_other", "restriction_code_type"]
if hasattr(settings, "ADVANCED_EDIT_EXCLUDE_FIELD"):
settings.ADVANCED_EDIT_EXCLUDE_FIELD += rndt_exclude_fields
else:
setattr(settings, "ADVANCED_EDIT_EXCLUDE_FIELD", rndt_exclude_fields)
RNDT_PARSER_FUNCTION = "rndt.metadata.parser.rndt_parser"

rndt_parsers = ["__DEFAULT__", "rndt.layers.metadata.rndt_parser"]
rndt_parsers = ["__DEFAULT__", RNDT_PARSER_FUNCTION]
if not getattr(settings, "METADATA_PARSERS", None):
setattr(settings, "METADATA_PARSERS", rndt_parsers)
elif "rndt.layers.metadata.rndt_parser" not in settings.METADATA_PARSERS:
settings.METADATA_PARSERS.extend(["rndt.layers.metadata.rndt_parser"])
elif RNDT_PARSER_FUNCTION not in settings.METADATA_PARSERS:
settings.METADATA_PARSERS.extend([RNDT_PARSER_FUNCTION])
setattr(settings, "METADATA_PARSERS", settings.METADATA_PARSERS)

rndt_storers = ["rndt.layers.storer.rndt_storer"]
if not getattr(settings, "METADATA_STORERS", None):
setattr(settings, "METADATA_STORERS", rndt_storers)
elif rndt_storers[0] not in settings.METADATA_STORERS:
settings.METADATA_STORERS.extend(rndt_storers)
setattr(settings, "METADATA_STORERS", settings.METADATA_STORERS)

rndt_required_fields = ["id_access_contraints", "id_use_constraints", "id_resolution", "id_accuracy"]
if not hasattr(settings, "UI_DEFAULT_MANDATORY_FIELDS"):
setattr(settings, "UI_DEFAULT_MANDATORY_FIELDS", rndt_required_fields)
else:
settings.UI_DEFAULT_MANDATORY_FIELDS.extend(rndt_required_fields)
setattr(settings, "UI_DEFAULT_MANDATORY_FIELDS", settings.UI_DEFAULT_MANDATORY_FIELDS)

urlpatterns += [
re_path(r"^", include("rndt.api.urls")),
re_path(r"^catalogue/", include("rndt.catalogue.urls")),
re_path(r"^datasets/", include("rndt.layers.urls")),
# re_path(r"^datasets/", include("rndt.layers.urls")),
]
5 changes: 0 additions & 5 deletions rndt/context_processors.py

This file was deleted.

63 changes: 0 additions & 63 deletions rndt/layers/forms.py

This file was deleted.

25 changes: 0 additions & 25 deletions rndt/layers/storer.py

This file was deleted.

5 changes: 0 additions & 5 deletions rndt/layers/urls.py

This file was deleted.

83 changes: 0 additions & 83 deletions rndt/layers/views.py

This file was deleted.

17 changes: 0 additions & 17 deletions rndt/locale/it/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,9 @@
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.

msgid "Data Constraints"
msgstr "Vincoli sui dati"

msgid "Access constraints"
msgstr "Vincoli di accesso"

msgid "Use constraints"
msgstr "Vincoli di fruibilità"

msgid "Free text"
msgstr "Testo Libero"

msgid "Resolution"
msgstr "Risoluzione"

msgid "Public Administration"
msgstr "Pubblica Amministrazione"

msgid "Additional info"
msgstr "Informazioni aggiuntive"

msgid "Positional Accuracy"
msgstr "Accuratezza posizionale"
File renamed without changes.
100 changes: 100 additions & 0 deletions rndt/metadata/handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import json
import logging
import os

from geonode.base.models import ResourceBase
from geonode.metadata.handlers.abstract import MetadataHandler
from geonode.metadata.handlers.sparse import sparse_field_registry
from geonode.metadata.manager import metadata_manager

logger = logging.getLogger(__name__)

CONTEXT_ID = "RNDT"

def load_schema_file():
with open(os.path.join(os.path.dirname(__file__), "schemas", "rndt.json")) as f:
schema_file = json.load(f)

return schema_file


class RNDTSchemaHandler(MetadataHandler):

def __init__(self) -> None:
super().__init__()
self.otherRestrictions = None # lazy init

def update_schema(self, jsonschema, context, lang=None):

schema_file = load_schema_file()

# building the full schema using the external file
for property_name, subschema in schema_file.items():
self._localize_subschema_labels(context, subschema, lang, property_name)

if "geonode:handler" not in subschema:
subschema["geonode:handler"] = "rndt"
else:
handler = subschema["geonode:handler"]
if handler == "sparse":
# fields has already been added to the sparsefield register
continue

self._add_subschema(jsonschema, property_name, subschema)

# rndt_required_fields = ["id_access_contraints", "id_use_constraints", "id_resolution", "id_accuracy"]

# === remove unused fields
exclude_fields = ["constraints_other", "restriction_code_type"]
for field in exclude_fields:
logger.debug(f"Removing field {field}")
del jsonschema["properties"][field]

return jsonschema

def get_jsonschema_instance(
self, resource: ResourceBase, field_name: str, context: dict, errors: dict, lang: str = None
):
raise Exception(f"Unhandled field {field_name}")

def update_resource(
self, resource, field_name, json_instance, context, errors, **kwargs
):
raise Exception(f"Unhandled field {field_name}")

def pre_save(
self, resource: ResourceBase, json_instance: dict, context: dict, errors: dict, **kwargs
):
# RNDT requires restriction_code_type to be "otherRestrictions"
if not self.otherRestrictions:
from geonode.base.models import RestrictionCodeType
# see https://github.com/GeoNode/geonode/issues/12745
self.otherRestrictions = RestrictionCodeType.objects.filter(identifier="otherRestrictions").first() or \
RestrictionCodeType.objects.filter(description="otherRestrictions").first()

resource.restriction_code_type = self.otherRestrictions
context.setdefault("base", {})["restriction_code_type"] = self.otherRestrictions

# Setting the ResourceBase field either as URL or freetext
json_instance.get("rndt_ConditionsApplyingToAccessAndUse", {})
if json_instance.get("inspire_url", False):
val = json_instance.get("url", None)
else:
val = json_instance.get("freetext", None)
val = val or "Missing value"
resource.constraints_other = val
context.setdefault("base", {})["constraints_other"] = val

def init():
logger.info("Init RNDTSchema hooks")

# == Add json schema

# register sparse fields:
for property_name, subschema in load_schema_file().items():
if subschema.get("geonode:handler", None) == "sparse":
sparse_field_registry.register(property_name, subschema)

metadata_manager.add_handler("rndt", RNDTSchemaHandler)

# TODO: check for mandatory thesauri
Loading