Browse Source

Collapse Django annotation templates

pull/159/head
Clemens Wolff 5 years ago
parent
commit
2bdcada9a7
10 changed files with 37 additions and 57 deletions
  1. 14
      app/server/models.py
  2. 4
      app/server/templates/annotation.html
  3. 6
      app/server/templates/annotation/document_classification.html
  4. 6
      app/server/templates/annotation/seq2seq.html
  5. 6
      app/server/templates/annotation/sequence_labeling.html
  6. 6
      app/server/templates/demo/demo_named_entity.html
  7. 6
      app/server/templates/demo/demo_text_classification.html
  8. 6
      app/server/templates/demo/demo_translation.html
  9. 18
      app/server/tests/test_models.py
  10. 22
      app/server/views.py

14
app/server/models.py

@ -33,7 +33,7 @@ class Project(PolymorphicModel):
def image(self):
raise NotImplementedError()
def get_template_name(self):
def get_bundle_name(self):
raise NotImplementedError()
def get_upload_template(self):
@ -61,8 +61,8 @@ class TextClassificationProject(Project):
def image(self):
return staticfiles_storage.url('images/cats/text_classification.jpg')
def get_template_name(self):
return 'annotation/document_classification.html'
def get_bundle_name(self):
return 'document_classification'
def get_upload_template(self):
return 'admin/upload/text_classification.html'
@ -88,8 +88,8 @@ class SequenceLabelingProject(Project):
def image(self):
return staticfiles_storage.url('images/cats/sequence_labeling.jpg')
def get_template_name(self):
return 'annotation/sequence_labeling.html'
def get_bundle_name(self):
return 'sequence_labeling'
def get_upload_template(self):
return 'admin/upload/sequence_labeling.html'
@ -115,8 +115,8 @@ class Seq2seqProject(Project):
def image(self):
return staticfiles_storage.url('images/cats/seq2seq.jpg')
def get_template_name(self):
return 'annotation/seq2seq.html'
def get_bundle_name(self):
return 'seq2seq'
def get_upload_template(self):
return 'admin/upload/seq2seq.html'

app/server/templates/annotation/annotation_base.html → app/server/templates/annotation.html

@ -1,5 +1,6 @@
{% extends "base.html" %}
{% load static %}
{% load render_bundle from webpack_loader %}
{% block header %}
<link rel="stylesheet" href="{% static 'css/annotation.css' %}">
{% endblock %}
@ -16,3 +17,6 @@
{% block content %}
<div id="mail-app"></div>
{% endblock %}
{% block footer %}
{% render_bundle bundle_name 'js' %}
{% endblock %}

6
app/server/templates/annotation/document_classification.html

@ -1,6 +0,0 @@
{% extends "annotation/annotation_base.html" %}
{% load static %}
{% load render_bundle from webpack_loader %}
{% block footer %}
{% render_bundle 'document_classification' 'js' %}
{% endblock %}

6
app/server/templates/annotation/seq2seq.html

@ -1,6 +0,0 @@
{% extends "annotation/annotation_base.html" %}
{% load static %}
{% load render_bundle from webpack_loader %}
{% block footer %}
{% render_bundle 'seq2seq' 'js' %}
{% endblock %}

6
app/server/templates/annotation/sequence_labeling.html

@ -1,6 +0,0 @@
{% extends "annotation/annotation_base.html" %}
{% load static %}
{% load render_bundle from webpack_loader %}
{% block footer %}
{% render_bundle 'sequence_labeling' 'js' %}
{% endblock %}

6
app/server/templates/demo/demo_named_entity.html

@ -1,6 +0,0 @@
{% extends "annotation/annotation_base.html" %}
{% load static %}
{% load render_bundle from webpack_loader %}
{% block footer %}
{% render_bundle 'demo_named_entity' 'js' %}
{% endblock %}

6
app/server/templates/demo/demo_text_classification.html

@ -1,6 +0,0 @@
{% extends "annotation/annotation_base.html" %}
{% load static %}
{% load render_bundle from webpack_loader %}
{% block footer %}
{% render_bundle 'demo_text_classification' 'js' %}
{% endblock %}

6
app/server/templates/demo/demo_translation.html

@ -1,6 +0,0 @@
{% extends "annotation/annotation_base.html" %}
{% load static %}
{% load render_bundle from webpack_loader %}
{% block footer %}
{% render_bundle 'demo_translation' 'js' %}
{% endblock %}

18
app/server/tests/test_models.py

@ -19,9 +19,9 @@ class TestTextClassificationProject(TestCase):
image_url = self.project.image
self.assertTrue(image_url.endswith('.jpg'))
def test_get_template_name(self):
template = self.project.get_template_name()
self.assertEqual(template, 'annotation/document_classification.html')
def test_get_bundle_name(self):
template = self.project.get_bundle_name()
self.assertEqual(template, 'document_classification')
def test_get_annotation_serializer(self):
serializer = self.project.get_annotation_serializer()
@ -42,9 +42,9 @@ class TestSequenceLabelingProject(TestCase):
image_url = self.project.image
self.assertTrue(image_url.endswith('.jpg'))
def test_get_template_name(self):
template = self.project.get_template_name()
self.assertEqual(template, 'annotation/sequence_labeling.html')
def test_get_bundle_name(self):
template = self.project.get_bundle_name()
self.assertEqual(template, 'sequence_labeling')
def test_get_annotation_serializer(self):
serializer = self.project.get_annotation_serializer()
@ -65,9 +65,9 @@ class TestSeq2seqProject(TestCase):
image_url = self.project.image
self.assertTrue(image_url.endswith('.jpg'))
def test_get_template_name(self):
template = self.project.get_template_name()
self.assertEqual(template, 'annotation/seq2seq.html')
def test_get_bundle_name(self):
template = self.project.get_bundle_name()
self.assertEqual(template, 'seq2seq')
def test_get_annotation_serializer(self):
serializer = self.project.get_annotation_serializer()

22
app/server/views.py

@ -18,10 +18,13 @@ class IndexView(TemplateView):
class ProjectView(LoginRequiredMixin, TemplateView):
template_name = 'annotation.html'
def get_template_names(self):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
project = get_object_or_404(Project, pk=self.kwargs['project_id'])
return [project.get_template_name()]
context['bundle_name'] = project.get_bundle_name()
return context
class ProjectsView(LoginRequiredMixin, TemplateView):
@ -79,12 +82,21 @@ class LoginView(BaseLoginView):
class DemoTextClassification(TemplateView):
template_name = 'demo/demo_text_classification.html'
template_name = 'annotation.html'
extra_context = {
'bundle_name': 'demo_text_classification',
}
class DemoNamedEntityRecognition(TemplateView):
template_name = 'demo/demo_named_entity.html'
template_name = 'annotation.html'
extra_context = {
'bundle_name': 'demo_named_entity',
}
class DemoTranslation(TemplateView):
template_name = 'demo/demo_translation.html'
template_name = 'annotation.html'
extra_context = {
'bundle_name': 'demo_translation',
}
Loading…
Cancel
Save