From 7fb4d79ecab0ef7b3125bbbab8707c3ebf85c7e3 Mon Sep 17 00:00:00 2001 From: Kenzo-Hugo Hillion <kenzo-hugo.hillion1@pasteur.fr> Date: Wed, 7 Aug 2019 16:15:39 +0200 Subject: [PATCH] change name gene length to length --- backend/metagenedb/api/catalog/views/gene.py | 16 +++++++--------- backend/metagenedb/apps/catalog/admin/gene.py | 2 +- ...e.py => 0007_length_name_and_positive_int.py} | 7 ++++++- backend/metagenedb/apps/catalog/models/gene.py | 2 +- .../metagenedb/apps/catalog/serializers/gene.py | 4 ++-- backend/metagenedb/settings/django.py | 2 +- backend/metagenedb/urls.py | 1 + nginx/dev/dev.conf | 2 +- 8 files changed, 20 insertions(+), 16 deletions(-) rename backend/metagenedb/apps/catalog/migrations/{0007_gene_length_positive.py => 0007_length_name_and_positive_int.py} (63%) diff --git a/backend/metagenedb/api/catalog/views/gene.py b/backend/metagenedb/api/catalog/views/gene.py index c36bdba..f60033e 100644 --- a/backend/metagenedb/api/catalog/views/gene.py +++ b/backend/metagenedb/api/catalog/views/gene.py @@ -1,7 +1,8 @@ import pandas as pd +import django_filters.rest_framework from drf_yasg import openapi from drf_yasg.utils import swagger_auto_schema -from rest_framework.viewsets import GenericViewSet +from rest_framework.viewsets import GenericViewSet, ModelViewSet from rest_framework import mixins from rest_framework import status from rest_framework.decorators import action @@ -15,16 +16,14 @@ from metagenedb.apps.catalog.serializers import GeneSerializer # Define global variable for API documentation window_size_param = openapi.Parameter('window_size', in_=openapi.IN_QUERY, description='Size of the window.', type=openapi.TYPE_INTEGER, default=10000) -gene_length_schema = openapi.Schema("pouet", {}, type={'hihi': 'haha'}) -gene_length_response = openapi.Response('Get the distribution of gene length for a given window size', schema=gene_length_schema) +# gene_length_schema = openapi.Schema("pouet", {}, type={'hihi': 'haha'}) +# gene_length_response = openapi.Response('Get the distribution of gene length for a given window size', schema=gene_length_schema) -class GeneViewSet(mixins.ListModelMixin, - mixins.RetrieveModelMixin, - GenericViewSet): +class GeneViewSet(ModelViewSet): queryset = Gene.objects.all() serializer_class = GeneSerializer - GENE_LENGTH_COL = 'gene_length' + GENE_LENGTH_COL = 'length' def _count_windows(self, df, window_size=10000, window_col=GENE_LENGTH_COL): """ @@ -48,10 +47,9 @@ class GeneViewSet(mixins.ListModelMixin, @swagger_auto_schema( manual_parameters=[window_size_param], responses={ - '200': gene_length_response, + # '200': gene_length_response, '204': 'no content' }, - security=[], operation_id='List of categories', ) @action(methods=['get'], detail=False) diff --git a/backend/metagenedb/apps/catalog/admin/gene.py b/backend/metagenedb/apps/catalog/admin/gene.py index c9104b6..694e7b2 100644 --- a/backend/metagenedb/apps/catalog/admin/gene.py +++ b/backend/metagenedb/apps/catalog/admin/gene.py @@ -6,7 +6,7 @@ from metagenedb.apps.catalog.models import Gene @admin.register(Gene) class GeneAdmin(admin.ModelAdmin): - list_display = ('gene_id', 'gene_length', 'get_functions', 'get_taxonomy') + list_display = ('gene_id', 'length', 'get_functions', 'get_taxonomy') search_fields = ('gene_id',) def get_functions(self, obj): diff --git a/backend/metagenedb/apps/catalog/migrations/0007_gene_length_positive.py b/backend/metagenedb/apps/catalog/migrations/0007_length_name_and_positive_int.py similarity index 63% rename from backend/metagenedb/apps/catalog/migrations/0007_gene_length_positive.py rename to backend/metagenedb/apps/catalog/migrations/0007_length_name_and_positive_int.py index 7e90fa6..1fa5859 100644 --- a/backend/metagenedb/apps/catalog/migrations/0007_gene_length_positive.py +++ b/backend/metagenedb/apps/catalog/migrations/0007_length_name_and_positive_int.py @@ -1,4 +1,4 @@ -# Generated by Django 2.2.1 on 2019-08-07 13:20 +# Generated by Django 2.2.1 on 2019-08-07 14:10 from django.db import migrations, models @@ -15,4 +15,9 @@ class Migration(migrations.Migration): name='gene_length', field=models.PositiveIntegerField(), ), + migrations.RenameField( + model_name='gene', + old_name='gene_length', + new_name='length', + ), ] diff --git a/backend/metagenedb/apps/catalog/models/gene.py b/backend/metagenedb/apps/catalog/models/gene.py index 755ea4b..06c14dd 100644 --- a/backend/metagenedb/apps/catalog/models/gene.py +++ b/backend/metagenedb/apps/catalog/models/gene.py @@ -5,7 +5,7 @@ from .function import Function class Gene(models.Model): gene_id = models.CharField(max_length=100, unique=True, db_index=True) - gene_length = models.PositiveIntegerField() + length = models.PositiveIntegerField() functions = models.ManyToManyField(Function) taxonomy = models.ForeignKey( 'Taxonomy', related_name='genes', diff --git a/backend/metagenedb/apps/catalog/serializers/gene.py b/backend/metagenedb/apps/catalog/serializers/gene.py index 1928f2e..fe869af 100644 --- a/backend/metagenedb/apps/catalog/serializers/gene.py +++ b/backend/metagenedb/apps/catalog/serializers/gene.py @@ -4,7 +4,7 @@ from metagenedb.apps.catalog.serializers import FunctionSerializer class GeneSerializer(serializers.ModelSerializer): - functions = FunctionSerializer(many=True, read_only=True) + functions = FunctionSerializer(many=True, required=False) taxonomy = serializers.SlugRelatedField( queryset=Taxonomy.objects.all(), slug_field='tax_id', @@ -13,4 +13,4 @@ class GeneSerializer(serializers.ModelSerializer): class Meta: model = Gene - fields = ('gene_id', 'gene_length', 'functions', 'taxonomy') + fields = ('gene_id', 'length', 'functions', 'taxonomy') diff --git a/backend/metagenedb/settings/django.py b/backend/metagenedb/settings/django.py index 4d0e798..9973a7e 100644 --- a/backend/metagenedb/settings/django.py +++ b/backend/metagenedb/settings/django.py @@ -106,7 +106,7 @@ REST_FRAMEWORK = { # 'rest_framework.authentication.BasicAuthentication', ), 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', - 'PAGE_SIZE': 100 + 'PAGE_SIZE': 100, } diff --git a/backend/metagenedb/urls.py b/backend/metagenedb/urls.py index 7d8394e..cc83bb9 100644 --- a/backend/metagenedb/urls.py +++ b/backend/metagenedb/urls.py @@ -39,4 +39,5 @@ urlpatterns = [ path('admin/', admin.site.urls), url(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'), url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), + url(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'), ] diff --git a/nginx/dev/dev.conf b/nginx/dev/dev.conf index 4b2b44e..112daec 100644 --- a/nginx/dev/dev.conf +++ b/nginx/dev/dev.conf @@ -41,7 +41,7 @@ http { } # backend urls - location ~ ^/(admin|api|swagger|static) { + location ~ ^/(admin|api|swagger|redoc|static) { proxy_redirect off; proxy_pass http://backend; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; -- GitLab