Skip to content

Remove Jinja and use Tornado templates#521

Merged
stefanoborini merged 9 commits into
masterfrom
remove-jinja
Jun 26, 2017
Merged

Remove Jinja and use Tornado templates#521
stefanoborini merged 9 commits into
masterfrom
remove-jinja

Conversation

@martinRenou

@martinRenou martinRenou commented Jun 13, 2017

Copy link
Copy Markdown
Member

Closes #474

@web.authenticated
@gen.coroutine
def get(self):
self.render('admin/page.html')

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the name of the admin and user page files because when doing {% extends "page.html" %} they were loading themselves resulting on an infinite loop.

@@ -1,6 +1,6 @@
{% extends "page.html" %}

{% set skin = "skin-red" %}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With tornado {% set skin = ... %} only sets a local variable which is not available in the parent scope. Unfortunately, according to tornadoweb/tornado#1323, an equivalent implementation in Tornado of the behavior of Jinja is not available yet. A workaround is to use a block.

{{message}}
</p>
{% endif %}
{% if message_html %}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find any other reference to message_html, maybe an old unused anymore variable ?


<script src="{{ static_url("dist/sharedDependencies.js") }}"></script>

<script type="text/javascript">

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In tornado we don't have the possibility to call super () in blocks, moving this script out of the block script_init was the only solution that I found.

@codecov-io

codecov-io commented Jun 13, 2017

Copy link
Copy Markdown

Codecov Report

Merging #521 into master will decrease coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #521      +/-   ##
==========================================
- Coverage   95.25%   95.18%   -0.07%     
==========================================
  Files          88       85       -3     
  Lines        3961     3905      -56     
  Branches      248      247       -1     
==========================================
- Hits         3773     3717      -56     
  Misses        137      137              
  Partials       51       51
Impacted Files Coverage Δ
remoteappmanager/base_application.py 97.46% <ø> (-0.21%) ⬇️
remoteappmanager/handlers/base_handler.py 96.77% <100%> (+0.1%) ⬆️
...oteappmanager/handlers/admin/admin_home_handler.py 100% <100%> (ø) ⬆️
remoteappmanager/handlers/user_home_handler.py 100% <100%> (ø) ⬆️
remoteappmanager/tests/fixtures/templates/foo.html

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7482382...57153cf. Read the comment docs.

<script type="text/javascript">
window.apidata = {
base_url: "{{base_url}}",
prefix: "{{prefix}}",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, I couldn't find any other reference to prefix

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jinja wasn't complaining but tornado is less permissive. With tornado code in the brackets is python code so it raises a name "prefix" is not defined

@stefanoborini stefanoborini self-requested a review June 19, 2017 10:15
@stefanoborini

Copy link
Copy Markdown
Contributor

Checked it once. I am unsure about a few things. Leaving for later.

Comment thread remoteappmanager/templates/page.html Outdated
</li>
</ul>
</div>
{% if user is not None %}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do we have user == None? (maybe we already talked about it, but I don't remember)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had it when rendering the error.html template

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, that's suspicious... why?

@martinRenou martinRenou Jun 26, 2017

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I shouldn't because the render function sets the user. So maybe I'm wrong, maybe I had an other reason but I can't remember..

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I suspect that it's because if you login and another user connects to the server, user is not defined (you are not passing the right credentials for the process) and in that case you issue an error message. but the error message cannot be shown because it depends on a template that requires the user.

So the best solution is to have an error message with a different base template.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do that in this PR ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please, it makes sense that we rationalise our templates. They are going away anyway, but as a stepstone it's probably the best strategy

@stefanoborini stefanoborini merged commit ae815bb into master Jun 26, 2017
@stefanoborini stefanoborini deleted the remove-jinja branch June 26, 2017 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants