Skip to content

Commit

Permalink
[Fixes #109 /2] Bug: Unable set keywords on geonode_objects when defi…
Browse files Browse the repository at this point in the history
…ning keyword via API
  • Loading branch information
Marcel Wallschlaeger committed Nov 9, 2024
1 parent e8ed2f7 commit a0aeb2c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 46 deletions.
2 changes: 1 addition & 1 deletion geonode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import os

__version__ = (4, 3, 1, 'final', 0)
__version__ = (4, 3, 1, "final", 0)


def get_version():
Expand Down
3 changes: 1 addition & 2 deletions geonode/base/api/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ def to_internal_value_single(self, data, serializer):
django.db.models.QuerySet: return QuerySet object of the request or set data
"""

related_model = serializer.Meta.model
try:
if isinstance(data, str):
data = json.loads(data)
Expand All @@ -89,6 +87,7 @@ def to_internal_value_single(self, data, serializer):
return super().to_internal_value_single(data, serializer)

def __set_full_keyword__(d):

if "name" not in d:
raise ValidationError('No "name" object found for given keyword ...')
if "slug" not in d:
Expand Down
41 changes: 2 additions & 39 deletions geonode/base/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ class Meta:
def to_representation(self, value):
return {"name": value.name, "slug": value.slug}


class _ThesaurusKeywordSerializerMixIn:
def to_representation(self, value):
_i18n = {}
Expand Down Expand Up @@ -416,39 +415,6 @@ def get_attribute(self, instance):
return False


# removed with merge to 4.3.1
# class UserSerializer(BaseDynamicModelSerializer):
# class Meta:
# ref_name = "UserProfile"
# model = get_user_model()
# name = "user"
# view_name = "users-list"
# fields = (
# "pk",
# "username",
# "first_name",
# "last_name",
# "avatar",
# "perms",
# "is_superuser",
# "is_staff",
# "email",
# "organization",
# "profile",
# "position",
# "voice",
# "fax",
# "delivery",
# "city",
# "area",
# "zipcode",
# "keywords",
# "country",
# "language",
# "timezone",
# "orcid_identifier",
# )

class AutoLinkField(DynamicComputedField):

def get_attribute(self, instance):
Expand Down Expand Up @@ -744,7 +710,7 @@ class ResourceBaseSerializer(DynamicModelSerializer):
sourcetype = serializers.CharField(read_only=True)
embed_url = EmbedUrlField(required=False)
thumbnail_url = ThumbnailUrlField(read_only=True)
keywords = ComplexDynamicRelationField(SimpleHierarchicalKeywordSerializer, many=True)
keywords = KeywordsDynamicRelationField(SimpleHierarchicalKeywordSerializer, many=True)
tkeywords = ComplexDynamicRelationField(SimpleThesaurusKeywordSerializer, many=True)
regions = DynamicRelationField(SimpleRegionSerializer, embed=True, many=True, read_only=True)
category = ComplexDynamicRelationField(SimpleTopicCategorySerializer, embed=True)
Expand Down Expand Up @@ -884,9 +850,7 @@ class Meta:
# metadata_uploaded, metadata_uploaded_preserve, metadata_xml,
# users_geolimits, groups_geolimits
)




def to_internal_value(self, data):
if isinstance(data, str):
data = json.loads(data)
Expand Down Expand Up @@ -964,7 +928,6 @@ class Meta:
view_name = "keywords-list"
fields = "__all__"


class ThesaurusKeywordSerializer(_ThesaurusKeywordSerializerMixIn, BaseResourceCountSerializer):
class Meta:
model = ThesaurusKeyword
Expand Down
1 change: 0 additions & 1 deletion geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ class HierarchicalKeywordManager(MP_NodeManager):
def get_queryset(self):
return HierarchicalKeywordQuerySet(self.model).order_by("path")


class HierarchicalKeyword(TagBase, MP_Node):
node_order_by = ["name"]
objects = HierarchicalKeywordManager()
Expand Down
12 changes: 9 additions & 3 deletions geonode/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,11 @@ def set_resource_default_links(instance, layer, prune=False, **kwargs):
# Set download links for WMS, WCS or WFS and KML
logger.debug(" -- Resource Links[Set download links for WMS, WCS or WFS and KML]...")
instance_ows_url = f"{instance.ows_url}?" if instance.ows_url else f"{ogc_server_settings.public_url}ows?"
links = wms_links(instance_ows_url, instance.alternate, bbox, srid, height, width) if instance.subtype != "tabular" else []
links = (
wms_links(instance_ows_url, instance.alternate, bbox, srid, height, width)
if instance.subtype != "tabular"
else []
)

for ext, name, mime, wms_url in links:
try:
Expand Down Expand Up @@ -1650,8 +1654,10 @@ def set_resource_default_links(instance, layer, prune=False, **kwargs):
ogc_wms_url = instance.ows_url or urljoin(ogc_server_settings.public_url, "ows")
ogc_wms_name = f"OGC WMS: {instance.workspace} Service"
if (
instance.subtype != "tabular" and
Link.objects.filter(resource=instance.resourcebase_ptr, name=ogc_wms_name, url=ogc_wms_url).count()
instance.subtype != "tabular"
and Link.objects.filter(
resource=instance.resourcebase_ptr, name=ogc_wms_name, url=ogc_wms_url
).count()
< 2
):
Link.objects.get_or_create(
Expand Down

0 comments on commit a0aeb2c

Please sign in to comment.