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

max number of fasta sequences in django env

parent ebf8da30
Pipeline #32500 passed with stages
in 3 minutes and 14 seconds
......@@ -2,12 +2,14 @@ import hashlib
from io import StringIO
from django.core.cache import cache
from django.http import HttpResponse, JsonResponse
from django.conf import settings
from django.http import HttpResponse
from drf_yasg.utils import swagger_auto_schema
from marshmallow.exceptions import ValidationError
from rest_framework.response import Response
from rest_framework.status import HTTP_422_UNPROCESSABLE_ENTITY
from rest_framework.status import (
HTTP_422_UNPROCESSABLE_ENTITY, HTTP_500_INTERNAL_SERVER_ERROR
)
from metagenedb.apps.catalog.models import Gene
from metagenedb.api.catalog.filters import GeneFilter
from metagenedb.api.catalog.qparams_validators.gene import GeneQueryParams
......@@ -16,6 +18,9 @@ from metagenedb.apps.catalog.serializers import GeneSerializer
from .base import BulkViewSet
MAX_FASTA_GENES = settings.MAX_FASTA_GENES
class GeneViewSet(BulkViewSet):
queryset = Gene.objects.select_related('taxonomy').prefetch_related('functions')
serializer_class = GeneSerializer
......@@ -34,8 +39,9 @@ class GeneViewSet(BulkViewSet):
def _build_fasta_response(self):
queryset = self.filter_queryset(self.get_queryset())
count = self._get_queryset_count(queryset)
if count >= 100000:
return JsonResponse({'error': 'Too many genes, can obtain only up to 100000 fasta seq.'})
if count >= MAX_FASTA_GENES:
error_message = f'Too many genes in the query, can obtain only up to {MAX_FASTA_GENES} fasta seq.'
return Response({'message': error_message}, status=HTTP_500_INTERNAL_SERVER_ERROR)
fasta_file = StringIO()
for gene in queryset.iterator():
fasta_file.write(gene.fasta)
......
from .django import * # noqa
from .celery import * # noqa
from .django import * # noqa
from .metagenedb import * # noqa
"""
Settings specific to metageneDB app and independant of Django
"""
import environ
root = environ.Path(__file__) - 3 # get root of the project
env = environ.Env()
environ.Env.read_env(root('.env')) # reading .env file
# Maximum number of FASTA genes able to retrieve through API
MAX_FASTA_GENES = env.str('MAX_FASTA_GENES', default=100000)
......@@ -49,8 +49,6 @@ spec:
value: '6379'
- name: PORT
value: "8000"
- name: DEBUG
value: "True"
ports:
- containerPort: 8000
resources:
......
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