Skip to content
GitLab
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
3ed89f51
Commit
3ed89f51
authored
Jun 04, 2020
by
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
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
backend/metagenedb/api/catalog/views/function.py
View file @
3ed89f51
...
...
@@ -57,7 +57,7 @@ class FunctionViewSet(BulkViewSet):
return
super
().
partial_update
(
*
args
,
**
kwargs
)
class
KeggOrthologyViewSet
(
QParamsValidation
ViewSet
):
class
KeggOrthologyViewSet
(
Bulk
ViewSet
):
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
(
QParamsValidation
ViewSet
):
class
EggNOGViewSet
(
Bulk
ViewSet
):
queryset
=
EggNOG
.
objects
.
all
()
serializer_class
=
EggNOGSerializer
lookup_field
=
'function_id'
...
...
backend/metagenedb/api/catalog/views/statistics.py
View file @
3ed89f51
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'
@
swagger_auto_schema
(
...
...
@@ -15,18 +18,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
)
backend/metagenedb/apps/catalog/admin/__init__.py
View file @
3ed89f51
from
.gene
import
GeneAdmin
# noqa
from
.function
import
FunctionAdmin
,
KeggOrthologyAdmin
# noqa
from
.statistics
import
Statistics
# noqa
from
.taxonomy
import
TaxonomyAdmin
# noqa
backend/metagenedb/apps/catalog/admin/statistics.py
0 → 100644
View file @
3ed89f51
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'
,)
backend/metagenedb/apps/catalog/models/statistics.py
View file @
3ed89f51
...
...
@@ -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"
backend/metagenedb/common/django_default/permissions.py
View file @
3ed89f51
...
...
@@ -7,4 +7,7 @@ class ListAndRetrieveAll(BasePermission):
"""
def
has_permission
(
self
,
request
,
view
):
print
(
view
.
action
)
print
(
view
.
action
in
[
'list'
,
'retrieve'
])
print
(
request
.
user
.
is_staff
)
return
view
.
action
in
[
'list'
,
'retrieve'
]
or
request
.
user
.
is_staff
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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