From 2dac9173c918444a252ed2c041bce09f92a83f22 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 5 Apr 2021 19:35:16 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20basic=20API=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sophon/core/serializers.py | 31 +++++++++++++++++++++++++++++++ sophon/core/urls.py | 13 +++++++++++++ sophon/core/views.py | 21 +++++++++++++++++++-- sophon/urls.py | 3 ++- 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 sophon/core/serializers.py create mode 100644 sophon/core/urls.py diff --git a/sophon/core/serializers.py b/sophon/core/serializers.py new file mode 100644 index 0000000..7ef6502 --- /dev/null +++ b/sophon/core/serializers.py @@ -0,0 +1,31 @@ +from rest_framework import serializers +from . import models + + +class DataSourceSerializer(serializers.ModelSerializer): + """ + Serializer for :class:`.models.DataSource` . + """ + + class Meta: + model = models.DataSource + fields = [ + "pandasdmx_id", + "builtin", + "settings", + ] + + +class ProjectSerializer(serializers.ModelSerializer): + """ + Serializer for :class:`.models.Project` . + """ + + class Meta: + model = models.Project + fields = [ + "id", + "name", + "description", + "sources", + ] diff --git a/sophon/core/urls.py b/sophon/core/urls.py new file mode 100644 index 0000000..8d549b4 --- /dev/null +++ b/sophon/core/urls.py @@ -0,0 +1,13 @@ +from django.urls import path, include +from rest_framework.routers import DefaultRouter +from . import views + + +router = DefaultRouter() +router.register("projects", views.ProjectViewSet) +router.register("datasources", views.DataSourceViewSet) + + +urlpatterns = [ + path("", include(router.urls)) +] diff --git a/sophon/core/views.py b/sophon/core/views.py index 91ea44a..1d32128 100644 --- a/sophon/core/views.py +++ b/sophon/core/views.py @@ -1,3 +1,20 @@ -from django.shortcuts import render +from rest_framework import viewsets, permissions +from . import models, serializers -# Create your views here. + +class ProjectViewSet(viewsets.ModelViewSet): + """ + Viewset for :class:`.models.Project` instances. + """ + queryset = models.Project.objects.all() + serializer_class = serializers.ProjectSerializer + permission_classes = [] + + +class DataSourceViewSet(viewsets.ModelViewSet): + """ + Viewset for :class:`.models.DataSource` instances. + """ + queryset = models.DataSource.objects.all() + serializer_class = serializers.DataSourceSerializer + permission_classes = [] diff --git a/sophon/urls.py b/sophon/urls.py index 05358c8..a363f0d 100644 --- a/sophon/urls.py +++ b/sophon/urls.py @@ -18,5 +18,6 @@ from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), - path('api-auth/', include("rest_framework.urls")) + path('api-auth/', include("rest_framework.urls")), + path('api/', include("sophon.core.urls")), ]