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

Merge branch '130-put-post-statistics-endpoint' into 'dev'

Resolve Endpoints to allow updating by admin without computing

Closes #130

See merge request !53
parents b9df62f1 0e2273b7
Pipeline #31634 passed with stages
in 3 minutes and 8 seconds
......@@ -13,7 +13,7 @@ from metagenedb.apps.catalog.models import EggNOG, Function, KeggOrthology
from metagenedb.apps.catalog.serializers import EggNOGSerializer, FunctionSerializer, KeggOrthologySerializer
from metagenedb.common.utils.external_api.togows import GetFunctionExternalInfo
from .base import BulkViewSet, QParamsValidationViewSet
from .base import BulkViewSet
logger = logging.getLogger(__name__)
......@@ -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
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'
@swagger_auto_schema(
......@@ -15,18 +16,31 @@ class StatisticsViewSet(viewsets.ViewSet):
operation_summary="API to list all pre-computed statistics.",
tags=['Statistics'],
)
def list(self, request):
queryset = Statistics.objects.all()
serializer = StatisticsSerializer(queryset, many=True)
return Response(serializer.data)
def list(self, *args, **kwargs):
return super().list(*args, **kwargs)
@swagger_auto_schema(
operation_description="Retrieve pre-computed statistics from an ID",
operation_summary="API to retrieve pre-computed statistics.",
tags=['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(serializer.data)
def retrieve(self, *args, **kwargs):
return super().retrieve(*args, **kwargs)
@swagger_auto_schema(
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 .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
@admin.register(Statistics)
class StatisticsAdmin(admin.ModelAdmin):
list_display = ('stats_id',)
search_fields = ('stats_id',)
......@@ -203,7 +203,7 @@ class Command(BaseCommand):
only_step = self._get_and_validate_only_step(options['only'])
gene_sources = self._get_and_validate_source(options['source'])
for gene_source in gene_sources:
if only_step is None or only_step == "clean":
if only_step == "clean":
ComputeStatistics(gene_source).clean_db()
if only_step is None or only_step == "counts":
ComputeCounts(gene_source).all()
......
# Generated by Django 3.0.4 on 2020-06-04 14:47
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('catalog', '0025_add_virgo_source'),
]
operations = [
migrations.AlterModelOptions(
name='statistics',
options={'verbose_name_plural': 'Statistics'},
),
]
......@@ -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"
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