From fbd04504c207fe1f6ca88c821ce0b29bd95e1cfa Mon Sep 17 00:00:00 2001 From: mwallschlaeger Date: Thu, 6 Jun 2024 16:19:14 +0200 Subject: [PATCH 1/2] [Fixes #104] Bug: setting a funder with fundingreference is not working --- geonode/base/api/fields.py | 2 +- geonode/base/api/serializers.py | 63 ++++++++++++++------------------- 2 files changed, 27 insertions(+), 38 deletions(-) diff --git a/geonode/base/api/fields.py b/geonode/base/api/fields.py index 84283af29f4..30bee56b73b 100644 --- a/geonode/base/api/fields.py +++ b/geonode/base/api/fields.py @@ -53,7 +53,7 @@ def to_internal_value_single(self, data, serializer): funder = Funder.objects.get_or_create(**data) except TypeError: raise ParseError(detail="Could not convert related_identifier to internal object ...", code=400) - return funder + return funder[0] class ComplexDynamicRelationField(DynamicRelationField): diff --git a/geonode/base/api/serializers.py b/geonode/base/api/serializers.py index d7e33a90382..70114c3c481 100644 --- a/geonode/base/api/serializers.py +++ b/geonode/base/api/serializers.py @@ -414,37 +414,37 @@ def get_attribute(self, instance): return False - 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" - ) + 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", + ) @classmethod def setup_eager_loading(cls, queryset): @@ -466,10 +466,7 @@ def to_representation(self, instance): return data avatar = AvatarUrlField(240, read_only=True) - keywords = ComplexDynamicRelationField( - SimpleHierarchicalKeywordSerializer, embed=False, many=True - ) - + keywords = ComplexDynamicRelationField(SimpleHierarchicalKeywordSerializer, embed=False, many=True) class ContactRoleField(DynamicComputedField): @@ -995,14 +992,6 @@ class Meta: fields = "__all__" -class FundingReferenceSerializer(DynamicModelSerializer): - class Meta: - name = "fundingreferences" - model = FundingReference - count_type = "fundingreferences" - fields = "__all__" - - class RelatedProjectSerializer(DynamicModelSerializer): class Meta: name = "relatedprojects" From c302b20cf27031565009375a6f5026b67dada006 Mon Sep 17 00:00:00 2001 From: mwallschlaeger Date: Thu, 6 Jun 2024 16:24:53 +0200 Subject: [PATCH 2/2] [Fixes #104] Bug: setting a funder with fundingreference is not working --- geonode/base/api/serializers.py | 9 +++++++++ geonode/base/api/views.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/geonode/base/api/serializers.py b/geonode/base/api/serializers.py index 75724cf4619..ec43c14d115 100644 --- a/geonode/base/api/serializers.py +++ b/geonode/base/api/serializers.py @@ -1006,6 +1006,15 @@ class Meta: count_type = "relatedidentifiertype" fields = "__all__" + +class RelatedIdentifierSerializer(DynamicModelSerializer): + class Meta: + name = "relatedidentifiers" + model = RelatedIdentifier + count_type = "relatedidentifier" + fields = "__all__" + + class RelatedProjectSerializer(DynamicModelSerializer): class Meta: name = "relatedprojects" diff --git a/geonode/base/api/views.py b/geonode/base/api/views.py index e268148032e..1541d8db12b 100644 --- a/geonode/base/api/views.py +++ b/geonode/base/api/views.py @@ -122,8 +122,8 @@ FullLicenseSerializer, RelationTypeSerializer, RelatedIdentifierTypeSerializer, - RelatedIdentifierSerializer, FundingReferenceSerializer, + RelatedIdentifierSerializer, RelatedProjectSerializer, RegionSerializer, ThesaurusKeywordSerializer,