Commit 3ed89f51 authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

add statistics PUT and POST and fix Kegg Eggnog permissions

parent 6053af0b
Pipeline #31628 failed with stages
in 3 minutes and 14 seconds
......@@ -57,7 +57,7 @@ class FunctionViewSet(BulkViewSet):
return super().partial_update(*args, **kwargs)
class KeggOrthologyViewSet(QParamsValidationViewSet):
class KeggOrthologyViewSet(BulkViewSet):
queryset = KeggOrthology.objects.all()
serializer_class = KeggOrthologySerializer
lookup_field = 'function_id'
......@@ -117,7 +117,7 @@ class KeggOrthologyViewSet(QParamsValidationViewSet):
return super().partial_update(*args, **kwargs)
class EggNOGViewSet(QParamsValidationViewSet):
class EggNOGViewSet(BulkViewSet):
queryset = EggNOG.objects.all()
serializer_class = EggNOGSerializer
lookup_field = 'function_id'
from django.shortcuts import get_object_or_404
from drf_yasg.utils import swagger_auto_schema
from rest_framework import viewsets
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.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'
......@@ -15,18 +18,31 @@ class StatisticsViewSet(viewsets.ViewSet):
operation_summary="API to list all pre-computed statistics.",
def list(self, request):
queryset = Statistics.objects.all()
serializer = StatisticsSerializer(queryset, many=True)
return Response(
def list(self, *args, **kwargs):
return super().list(*args, **kwargs)
operation_description="Retrieve pre-computed statistics from an ID",
operation_summary="API to retrieve pre-computed statistics.",
def retrieve(self, request, stats_id=None):
queryset = Statistics.objects.all()
stats = get_object_or_404(queryset, stats_id=stats_id)
serializer = StatisticsSerializer(stats)
return Response(
def retrieve(self, *args, **kwargs):
return super().retrieve(*args, **kwargs)
def create(self, *args, **kwargs):
return super().create(*args, **kwargs)
def update(self, *args, **kwargs):
return super().update(*args, **kwargs)
def partial_update(self, *args, **kwargs):
return super().partial_update(*args, **kwargs)
from .gene import GeneAdmin # noqa
from .function import FunctionAdmin, KeggOrthologyAdmin # noqa
from .statistics import Statistics # noqa
from .taxonomy import TaxonomyAdmin # noqa
from django.contrib import admin
from metagenedb.apps.catalog.models import Statistics
class StatisticsAdmin(admin.ModelAdmin):
list_display = ('stats_id',)
search_fields = ('stats_id',)
......@@ -9,3 +9,6 @@ class Statistics(models.Model):
stats_id = models.SlugField(max_length=400, db_index=True, unique=True)
body = JSONField()
class Meta:
verbose_name_plural = "Statistics"
......@@ -7,4 +7,7 @@ class ListAndRetrieveAll(BasePermission):
def has_permission(self, request, view):
print(view.action in ['list', 'retrieve'])
return view.action in ['list', 'retrieve'] or request.user.is_staff
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment