Browse Source

Merge pull request #1161 from doccano/fix/#713

Fix 500 error after project creation
pull/1165/head
Hiroki Nakayama 3 years ago
committed by GitHub
parent
commit
e33f0fde8e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 41 deletions
  1. 21
      app/api/models.py
  2. 8
      app/api/serializers.py
  3. 16
      app/api/tests/test_models.py

21
app/api/models.py

@ -6,7 +6,6 @@ from django.db.models.signals import post_save, pre_delete
from django.urls import reverse
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.staticfiles.storage import staticfiles_storage
from django.core.exceptions import ValidationError
from polymorphic.models import PolymorphicModel
@ -39,10 +38,6 @@ class Project(PolymorphicModel):
def get_absolute_url(self):
return reverse('upload', args=[self.id])
@property
def image(self):
raise NotImplementedError()
def get_bundle_name(self):
raise NotImplementedError()
@ -67,10 +62,6 @@ class Project(PolymorphicModel):
class TextClassificationProject(Project):
@property
def image(self):
return staticfiles_storage.url('assets/images/cats/text_classification.jpg')
def get_bundle_name(self):
return 'document_classification'
@ -94,10 +85,6 @@ class TextClassificationProject(Project):
class SequenceLabelingProject(Project):
@property
def image(self):
return staticfiles_storage.url('assets/images/cats/sequence_labeling.jpg')
def get_bundle_name(self):
return 'sequence_labeling'
@ -121,10 +108,6 @@ class SequenceLabelingProject(Project):
class Seq2seqProject(Project):
@property
def image(self):
return staticfiles_storage.url('assets/images/cats/seq2seq.jpg')
def get_bundle_name(self):
return 'seq2seq'
@ -148,10 +131,6 @@ class Seq2seqProject(Project):
class Speech2textProject(Project):
@property
def image(self):
return staticfiles_storage.url('images/cats/speech2text.jpg')
def get_bundle_name(self):
return 'speech2text'

8
app/api/serializers.py

@ -119,9 +119,9 @@ class ProjectSerializer(serializers.ModelSerializer):
class Meta:
model = Project
fields = ('id', 'name', 'description', 'guideline', 'users', 'current_users_role', 'project_type', 'image',
fields = ('id', 'name', 'description', 'guideline', 'users', 'current_users_role', 'project_type',
'updated_at', 'randomize_document_order', 'collaborative_annotation', 'single_class_classification')
read_only_fields = ('image', 'updated_at', 'users', 'current_users_role')
read_only_fields = ('updated_at', 'users', 'current_users_role')
class TextClassificationProjectSerializer(ProjectSerializer):
@ -152,9 +152,9 @@ class Speech2textProjectSerializer(ProjectSerializer):
class Meta:
model = Speech2textProject
fields = ('id', 'name', 'description', 'guideline', 'users', 'current_users_role', 'project_type', 'image',
fields = ('id', 'name', 'description', 'guideline', 'users', 'current_users_role', 'project_type',
'updated_at', 'randomize_document_order')
read_only_fields = ('image', 'updated_at', 'users', 'current_users_role')
read_only_fields = ('updated_at', 'users', 'current_users_role')
class ProjectPolymorphicSerializer(PolymorphicSerializer):

16
app/api/tests/test_models.py

@ -17,10 +17,6 @@ class TestTextClassificationProject(TestCase):
def setUpTestData(cls):
cls.project = mommy.make('TextClassificationProject')
def test_image(self):
image_url = self.project.image
self.assertTrue(image_url.endswith('.jpg'))
def test_get_bundle_name(self):
template = self.project.get_bundle_name()
self.assertEqual(template, 'document_classification')
@ -41,10 +37,6 @@ class TestSequenceLabelingProject(TestCase):
def setUpTestData(cls):
cls.project = mommy.make('SequenceLabelingProject')
def test_image(self):
image_url = self.project.image
self.assertTrue(image_url.endswith('.jpg'))
def test_get_bundle_name(self):
template = self.project.get_bundle_name()
self.assertEqual(template, 'sequence_labeling')
@ -65,10 +57,6 @@ class TestSeq2seqProject(TestCase):
def setUpTestData(cls):
cls.project = mommy.make('Seq2seqProject')
def test_image(self):
image_url = self.project.image
self.assertTrue(image_url.endswith('.jpg'))
def test_get_bundle_name(self):
template = self.project.get_bundle_name()
self.assertEqual(template, 'seq2seq')
@ -89,10 +77,6 @@ class TestSpeech2textProject(TestCase):
def setUpTestData(cls):
cls.project = mommy.make('Speech2textProject')
def test_image(self):
image_url = self.project.image
self.assertTrue(image_url.endswith('.jpg'))
def test_get_bundle_name(self):
template = self.project.get_bundle_name()
self.assertEqual(template, 'speech2text')

Loading…
Cancel
Save