Enhancement/Remove Django template inheritance from annotation pages#159
Merged
Hironsan merged 6 commits intodoccano:masterfrom Apr 25, 2019
Conversation
Hironsan
reviewed
Apr 15, 2019
Member
bcfaad4 to
2bdcada
Compare
Member
Author
|
@Hironsan Thanks for the initial review. Could you share the data file (or a subset thereof) that exhibits the strange behavior in the sequence labeling project? |
Member
Member
Author
Member
Author
|
Based on the work in this pull request, I now also have a branch that moves the admin pages to Vue single-file components (see diff). I will submit these changes once this PR is fully discussed, reviewed and merged. |
ac4292b to
88a4826
Compare
Member
Author
|
@Hironsan Just following up on this pull request. Do you have any further questions or concerns about this change that I can help address? |
Member
Author
|
Thanks for the merge! I've now also submitted the follow-up PR which applies the same refactor to the admin pages. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


This pull request is a follow-up to #148 and moves the annotation pages to Vue single-file components. This change also fully decouples the Vue frontend for the annotation from the Django server by removing all usage of Django block-based template inheritance.
The main approach to removing the Django template inheritance is modeled after the article Extending VueJS Components and leverages the Pug pre-processor for Vue templates.
In the future, a separate refactor could further simplify the approach and remove Pug in favor of splitting the Vue components into smaller independent pieces and using slots for the content composition. This would be cleaner overall solution, but it would also be a much more invasive refactoring. In any case, I believe Pug is a good step in the right direction and will make these future refactorings easier since now all the templating code is in Vue. Having all the templating code in Vue also makes other efforts such as component re-use or testing much simpler. Alternatively, if the project decides that Pug offers value on its own due to its improved terseness over plain HTML templates, other Vue components could also be converted to Pug in the future to make the codebase more uniform.
The Pug approach demonstrated in this pull request can also be extended to the admin pages in Doccano, for example to replace the Django template inheritance on the upload and download screens, but I haven't tackled this yet.
Unfortunately the pull request diff is somewhat large, so please don't hesitate to reach out with questions or comments. However, most of the changes made were very mechanical and so the overall pull request should be low risk. See below for an outline of the refactoring approach. Steps 1-3 below are in commit d5bc9e4. Step 4 is commit bcfaad4.
For each webpack bundle, copy the source Javascript file into the
<script>section of a new Vue single file component. Keep all the code associated with creating a new Vue instance in the webpack bundle Javascript file and remove those lines from the Vue single file component so that the file only exports a pure Vue component without any side-effects.For each Django base template (e.g.
annotation_base.html), move all HTML associated with a Vue template into a Pug file. Convert all the HTML to the equivalent Pug code and replace each Django block with a Pug block.For each Django leaf template (e.g.
document_classification.html), move all HTML associated with a Vue template to the<template>section of the appropriate Vue single file component. If the Django template referenced a block, convert the HTML to Pug and extend the appropriate Pug base template.All the Django leaf templates now only differ in the webpack bundle they include to scaffold the page, so delete them all in favor of a single base template which uses the Django context to configure which webpack bundle should be injected. Update all the views in Django to use the new base template and set the appropriate context variable for the webpack include.
In order to ensure that all Pug templates remain high quality going forward, I've also added a linter for Pug in commit ab473e3.