Skip to content

Commit

Permalink
[To be reviewed] Fix some quirks occured while testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ridoo committed Feb 4, 2025
1 parent ea0d8a0 commit 9ad260d
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 30 deletions.
9 changes: 6 additions & 3 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import uuid
import logging
import traceback
import tempfile
from typing import List, Optional, Union, Tuple
from sequences.models import Sequence
from sequences import get_next_value
Expand All @@ -37,7 +38,7 @@
from django.utils.timezone import now
from django.db.models import Q, signals
from django.db.utils import IntegrityError, OperationalError
from django.contrib.auth.models import Group
from django.core.files import File
from django.core.files.base import ContentFile
from django.contrib.auth import get_user_model
from django.db.models.query import QuerySet
Expand Down Expand Up @@ -781,7 +782,7 @@ class ResourceBase(PolymorphicModel, PermissionLevelMixin, ItemBase):
data_quality_statement = models.TextField(
_("data quality statement"), max_length=2000, blank=True, null=True, help_text=data_quality_statement_help_text
)
group = models.ForeignKey(Group, null=True, blank=True, on_delete=models.SET_NULL)
group = models.ForeignKey(GroupProfile, null=True, blank=True, on_delete=models.SET_NULL)

# Section 9
# see metadata_author property definition below
Expand Down Expand Up @@ -1559,9 +1560,11 @@ def save_thumbnail(self, filename, image, thumbnail_algorithm=ThumbnailAlgorithm
tmp_location = os.path.abspath(f"{settings.MEDIA_ROOT}/{upload_path}")
im.save(tmp_location, quality="high")

lf = tempfile.NamedTemporaryFile(dir="media")
with open(tmp_location, "rb+") as img:
lf.write(img.read())
# Saving the img via storage manager
storage_manager.save(storage_manager.path(upload_path), img)
storage_manager.save(storage_manager.path(upload_path), File(img))

# If we use a remote storage, the local img is deleted
if tmp_location != storage_manager.path(upload_path):
Expand Down
6 changes: 1 addition & 5 deletions geonode/metadata/handlers/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ def update_schema(self, jsonschema, context, lang=None):
return jsonschema

def get_jsonschema_instance(self, resource, field_name, context, errors, lang=None):
return (
{"id": str(resource.group.groupprofile.pk), "label": resource.group.groupprofile.title}
if resource.group
else None
)
return {"id": str(resource.group.pk), "label": resource.group.title} if resource.group else None

def update_resource(self, resource, field_name, json_instance, context, errors, **kwargs):
data = json_instance.get(field_name, None)
Expand Down
4 changes: 2 additions & 2 deletions geonode/metadata/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,8 +1184,8 @@ def test_group_handler_get_jsonschema_instance_with_group(self):
field_name = "group"

expected_group_instance = {
"id": str(self.resource.group.groupprofile.pk),
"label": self.resource.group.groupprofile.title,
"id": str(self.resource.group.pk),
"label": self.resource.group.title,
}

group_instance = self.group_handler.get_jsonschema_instance(
Expand Down
4 changes: 3 additions & 1 deletion geonode/resource/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ def delete(self, uuid: str, /, instance: ResourceBase = None) -> int:
ResourceBase.objects.filter(uuid=uuid).delete()
return 0

def create(self, uuid: str, /, resource_type: typing.Optional[object] = None, defaults: dict = {}, *args, **kwargs) -> ResourceBase:
def create(
self, uuid: str, /, resource_type: typing.Optional[object] = None, defaults: dict = {}, *args, **kwargs
) -> ResourceBase:
if resource_type.objects.filter(uuid=uuid).exists():
return resource_type.objects.filter(uuid=uuid).get()
uuid = uuid or str(uuid4())
Expand Down
2 changes: 1 addition & 1 deletion geonode/templates/user_messages/thread_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h3>{{ thread.subject }}</h3>
,
{% endif %}
{% for group in thread.registered_groups.all%}
<a href={{ group.groupprofile.get_absolute_url }}>{{ group.groupprofile.title }}</a>
<a href={{ group.get_absolute_url }}>{{ group.title }}</a>
{%if not forloop.last%},{%endif%}
{% endfor %}
</div>
Expand Down
16 changes: 10 additions & 6 deletions geonode/upload/handlers/common/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,16 @@ def extract_params_from_data(_data, action=None):
title = json.loads(_data.get("defaults"))
return {"title": title.pop("title"), "store_spatial_file": True}, _data

return BaseHandler.extract_params_from_data(_data)[0] | {
"action": _data.pop("action", "upload"),
"title": _data.pop("title", None),
"url": _data.pop("url", None),
"type": _data.pop("type", None),
}, _data
return (
BaseHandler.extract_params_from_data(_data)[0]
| {
"action": _data.pop("action", "upload"),
"title": _data.pop("title", None),
"url": _data.pop("url", None),
"type": _data.pop("type", None),
},
_data,
)

def pre_validation(self, files, execution_id, **kwargs):
"""
Expand Down
10 changes: 7 additions & 3 deletions geonode/upload/handlers/common/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,13 @@ def extract_params_from_data(_data, action=None):
title = json.loads(_data.get("defaults"))
return {"title": title.pop("title"), "store_spatial_file": True}, _data

return BaseHandler.extract_params_from_data(_data)[0] | {
"action": _data.pop("action", "upload"),
}, _data
return (
BaseHandler.extract_params_from_data(_data)[0]
| {
"action": _data.pop("action", "upload"),
},
_data,
)

@staticmethod
def publish_resources(resources: List[str], catalog, store, workspace):
Expand Down
4 changes: 3 additions & 1 deletion geonode/upload/handlers/remote/tiles3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def create_geonode_resource(
asset=None,
custom: object = {},
):
resource = super().create_geonode_resource(layer_name, alternate, execution_id, resource_type, asset=asset, custom=custom)
resource = super().create_geonode_resource(
layer_name, alternate, execution_id, resource_type, asset=asset, custom=custom
)
_exec = orchestrator.get_execution_object(exec_id=execution_id)
try:
js_file = requests.get(_exec.input_params.get("url"), timeout=10).json()
Expand Down
4 changes: 3 additions & 1 deletion geonode/upload/handlers/remote/wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ def create_geonode_resource(
Use the default RemoteResourceHandler to create the geonode resource
after that, we assign the bbox and re-generate the thumbnail
"""
resource = super().create_geonode_resource(layer_name, alternate, execution_id, Dataset, asset=asset, custom=custom)
resource = super().create_geonode_resource(
layer_name, alternate, execution_id, Dataset, asset=asset, custom=custom
)
_exec = orchestrator.get_execution_object(execution_id)
remote_bbox = _exec.input_params.get("bbox")
if remote_bbox:
Expand Down
10 changes: 7 additions & 3 deletions geonode/upload/handlers/shapefile/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,13 @@ def extract_params_from_data(_data, action=None):
title = json.loads(_data.get("defaults"))
return {"title": title.pop("title"), "store_spatial_file": True}, _data

return BaseHandler.extract_params_from_data(_data)[0] | {
"action": _data.pop("action", "upload"),
}, _data
return (
BaseHandler.extract_params_from_data(_data)[0]
| {
"action": _data.pop("action", "upload"),
},
_data,
)

@staticmethod
def is_valid(files, user, **kwargs):
Expand Down
14 changes: 10 additions & 4 deletions geonode/upload/handlers/tiles3d/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,13 @@ def extract_params_from_data(_data, action=None):
title = json.loads(_data.get("defaults"))
return {"title": title.pop("title"), "store_spatial_file": True}, _data

return BaseHandler.extract_params_from_data(_data)[0] | {
"action": _data.pop("action", "upload"),
}, _data
return (
BaseHandler.extract_params_from_data(_data)[0]
| {
"action": _data.pop("action", "upload"),
},
_data,
)

def import_resource(self, files: dict, execution_id: str, **kwargs) -> str:
logger.info("Total number of layers available: 1")
Expand Down Expand Up @@ -226,7 +230,9 @@ def create_geonode_resource(
asset.location = [path for path in asset.location if path.endswith(".json")]
asset.save()

resource = super().create_geonode_resource(layer_name, alternate, execution_id, ResourceBase, asset=asset, custom=custom)
resource = super().create_geonode_resource(
layer_name, alternate, execution_id, ResourceBase, asset=asset, custom=custom
)

# fixing-up bbox for the 3dtile object
js_file = None
Expand Down

0 comments on commit 9ad260d

Please sign in to comment.