diff --git a/apps/resm/serializers.py b/apps/resm/serializers.py new file mode 100644 index 0000000..c5f69f5 --- /dev/null +++ b/apps/resm/serializers.py @@ -0,0 +1,7 @@ +from apps.utils.serializers import CustomModelSerializer +from .models import Paper + +class PaperListSerializer(CustomModelSerializer): + class Meta: + model = Paper + fields = '__all__' \ No newline at end of file diff --git a/apps/resm/urls.py b/apps/resm/urls.py index e69de29..0a23086 100644 --- a/apps/resm/urls.py +++ b/apps/resm/urls.py @@ -0,0 +1,13 @@ +from django.urls import path, include +from rest_framework import routers +from .views import PaperViewSet + +API_BASE_URL = 'api/resm/' +HTML_BASE_URL = 'resm/' + +router = routers.DefaultRouter() +router.register('paper', PaperViewSet, basename="paper") + +urlpatterns = [ + path(API_BASE_URL, include(router.urls)) +] \ No newline at end of file diff --git a/apps/resm/views.py b/apps/resm/views.py index 91ea44a..5abfecc 100644 --- a/apps/resm/views.py +++ b/apps/resm/views.py @@ -1,3 +1,24 @@ from django.shortcuts import render +from rest_framework.response import Response +from .models import Paper, PaperAbstract +from .serializers import PaperListSerializer +from apps.utils.viewsets import CustomGenericViewSet, CustomListModelMixin +from rest_framework.permissions import AllowAny # Create your views here. +class PaperViewSet(CustomGenericViewSet, CustomListModelMixin): + queryset = Paper.objects.all() + serializer_class = PaperListSerializer + filterset_fields = ["publication_year", "type", "fetch_status"] + search_fields = ['title', 'first_author', 'first_author_institution'] + ordering = ["-publication_date", "-create_time"] + + def get_authenticators(self): + if self.request.method == 'GET': + return [] + return super().get_authenticators() + + def get_permissions(self): + if self.request.method == 'GET': + return [AllowAny()] + return super().get_permissions() \ No newline at end of file diff --git a/server/urls.py b/server/urls.py index 8b32cc7..a2c95eb 100755 --- a/server/urls.py +++ b/server/urls.py @@ -48,6 +48,7 @@ urlpatterns = [ path('', include('apps.wf.urls')), path('', include('apps.utils.urls')), path('', include('apps.ops.urls')), + path('', include('apps.resm.urls')), # 前端页面入口 path('', TemplateView.as_view(template_name="index.html")),