diff --git a/scipost_django/api/urls.py b/scipost_django/api/urls.py index b3fbee1594a7f60c5a9354f84ed72cc4842f50b9..5422a80a5f0ee61703322bc0376c84a55e58d8cd 100644 --- a/scipost_django/api/urls.py +++ b/scipost_django/api/urls.py @@ -27,7 +27,7 @@ router.register('publications', PublicationViewSet) # organizations router.register('organizations', OrganizationViewSet) -router.register('nap/organizations', OrganizationNAPViewSet) +router.register('nap', OrganizationNAPViewSet) # submissions router.register('submissions', SubmissionViewSet) @@ -49,6 +49,5 @@ urlpatterns += [ ), path('finances/', include('finances.api.urls')), path('journals/', include('journals.api.urls')), - path('organizations/', include('organizations.api.urls')), ] diff --git a/scipost_django/journals/api/serializers.py b/scipost_django/journals/api/serializers.py index 1bf970d0d8dd6bf63b68d034f985840b429a44db..69a9cc6b3830a133d05efacb97a0cd870aee5645 100644 --- a/scipost_django/journals/api/serializers.py +++ b/scipost_django/journals/api/serializers.py @@ -4,6 +4,7 @@ __license__ = "AGPL v3" from rest_framework import serializers +from organizations.api.serializers import OrganizationSerializer from ..models import Publication, OrgPubFraction @@ -54,6 +55,7 @@ class OrgPubFractionSerializer(serializers.ModelSerializer): Takes optional `fields` argument specifying which fields should be displayed. """ + organization = OrganizationSerializer() publication = PublicationSerializer() class Meta: diff --git a/scipost_django/organizations/api/urls.py b/scipost_django/organizations/api/urls.py deleted file mode 100644 index 1b9442509b490d2d55d4fc7b4437a7c1528464a3..0000000000000000000000000000000000000000 --- a/scipost_django/organizations/api/urls.py +++ /dev/null @@ -1,30 +0,0 @@ -copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" -__license__ = "AGPL v3" - - -from django.urls import path - -from rest_framework import routers - -#from organizations.api import views as api_views -from . import views as api_views -from . import viewsets as api_viewsets - - -router = routers.SimpleRouter() - -# OrganizationNAPViewSet before OrganizationViewSet, to prevent 404 -router.register('nap', api_viewsets.OrganizationNAPViewSet) -router.register('', api_viewsets.OrganizationViewSet) - - -urlpatterns = router.urls - -urlpatterns += [ - - path( # /api/organizations/<int:pk>/balance - '<int:pk>/balance', - api_views.OrganizationBalanceAPIView.as_view(), - name='organization-balance', - ) -] diff --git a/scipost_django/organizations/api/views.py b/scipost_django/organizations/api/views.py deleted file mode 100644 index 2dfc6d54905337e654632fb420af35d07d5e3529..0000000000000000000000000000000000000000 --- a/scipost_django/organizations/api/views.py +++ /dev/null @@ -1,33 +0,0 @@ -__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" -__license__ = "AGPL v3" - - -from rest_framework.generics import ListAPIView, RetrieveAPIView -from rest_framework.settings import api_settings -from rest_framework_csv import renderers as r - -from ..models import Organization -from .serializers import ( - OrganizationSerializer, - OrganizationNAPSerializer, - OrganizationBalanceSerializer -) -from .viewsets import OrganizationFilterSet - - -class OrganizationNAPListAPIView(ListAPIView): - queryset = Organization.objects.all() - serializer_class = OrganizationNAPSerializer - renderer_classes = tuple(api_settings.DEFAULT_RENDERER_CLASSES) + (r.PaginatedCSVRenderer, ) - search_fields = ['name', 'name_original', 'acronym',] - filterset_class = OrganizationFilterSet - default_filtering_fields = [ - 'name__icontains', - 'name_original__icontains', - 'acronym__icontains' - ] - - -class OrganizationBalanceAPIView(RetrieveAPIView): - queryset = Organization.objects.all() - serializer_class = OrganizationBalanceSerializer diff --git a/scipost_django/organizations/api/viewsets.py b/scipost_django/organizations/api/viewsets.py index 839e4ae985f5efa27f3d85fb43d99e696c0bb7e9..ce2bb0a96dbe372d5c40eab3e67ea59a93b3ffcb 100644 --- a/scipost_django/organizations/api/viewsets.py +++ b/scipost_django/organizations/api/viewsets.py @@ -16,7 +16,12 @@ from rest_framework_csv import renderers as r from api.viewsets.mixins import FilteringOptionsActionMixin from ..models import Organization -from .serializers import OrganizationSerializer, OrganizationNAPSerializer +from journals.api.serializers import OrgPubFractionSerializer +from .serializers import ( + OrganizationSerializer, + OrganizationNAPSerializer, + OrganizationBalanceSerializer +) class OrganizationFilterSet(df_filters.FilterSet): @@ -45,6 +50,21 @@ class OrganizationViewSet(FilteringOptionsActionMixin, 'acronym__icontains' ] + @action(detail=True) + def pubfractions(self, request, pk=None): + pubfractions = self.get_object().pubfractions.all() + serializer = OrgPubFractionSerializer( + pubfractions, + many=True, + context={'request': self.request} + ) + return Response(serializer.data) + + @action(detail=True) + def balance(self, request, pk=None): + serializer = OrganizationBalanceSerializer(self.get_object()) + return Response(serializer.data) + class OrganizationNAPViewSet(OrganizationViewSet): serializer_class = OrganizationNAPSerializer