Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Metagenomics
metagenedb
Commits
ad8a488c
Commit
ad8a488c
authored
Jun 18, 2020
by
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
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
backend/metagenedb/api/catalog/views/gene.py
View file @
ad8a488c
...
...
@@ -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
)
...
...
backend/metagenedb/settings/__init__.py
View file @
ad8a488c
from
.django
import
*
# noqa
from
.celery
import
*
# noqa
from
.django
import
*
# noqa
from
.metagenedb
import
*
# noqa
backend/metagenedb/settings/metagenedb.py
0 → 100644
View file @
ad8a488c
"""
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
)
ci/kubernetes/backend.yaml
View file @
ad8a488c
...
...
@@ -49,8 +49,6 @@ spec:
value
:
'
6379'
-
name
:
PORT
value
:
"
8000"
-
name
:
DEBUG
value
:
"
True"
ports
:
-
containerPort
:
8000
resources
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment