Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fixes #130] Feature add all bonares contact roles #216

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
30 changes: 15 additions & 15 deletions geonode/base/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
Link,
RelationType,
RelatedIdentifierType,
FundingReference,
Organization,
RelatedIdentifier,
Funder,
Funding,
RelatedProject,
License,
HierarchicalKeyword,
Expand Down Expand Up @@ -224,22 +224,22 @@ class RelatedIdentifierTypeAdmin(admin.ModelAdmin):
form = forms.modelform_factory(RelatedIdentifierType, fields="__all__")


class FundingReferenceAdmin(admin.ModelAdmin):
model = FundingReference
list_display = ("name_of_the_institution", "ror", "abbreviation", "address_information", "contact_information")
class OrganizationAdmin(admin.ModelAdmin):
model = Organization
list_display = ("id", "organization", "ror", "abbreviation")
list_display_links = []
list_filter = ("name_of_the_institution", "ror", "abbreviation")
list_filter = ("organization", "ror", "abbreviation")

form = forms.modelform_factory(FundingReference, fields="__all__")
form = forms.modelform_factory(Organization, fields="__all__")


class FunderAdmin(admin.ModelAdmin):
model = Funder
list_display = ("funding_reference", "award_number", "award_uri", "award_title")
list_display_links = ("funding_reference",)
list_filter = ("funding_reference", "award_number", "award_uri", "award_title")
class FundingAdmin(admin.ModelAdmin):
model = Funding
list_display = ("organization", "award_number", "award_uri", "award_title")
list_display_links = ("organization",)
list_filter = ("organization", "award_number", "award_uri", "award_title")

form = forms.modelform_factory(Funder, fields="__all__")
form = forms.modelform_factory(Funding, fields="__all__")


class RelatedProjectAdmin(admin.ModelAdmin):
Expand Down Expand Up @@ -389,8 +389,8 @@ def keyword_id(self, obj):
admin.site.register(RelationType, RelationTypeAdmin)
admin.site.register(RelatedIdentifierType, RelatedIdentifierTypeAdmin)
admin.site.register(RelatedIdentifier, RelatedIdentifierAdmin)
admin.site.register(FundingReference, FundingReferenceAdmin)
admin.site.register(Funder, FunderAdmin)
admin.site.register(Organization, OrganizationAdmin)
admin.site.register(Funding, FundingAdmin)
admin.site.register(RelatedProject, RelatedProjectAdmin)
admin.site.register(HierarchicalKeyword, HierarchicalKeywordAdmin)
admin.site.register(MenuPlaceholder, MenuPlaceholderAdmin)
Expand Down
17 changes: 8 additions & 9 deletions geonode/base/api/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
RelatedIdentifierType,
RelationType,
RelatedIdentifier,
FundingReference,
Funder,
Organization,
Funding,
HierarchicalKeyword,
)

Expand All @@ -49,17 +49,17 @@ def to_internal_value_single(self, data, serializer):
return r


class FundersDynamicRelationField(DynamicRelationField):
class FundingsDynamicRelationField(DynamicRelationField):
def to_internal_value_single(self, data, serializer):
try:
funding_reference = FundingReference.objects.get(**data["funding_reference"])
data["funding_reference"] = funding_reference
organization = Organization.objects.get(**data["organization"])
data["organization"] = organization
except TypeError:
raise ParseError(detail="Missing funding_reference object in funders ...", code=400)
raise ParseError(detail="Missing funding_organization object in funding ...", code=400)
try:
funder = Funder.objects.get_or_create(**data)
funder = Funding.objects.get_or_create(**data)
except TypeError:
raise ParseError(detail="Could not convert related_identifier to internal object ...", code=400)
raise ParseError(detail="Could not convert funding to internal object ...", code=400)
return funder[0]


Expand Down Expand Up @@ -87,7 +87,6 @@ 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
91 changes: 64 additions & 27 deletions geonode/base/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
RelatedIdentifierType,
RelationType,
RelatedIdentifier,
FundingReference,
Organization,
RelatedProject,
Funder,
Funding,
LinkedResource,
)
from geonode.documents.models import Document
Expand All @@ -70,7 +70,7 @@
from geonode.base.api.fields import (
ComplexDynamicRelationField,
RelatedIdentifierDynamicRelationField,
FundersDynamicRelationField,
FundingsDynamicRelationField,
KeywordsDynamicRelationField,
)
from geonode.layers.utils import get_dataset_download_handlers, get_default_dataset_download_handler
Expand Down Expand Up @@ -161,6 +161,7 @@ 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 @@ -225,20 +226,20 @@ class Meta:
relation_type = DynamicRelationField(SimpleRelationType, embed=True, many=False)


class FundingReferenceSerializer(DynamicModelSerializer):
class OrganizationSerializer(DynamicModelSerializer):
class Meta:
model = FundingReference
name = "FundingReference"
fields = ("name_of_the_institution", "ror", "abbreviation")
model = Organization
name = " Organization"
fields = ("id", "organization", "ror", "abbreviation")


class SimpleFunderSerializer(DynamicModelSerializer):
class FundingSerializer(DynamicModelSerializer):
class Meta:
model = Funder
name = "Funder"
fields = ("award_title", "award_uri", "funding_reference", "award_number")
model = Funding
name = "Funding"
fields = ("organization", "award_title", "award_uri", "award_number")

funding_reference = DynamicRelationField(FundingReferenceSerializer, embed=True, many=False)
organization = DynamicRelationField(OrganizationSerializer, embed=True, many=False)


class SimpleRelatedProjectSerializer(DynamicModelSerializer):
Expand Down Expand Up @@ -416,7 +417,6 @@ def get_attribute(self, instance):


class AutoLinkField(DynamicComputedField):

def get_attribute(self, instance):
parents = []
parent = self.parent
Expand All @@ -443,6 +443,7 @@ def get_attribute(self, instance):
logger.exception(e)
return None


class ContactRoleField(DynamicComputedField):
default_error_messages = {
"required": ("ContactRoleField This field is required."),
Expand Down Expand Up @@ -626,9 +627,30 @@ class ResourceBaseSerializer(DynamicModelSerializer):
resource_provider = ContactRoleField(Roles.RESOURCE_PROVIDER.name, required=False)
originator = ContactRoleField(Roles.ORIGINATOR.name, required=False)
principal_investigator = ContactRoleField(Roles.PRINCIPAL_INVESTIGATOR.name, required=False)

data_collector = ContactRoleField(Roles.DATA_COLLECTOR.name, required=False)
data_curator = ContactRoleField(Roles.DATA_CURATOR.name, required=False)
editor = ContactRoleField(Roles.EDITOR.name, required=False)
host_institution = ContactRoleField(Roles.HOSTING_INSTITUTION.name, required=False)
other = ContactRoleField(Roles.OTHER.name, required=False)
producer = ContactRoleField(Roles.PRODUCER.name, required=False)
project_leader = ContactRoleField(Roles.PROJECT_LEADER.name, required=False)
project_manager = ContactRoleField(Roles.PROJECT_MANAGER.name, required=False)
project_member = ContactRoleField(Roles.PROJECT_MEMBER.name, required=False)
registration_agency = ContactRoleField(Roles.REGISTRATION_AGENCY.name, required=False)
registration_authority = ContactRoleField(Roles.REGISTRATION_AUTHORITY.name, required=False)
related_person = ContactRoleField(Roles.RELATED_PERSON.name, required=False)
research_group = ContactRoleField(Roles.RESEARCH_GROUP.name, required=False)
researcher = ContactRoleField(Roles.RESEARCHER.name, required=False)
rights_holder = ContactRoleField(Roles.RIGHTS_HOLDER.name, required=False)
sponsor = ContactRoleField(Roles.SPONSOR.name, required=False)
supervisor = ContactRoleField(Roles.SUPERVISOR.name, required=False)
work_package_leader = ContactRoleField(Roles.WORK_PACKAGE_LEADER.name, required=False)


title = serializers.CharField(required=False)
abstract = serializers.CharField(required=False)

# BONARES ELEMENTS
title_translated = serializers.CharField(required=False)
abstract_translated = serializers.CharField(required=False)
Expand All @@ -639,18 +661,12 @@ class ResourceBaseSerializer(DynamicModelSerializer):
technical_info = serializers.CharField(required=False)
other_description = serializers.CharField(required=False)

related_identifier = RelatedIdentifierDynamicRelationField(
SimpleRelatedIdentifierSerializer, embed=True, many=True
)
funders = FundersDynamicRelationField(SimpleFunderSerializer, embed=True, many=True)
related_projects = ComplexDynamicRelationField(
SimpleRelatedProjectSerializer, embed=True, many=True
)
related_identifier = RelatedIdentifierDynamicRelationField(SimpleRelatedIdentifierSerializer, embed=True, many=True)
# fundings = FundingsDynamicRelationField(FundingSerializer, embed=True, many=True)
related_projects = ComplexDynamicRelationField(SimpleRelatedProjectSerializer, embed=True, many=True)
conformity_results = serializers.CharField(required=False)
conformity_explanation = serializers.CharField(required=False)
parent_identifier = ComplexDynamicRelationField(
SimpleResourceSerializer, embed=True, many=False, required=False
)
parent_identifier = ComplexDynamicRelationField(SimpleResourceSerializer, embed=True, many=False, required=False)
date_available = serializers.DateField(required=False)
date_updated = serializers.DateField(required=False)
date_created = serializers.DateField(required=False)
Expand Down Expand Up @@ -714,7 +730,7 @@ class ResourceBaseSerializer(DynamicModelSerializer):
tkeywords = ComplexDynamicRelationField(SimpleThesaurusKeywordSerializer, many=True)
regions = DynamicRelationField(SimpleRegionSerializer, embed=True, many=True, read_only=True)
category = ComplexDynamicRelationField(SimpleTopicCategorySerializer, embed=True)
#restriction_code_type = ComplexDynamicRelationField(RestrictionCodeTypeSerializer, embed=True)
# restriction_code_type = ComplexDynamicRelationField(RestrictionCodeTypeSerializer, embed=True)
spatial_representation_type = ComplexDynamicRelationField(SpatialRepresentationTypeSerializer, embed=True)
blob = serializers.JSONField(required=False, write_only=True)
is_copyable = serializers.BooleanField(read_only=True)
Expand Down Expand Up @@ -756,6 +772,26 @@ class Meta:
"resource_provider",
"originator",
"principal_investigator",

"data_collector",
"data_curator",
"editor",
"host_institution",
"other",
"producer",
"project_leader",
"project_manager",
"project_member",
"registration_agency",
"registration_authority",
"related_person",
"research_group",
"researcher",
"rights_holder",
"sponsor",
"supervisor",
"work_package_leader",

"keywords",
"tkeywords",
"regions",
Expand All @@ -773,7 +809,7 @@ class Meta:
"technical_info",
"other_description",
"related_identifier",
"funders",
"fundings",
"conformity_results",
"conformity_explanation",
"parent_identifier",
Expand Down Expand Up @@ -850,7 +886,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 @@ -928,6 +964,7 @@ class Meta:
view_name = "keywords-list"
fields = "__all__"


class ThesaurusKeywordSerializer(_ThesaurusKeywordSerializerMixIn, BaseResourceCountSerializer):
class Meta:
model = ThesaurusKeyword
Expand Down
6 changes: 3 additions & 3 deletions geonode/base/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1925,10 +1925,10 @@ def test_set_resource_thumbnail(self):
self.assertEqual(response.json(), "The url must be of an image with format (png, jpeg or jpg)")

# using Base64 data as an ASCII byte string
data["file"] = (
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABHNCSVQICAgI\
data[
"file"
] = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABHNCSVQICAgI\
fAhkiAAAABl0RVh0U29mdHdhcmUAZ25vbWUtc2NyZWVuc2hvdO8Dvz4AAAANSURBVAiZYzAxMfkPAALYAZzx61+bAAAAAElFTkSuQmCC"
)
with patch("geonode.base.models.is_monochromatic_image") as _mck:
_mck.return_value = False
response = self.client.put(url, data=data, format="json")
Expand Down
3 changes: 2 additions & 1 deletion geonode/base/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
router.register(r"relationtypes", views.RelationTypeViewSet, "relationtypes")
router.register(r"relatedidentifiertypes", views.RelatedIdentifierTypeViewSet, "relatedidentifiertypes")
router.register(r"relatedidentifiers", views.RelatedIdentifierViewSet, "relatedidentifiers")
router.register(r"fundingreferences", views.FundingReferenceViewSet, "fundingreferences")
router.register(r"organizations", views.OrganizationViewSet, "organizations")
router.register(r"fundings", views.FundingViewSet, "fundings")
router.register(r"relatedprojects", views.RelatedProjectViewSet, "relatedprojects")
router.register(r"keywords", views.HierarchicalKeywordViewSet, "keywords")
router.register(r"tkeywords", views.ThesaurusKeywordViewSet, "tkeywords")
Expand Down
28 changes: 22 additions & 6 deletions geonode/base/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
RelationType,
RelatedIdentifierType,
RelatedIdentifier,
FundingReference,
Organization,
Funding,
RelatedProject,
)
from geonode.base.api.filters import (
Expand Down Expand Up @@ -113,7 +114,8 @@
FullLicenseSerializer,
RelationTypeSerializer,
RelatedIdentifierTypeSerializer,
FundingReferenceSerializer,
OrganizationSerializer,
FundingSerializer,
RelatedIdentifierSerializer,
RelatedProjectSerializer,
RegionSerializer,
Expand Down Expand Up @@ -339,17 +341,31 @@ class RelatedIdentifierViewSet(WithDynamicViewSetMixin, ListModelMixin, Retrieve
pagination_class = GeoNodeApiPagination


class FundingReferenceViewSet(WithDynamicViewSetMixin, ListModelMixin, RetrieveModelMixin, GenericViewSet):
class OrganizationViewSet(WithDynamicViewSetMixin, ListModelMixin, RetrieveModelMixin, GenericViewSet):
"""
API endpoint that lists fundingreference.
API endpoint that lists Organizations, which are used as Funders and Organizations people are related to.
"""

permission_classes = [
AllowAny,
]
filter_backends = [DynamicFilterBackend, DynamicSortingFilter, DynamicSearchFilter]
queryset = FundingReference.objects.all()
serializer_class = FundingReferenceSerializer
queryset = Organization.objects.all()
serializer_class = OrganizationSerializer
pagination_class = GeoNodeApiPagination


class FundingViewSet(WithDynamicViewSetMixin, ListModelMixin, RetrieveModelMixin, GenericViewSet):
"""
API endpoint that lists Fundings.
"""

permission_classes = [
AllowAny,
]
filter_backends = [DynamicFilterBackend, DynamicSortingFilter, DynamicSearchFilter]
queryset = Funding.objects.all()
serializer_class = FundingSerializer
pagination_class = GeoNodeApiPagination


Expand Down
Loading