diff --git a/api/urls.py b/api/urls.py index 8cc44e69c969fd653553b615bfe82b0bf7ac2c71..3cf361a5104365de08b98d8666cd6f6f7570bf4a 100644 --- a/api/urls.py +++ b/api/urls.py @@ -10,8 +10,6 @@ from rest_framework import routers from conflicts.viewsets import ConflictOfInterestViewSet from news.viewsets import NewsItemViewSet -from journals.api import views as journal_api_views - router = routers.SimpleRouter() router.register(r'news', NewsItemViewSet) @@ -26,5 +24,6 @@ urlpatterns = router.urls urlpatterns += [ path('journals/', include('journals.api.urls')), + path('organizations/', include('organizations.api.urls')), ] diff --git a/organizations/api/serializers.py b/organizations/api/serializers.py new file mode 100644 index 0000000000000000000000000000000000000000..2e7a014fc7218ecc14f9fdd9ee3cbe8ef0da304b --- /dev/null +++ b/organizations/api/serializers.py @@ -0,0 +1,26 @@ +__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" +__license__ = "AGPL v3" + + +from rest_framework import serializers + +from django_countries.serializer_fields import CountryField + +from ..models import Organization + + +class OrganizationSerializer(serializers.BaseSerializer): + name = serializers.CharField(max_length=256) + name_original = serializers.CharField(max_length=256) + acronym = serializers.CharField(max_length=64) + country = CountryField() + + def to_representation(self, instance): + rep = { + 'name': instance.name, + 'acronym': instance.acronym, + 'country': instance.country.name + } + if instance.name_original: + rep['name_original'] = instance.name_original + return rep diff --git a/organizations/api/urls.py b/organizations/api/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..b82b3a7a1e671767bf278a203841830325bb0101 --- /dev/null +++ b/organizations/api/urls.py @@ -0,0 +1,23 @@ +copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" +__license__ = "AGPL v3" + + +from django.urls import path + +from organizations.api import views as api_views + + +urlpatterns = [ + + path( # /api/organizations/ + '', + api_views.OrganizationListAPIView.as_view(), + name='organizations' + ), + path( # /api/organizations/<int:pk> + '<int:pk>', + api_views.OrganizationRetrieveAPIView.as_view(), + name='organization-detail' + ), + +] diff --git a/organizations/api/views.py b/organizations/api/views.py new file mode 100644 index 0000000000000000000000000000000000000000..9699d829bf1919c49739d0422ece25a906cbb57f --- /dev/null +++ b/organizations/api/views.py @@ -0,0 +1,18 @@ +__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" +__license__ = "AGPL v3" + + +from rest_framework.generics import ListAPIView, RetrieveAPIView + +from ..models import Organization +from .serializers import OrganizationSerializer + + +class OrganizationListAPIView(ListAPIView): + queryset = Organization.objects.all().order_by('name') + serializer_class = OrganizationSerializer + + +class OrganizationRetrieveAPIView(RetrieveAPIView): + queryset = Organization.objects.all() + serializer_class = OrganizationSerializer