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

Change gene_id to slugfield

parent e2f7adf6
Pipeline #13925 passed with stages
in 2 minutes and 8 seconds
......@@ -52,6 +52,7 @@ PyJWT = "*"
metagenedb = {editable = true,path = "."}
drf-yasg = "*"
packaging = "*"
python-slugify = "*"
[requires]
python_version = "3.7"
{
"_meta": {
"hash": {
"sha256": "d669f354e8994bdf3d7ba50fa5966b453792364ae116e1efbf8460a33b1fa4f9"
"sha256": "8c5558c05e9194e5413000349af9f264e61330fd1b4bd37e1fdb1e5579b361f5"
},
"pipfile-spec": 6,
"requires": {
......@@ -63,11 +63,11 @@
},
"django-cors-headers": {
"hashes": [
"sha256:5b80bf0f8d7fc6e2bcb4f40781d5ff3661961bbf1982e52daec77241dea3b890",
"sha256:ebf3e2cf25aa6993b959a8e6a87828ebb3c8fe5bc3ec4a2d6e65f3b8d9b4212c"
"sha256:e4b12209b3a0bc577883fe0ac0aa3adac9e82742389f8ddb6c6b41c66b1e9c4f",
"sha256:e69b1c909f2eddc7ef2a24f071583bc22b73b871731ea3370ac52b3318c43b3c"
],
"index": "pypi",
"version": "==3.0.2"
"version": "==3.1.0"
},
"django-environ": {
"hashes": [
......@@ -271,6 +271,13 @@
"index": "pypi",
"version": "==2.8.0"
},
"python-slugify": {
"hashes": [
"sha256:a9f468227cb11e20e251670d78e1b5f6b0b15dd37bbd5c9814a25a904e44ff66"
],
"index": "pypi",
"version": "==3.0.3"
},
"pytz": {
"hashes": [
"sha256:26c0b32e437e54a18161324a2fca3c4b9846b74a8dccddd843113109e1116b32",
......@@ -289,9 +296,10 @@
},
"ruamel.yaml": {
"hashes": [
"sha256:547aeab5c51c93bc750ed2a320c1559b605bde3aa569216aa75fd91d8a1c4623"
"sha256:0db639b1b2742dae666c6fc009b8d1931ef15c9276ef31c0673cc6dcf766cf40",
"sha256:412a6f5cfdc0525dee6a27c08f5415c7fd832a7afcb7a0ed7319628aed23d408"
],
"version": "==0.16.1"
"version": "==0.16.5"
},
"ruamel.yaml.clib": {
"hashes": [
......@@ -314,6 +322,7 @@
"sha256:ef8d4522d231cb9b29f6cdd0edc8faac9d9715c60dc7becbd6eb82c915a98e5b",
"sha256:f504d45230cc9abf2810623b924ae048b224a90adb01f97db4e766cfdda8e6eb"
],
"markers": "platform_python_implementation == 'CPython' and python_version < '3.8'",
"version": "==0.1.2"
},
"six": {
......@@ -332,6 +341,13 @@
"index": "pypi",
"version": "==0.3.0"
},
"text-unidecode": {
"hashes": [
"sha256:5a1375bb2ba7968740508ae38d92e1f889a0832913cb1c447d5e2046061a396d",
"sha256:801e38bd550b943563660a91de8d4b6fa5df60a542be9093f7abf819f86050cc"
],
"version": "==1.2"
},
"uritemplate": {
"hashes": [
"sha256:01c69f4fe8ed503b2951bef85d996a9d22434d2431584b5b107b2981ff416fbd",
......@@ -465,10 +481,10 @@
},
"faker": {
"hashes": [
"sha256:96ad7902706f2409a2d0c3de5132f69b413555a419bacec99d3f16e657895b47",
"sha256:b3bb64aff9571510de6812df45122b633dbc6227e870edae3ed9430f94698521"
"sha256:1d3f700e8dfcefd6e657118d71405d53e86974448aba78884f119bbd84c0cddf",
"sha256:d5366e120191c5610fceeebfe1c298dc46da0277096f639c6dd7e2eaee0fa547"
],
"version": "==2.0.0"
"version": "==2.0.1"
},
"flake8": {
"hashes": [
......@@ -523,10 +539,10 @@
},
"jedi": {
"hashes": [
"sha256:53c850f1a7d3cfcd306cc513e2450a54bdf5cacd7604b74e42dd1f0758eaaf36",
"sha256:e07457174ef7cb2342ff94fa56484fe41cec7ef69b0059f01d3f812379cb6f7c"
"sha256:786b6c3d80e2f06fd77162a07fed81b8baa22dde5d62896a790a331d6ac21a27",
"sha256:ba859c74fa3c966a22f2aeebe1b74ee27e2a462f56d3f5f7ca4a59af61bfe42e"
],
"version": "==0.14.1"
"version": "==0.15.1"
},
"jinja2": {
"hashes": [
......@@ -664,10 +680,10 @@
},
"nbconvert": {
"hashes": [
"sha256:138381baa41d83584459b5cfecfc38c800ccf1f37d9ddd0bd440783346a4c39c",
"sha256:4a978548d8383f6b2cfca4a3b0543afb77bc7cb5a96e8b424337ab58c12da9bc"
"sha256:427a468ec26e7d68a529b95f578d5cbf018cb4c1f889e897681c2b6d11897695",
"sha256:48d3c342057a2cf21e8df820d49ff27ab9f25fc72b8f15606bd47967333b2709"
],
"version": "==5.5.0"
"version": "==5.6.0"
},
"nbformat": {
"hashes": [
......@@ -678,10 +694,10 @@
},
"notebook": {
"hashes": [
"sha256:0be97e939cec73cde37fc4d2a606a6f497a9addf3afcf61a09a21b0c35e699c5",
"sha256:5c16dbf4fa824db19de43637ebfb24bcbd3b4f646e5d6a0414ed3a376d6bc951"
"sha256:660976fe4fe45c7aa55e04bf4bccb9f9566749ff637e9020af3422f9921f9a5d",
"sha256:b0a290f5cc7792d50a21bec62b3c221dd820bf00efa916ce9aeec4b5354bde20"
],
"version": "==6.0.0"
"version": "==6.0.1"
},
"packaging": {
"hashes": [
......@@ -795,11 +811,11 @@
},
"pytest": {
"hashes": [
"sha256:6ef6d06de77ce2961156013e9dff62f1b2688aa04d0dc244299fe7d67e09370d",
"sha256:a736fed91c12681a7b34617c8fcefe39ea04599ca72c608751c31d89579a3f77"
"sha256:95b1f6db806e5b1b5b443efeb58984c24945508f93a866c1719e1a507a957d7c",
"sha256:c3d5020755f70c82eceda3feaf556af9a341334414a8eca521a18f463bcead88"
],
"index": "pypi",
"version": "==5.0.1"
"version": "==5.1.1"
},
"pytest-cov": {
"hashes": [
......@@ -864,10 +880,10 @@
},
"qtconsole": {
"hashes": [
"sha256:6a85456af7a98b0f554d140922b7b6a219757b039adb2b95e847cf115eaa20ae",
"sha256:767eb9ec3f9943bc84270198b5ff95d2d86d68d6b57792fafa4df4fc6b16cd7c"
"sha256:40f53ab58ef77aa4b53aca1ee314eed873d05952dec22d2ab84d20660943b7de",
"sha256:756bdcb6de6900dc50b14430accff2e47b846c3e7820e04075d4067b4c0ab52f"
],
"version": "==4.5.2"
"version": "==4.5.4"
},
"send2trash": {
"hashes": [
......
......@@ -3,7 +3,6 @@ from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from rest_framework import status
from rest_framework.decorators import action
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
......@@ -45,6 +44,7 @@ class DocGeneLength(object):
class GeneViewSet(ModelViewSet):
queryset = Gene.objects.all()
serializer_class = GeneSerializer
lookup_field = 'gene_id'
GENE_LENGTH_COL = 'length'
def get_permissions(self):
......
......@@ -6,8 +6,8 @@ from metagenedb.apps.catalog.models import Gene
@admin.register(Gene)
class GeneAdmin(admin.ModelAdmin):
list_display = ('gene_id', 'length', 'get_functions', 'get_taxonomy')
search_fields = ('gene_id',)
list_display = ('gene_id', 'gene_name', 'length', 'get_functions', 'get_taxonomy')
search_fields = ('gene_name',)
def get_functions(self, obj):
if obj.functions.all():
......
# Generated by Django 2.2.4 on 2019-08-22 13:43
from django.db import migrations, models
from slugify import slugify
def populate_slug_field(apps, schema_editor):
Gene = apps.get_model('catalog', 'Gene')
for gene in Gene.objects.all():
gene.gene_name = gene.gene_id
gene.gene_id = slugify(gene.gene_name)
gene.save()
class Migration(migrations.Migration):
dependencies = [
('catalog', '0007_length_name_and_positive_int'),
]
operations = [
migrations.AlterField(
model_name='gene',
name='gene_id',
field=models.SlugField(max_length=100, unique=True),
),
migrations.AddField(
model_name='gene',
name='gene_name',
field=models.CharField(max_length=100, default="name"),
preserve_default=False,
),
migrations.RunPython(populate_slug_field),
migrations.AlterField(
model_name='gene',
name='gene_name',
field=models.CharField(max_length=100, unique=True),
),
]
......@@ -4,7 +4,8 @@ from .function import Function
class Gene(models.Model):
gene_id = models.CharField(max_length=100, unique=True, db_index=True)
gene_name = models.CharField(max_length=100, unique=True)
gene_id = models.SlugField(max_length=100, unique=True)
length = models.PositiveIntegerField()
functions = models.ManyToManyField(Function)
taxonomy = models.ForeignKey(
......@@ -14,7 +15,7 @@ class Gene(models.Model):
)
def __str__(self):
return self.gene_id
return self.gene_slug
class Meta:
ordering = ['-gene_id']
......@@ -13,4 +13,4 @@ class GeneSerializer(serializers.ModelSerializer):
class Meta:
model = Gene
fields = ('gene_id', 'length', 'functions', 'taxonomy')
fields = ('gene_id', 'gene_name', 'length', 'functions', 'taxonomy')
......@@ -73,6 +73,7 @@ class TestUpsertGene(APITestCase):
def test_insert_valid_gene_no_kegg(self):
valid_gene = {
'gene_name': 'test_gene.01',
'gene_id': 'test_gene01',
'length': 3556
}
......@@ -89,10 +90,12 @@ class TestUpsertGene(APITestCase):
def test_update_gene(self):
valid_gene = {
'gene_name': 'test_gene.01',
'gene_id': 'test_gene01',
'length': 3556
}
updated_gene = {
'gene_name': 'test_gene.01',
'gene_id': 'test_gene01',
'length': 356
}
......
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