Skip to content
Snippets Groups Projects
Commit 3ed89f51 authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion :recycle:
Browse files

add statistics PUT and POST and fix Kegg Eggnog permissions

parent 6053af0b
No related branches found
No related tags found
2 merge requests!59Prod,!53Resolve Endpoints to allow updating by admin without computing
Pipeline #31628 failed
...@@ -57,7 +57,7 @@ class FunctionViewSet(BulkViewSet): ...@@ -57,7 +57,7 @@ class FunctionViewSet(BulkViewSet):
return super().partial_update(*args, **kwargs) return super().partial_update(*args, **kwargs)
class KeggOrthologyViewSet(QParamsValidationViewSet): class KeggOrthologyViewSet(BulkViewSet):
queryset = KeggOrthology.objects.all() queryset = KeggOrthology.objects.all()
serializer_class = KeggOrthologySerializer serializer_class = KeggOrthologySerializer
lookup_field = 'function_id' lookup_field = 'function_id'
...@@ -117,7 +117,7 @@ class KeggOrthologyViewSet(QParamsValidationViewSet): ...@@ -117,7 +117,7 @@ class KeggOrthologyViewSet(QParamsValidationViewSet):
return super().partial_update(*args, **kwargs) return super().partial_update(*args, **kwargs)
class EggNOGViewSet(QParamsValidationViewSet): class EggNOGViewSet(BulkViewSet):
queryset = EggNOG.objects.all() queryset = EggNOG.objects.all()
serializer_class = EggNOGSerializer serializer_class = EggNOGSerializer
lookup_field = 'function_id' lookup_field = 'function_id'
......
from django.shortcuts import get_object_or_404
from drf_yasg.utils import swagger_auto_schema from drf_yasg.utils import swagger_auto_schema
from rest_framework import viewsets from rest_framework import viewsets
from rest_framework.response import Response from rest_framework.response import Response
...@@ -6,8 +5,12 @@ from rest_framework.response import Response ...@@ -6,8 +5,12 @@ from rest_framework.response import Response
from metagenedb.apps.catalog.models import Statistics from metagenedb.apps.catalog.models import Statistics
from metagenedb.apps.catalog.serializers import StatisticsSerializer from metagenedb.apps.catalog.serializers import StatisticsSerializer
from .base import BulkViewSet
class StatisticsViewSet(viewsets.ViewSet):
class StatisticsViewSet(BulkViewSet):
queryset = Statistics.objects.all()
serializer_class = StatisticsSerializer
lookup_field = 'stats_id' lookup_field = 'stats_id'
@swagger_auto_schema( @swagger_auto_schema(
...@@ -15,18 +18,31 @@ class StatisticsViewSet(viewsets.ViewSet): ...@@ -15,18 +18,31 @@ class StatisticsViewSet(viewsets.ViewSet):
operation_summary="API to list all pre-computed statistics.", operation_summary="API to list all pre-computed statistics.",
tags=['Statistics'], tags=['Statistics'],
) )
def list(self, request): def list(self, *args, **kwargs):
queryset = Statistics.objects.all() return super().list(*args, **kwargs)
serializer = StatisticsSerializer(queryset, many=True)
return Response(serializer.data)
@swagger_auto_schema( @swagger_auto_schema(
operation_description="Retrieve pre-computed statistics from an ID", operation_description="Retrieve pre-computed statistics from an ID",
operation_summary="API to retrieve pre-computed statistics.", operation_summary="API to retrieve pre-computed statistics.",
tags=['Statistics'], tags=['Statistics'],
) )
def retrieve(self, request, stats_id=None): def retrieve(self, *args, **kwargs):
queryset = Statistics.objects.all() return super().retrieve(*args, **kwargs)
stats = get_object_or_404(queryset, stats_id=stats_id)
serializer = StatisticsSerializer(stats) @swagger_auto_schema(
return Response(serializer.data) tags=['Statistics'],
)
def create(self, *args, **kwargs):
return super().create(*args, **kwargs)
@swagger_auto_schema(
tags=['Statistics'],
)
def update(self, *args, **kwargs):
return super().update(*args, **kwargs)
@swagger_auto_schema(
tags=['Statistics'],
)
def partial_update(self, *args, **kwargs):
return super().partial_update(*args, **kwargs)
from .gene import GeneAdmin # noqa from .gene import GeneAdmin # noqa
from .function import FunctionAdmin, KeggOrthologyAdmin # noqa from .function import FunctionAdmin, KeggOrthologyAdmin # noqa
from .statistics import Statistics # noqa
from .taxonomy import TaxonomyAdmin # noqa from .taxonomy import TaxonomyAdmin # noqa
from django.contrib import admin
from metagenedb.apps.catalog.models import Statistics
@admin.register(Statistics)
class StatisticsAdmin(admin.ModelAdmin):
list_display = ('stats_id',)
search_fields = ('stats_id',)
...@@ -9,3 +9,6 @@ class Statistics(models.Model): ...@@ -9,3 +9,6 @@ class Statistics(models.Model):
stats_id = models.SlugField(max_length=400, db_index=True, unique=True) stats_id = models.SlugField(max_length=400, db_index=True, unique=True)
body = JSONField() body = JSONField()
class Meta:
verbose_name_plural = "Statistics"
...@@ -7,4 +7,7 @@ class ListAndRetrieveAll(BasePermission): ...@@ -7,4 +7,7 @@ class ListAndRetrieveAll(BasePermission):
""" """
def has_permission(self, request, view): def has_permission(self, request, view):
print(view.action)
print(view.action in ['list', 'retrieve'])
print(request.user.is_staff)
return view.action in ['list', 'retrieve'] or request.user.is_staff return view.action in ['list', 'retrieve'] or request.user.is_staff
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment