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

update filters and use from frontend

parent 580c2bdf
Pipeline #53863 failed with stages
in 3 minutes and 45 seconds
......@@ -24,6 +24,9 @@ class GeneFilter(filters.FilterSet):
tax_id = filters.CharFilter(
method='filter_annotated_tax'
)
source = filters.CharFilter(
field_name="source__slug"
)
function = filters.ModelMultipleChoiceFilter(
queryset=Function.objects.all(),
field_name='functions__function_id',
......@@ -37,4 +40,4 @@ class GeneFilter(filters.FilterSet):
class Meta:
model = Gene
fields = ['length', 'name', 'source']
fields = ['length', 'name']
......@@ -61,6 +61,7 @@ api_router.register(r'kegg-orthologies', views.KeggOrthologyViewSet, basename='k
api_router.register(r'eggnogs', views.EggNOGViewSet, basename='eggnogs')
api_router.register(r'genes', views.GeneViewSet, basename='genes')
api_router.register(r'taxonomy', views.TaxonomyViewSet, basename='taxonomy')
api_router.register(r'sources', views.SourceViewSet, basename='sources')
api_router.register(r'statistics', views.StatisticsViewSet, basename='statistics')
......
from .function import EggNOGViewSet, KeggOrthologyViewSet, FunctionViewSet # noqa
from .gene import GeneViewSet # noqa
from .statistics import StatisticsViewSet # noqa
from .source import SourceViewSet # noqa
from .taxonomy import TaxonomyViewSet # noqa
from drf_yasg.utils import swagger_auto_schema
from metagenedb.apps.catalog.models import Source
from metagenedb.apps.catalog.serializers import SourceSerializer
from .base import BulkViewSet
class SourceViewSet(BulkViewSet):
queryset = Source.objects.all()
serializer_class = SourceSerializer
lookup_field = 'slug'
@swagger_auto_schema(
operation_description="List all gene sources",
operation_summary="API to list all gene sources of the catalog.",
tags=['Source'],
)
def list(self, *args, **kwargs):
return super().list(*args, **kwargs)
@swagger_auto_schema(
operation_description="Retrieve gene source from a name",
operation_summary="API to retrieve gene source.",
tags=['Source'],
)
def retrieve(self, *args, **kwargs):
return super().retrieve(*args, **kwargs)
@swagger_auto_schema(
tags=['Source'],
)
def create(self, *args, **kwargs):
return super().create(*args, **kwargs)
@swagger_auto_schema(
tags=['Source'],
)
def update(self, *args, **kwargs):
return super().update(*args, **kwargs)
@swagger_auto_schema(
tags=['Source'],
)
def partial_update(self, *args, **kwargs):
return super().partial_update(*args, **kwargs)
......@@ -5,5 +5,5 @@ from metagenedb.apps.catalog.models import Source
@admin.register(Source)
class SourceAdmin(admin.ModelAdmin):
list_display = ('name', 'url', 'doi')
list_display = ('name', 'slug', 'url', 'doi')
search_fields = ('name',)
# Generated by Django 3.1.7 on 2021-04-15 13:16
from django.db import migrations, models
from slugify import slugify
def add_slug(apps, schema_editor):
Source = apps.get_model('catalog', 'Source')
for item in Source.objects.all():
item.slug = slugify(item.name)
item.save()
class Migration(migrations.Migration):
dependencies = [
('catalog', '0029_source'),
]
operations = [
migrations.AddField(
model_name='source',
name='slug',
field=models.CharField(db_index=True, max_length=100, unique=True, null=True),
preserve_default=False,
),
migrations.RunPython(add_slug),
migrations.AlterField(
model_name='source',
name='slug',
field=models.CharField(db_index=True, max_length=100, unique=True),
),
]
from django.db import models
from slugify import slugify
class Source(models.Model):
name = models.CharField(max_length=100, unique=True, db_index=True)
slug = models.CharField(max_length=100, unique=True, db_index=True)
url = models.CharField(max_length=100, blank=True)
doi = models.CharField(max_length=100, blank=True)
tools = models.JSONField(blank=True, null=True)
def save(self, *args, **kwargs):
self.slug=slugify(self.name)
super(Source, self).save(*args, **kwargs)
def __str__(self):
return f"{self.name}"
from .function import EggNOGSerializer, FunctionSerializer, KeggOrthologySerializer # noqa
from .gene import GeneSerializer # noqa
from .statistics import StatisticsSerializer # noqa
from .source import SourceSerializer # noqa
from .taxonomy import TaxonomySerializer # noqa
......@@ -7,5 +7,5 @@ class SourceSerializer(serializers.ModelSerializer):
class Meta:
model = Source
fields = (
'name', 'url', 'doi'
'name', 'slug', 'url', 'doi'
)
......@@ -66,7 +66,7 @@
<!-- Gene source -->
<v-flex xs12 sm6 md4 lg2>
<v-select
:items="geneSources"
:items="Object.keys(geneSources)"
v-model="geneSource"
label="Gene source"
@input="getTaxoPresenceOptional"
......
......@@ -21,6 +21,8 @@ export default {
searchGeneName: null,
filterGeneLength: false,
geneLengthFilterRange: [0, 2000],
// - Source
geneSources: {},
// - Taxonomy
taxLevel: null,
taxItems: [],
......@@ -63,12 +65,6 @@ export default {
];
return this.formatList(texts);
},
geneSources() {
const texts = [
'IGC', 'Virgo',
];
return this.formatList(texts);
},
rowsPerPageItems() {
return [this.page_size];
},
......@@ -78,7 +74,7 @@ export default {
page: this.pageNumber
};
if (this.geneSource && this.geneSource != 'all') {
qParams.source = this.geneSource
qParams.source = this.geneSources[this.geneSource];
}
if (this.filterGeneLength) {
qParams.length__gt = this.geneLengthFilterRange[0];
......@@ -199,6 +195,7 @@ export default {
}
},
mounted() {
this.getSources();
this.getGenes();
},
methods: {
......@@ -270,6 +267,23 @@ export default {
this.requestDone = true;
});
},
getSources() {
axios.get('/api/catalog/v1/sources', {
params: this.qParams,
headers: {
Accept: 'application/json',
},
})
.then((response) => {
const sources = response.data.results;
sources.forEach((item, index) => {
this.geneSources[item.name] = item.slug;
});
})
.catch((error) => {
console.error(error);
});
},
forceFileDownload(response, fileName){
const url = window.URL.createObjectURL(new Blob([response.data]))
const link = document.createElement('a')
......
Markdown is supported
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