Always add Matemat version number to Jinja template.

This commit is contained in:
s3lph 2018-07-09 22:46:35 +02:00
parent 1b00c80133
commit 0481b5bf98
5 changed files with 32 additions and 46 deletions

View file

@ -1,6 +1,8 @@
from jinja2 import Environment, Template
from matemat import __version__
class PageletResponse:
"""
@ -60,4 +62,4 @@ class TemplateResponse(PageletResponse):
:return: An UTF-8 encoded bytes object containing the template rendering result.
"""
template: Template = jinja_env.get_template(self.name)
return template.render(**self.kwargs).encode('utf-8')
return template.render(**self.kwargs, __version__=__version__).encode('utf-8')

17
templates/base.html Normal file
View file

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>Matemat</title>
<style>
body {
color: #f0f0f0;
background: #000000;
}
</style>
</head>
<body>
<h1>Matemat {{__version__}}</h1>
{% block main %}
{% endblock %}
</body>
</html>

View file

@ -1,20 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Matemat</title>
<style>
body {
color: #f0f0f0;
background: #000000;
}
</style>
</head>
<body>
<h1>Matemat</h1>
{% extends "base.html" %}
{% block main %}
<form action="/login" method="post">
Username: <input type="text" name="username"/><br/>
Password: <input type="password" name="password" /><br/>
<input type="submit" value="Login"/>
</form>
</body>
</html>
{% endblock%}

View file

@ -1,16 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<title>Matemat</title>
<style>
body {
color: #f0f0f0;
background: #000000;
}
</style>
</head>
<body>
<h1>Matemat</h1>
{% extends "base.html" %}
{% block main %}
{{ user|default("") }}
<ul>
{% if user is defined %}
@ -29,5 +19,4 @@
<li/> <a href="/login">Password login</a>
{% endif %}
</ul>
</body>
</html>
{% endblock %}

View file

@ -1,20 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Matemat</title>
<style>
body {
color: #f0f0f0;
background: #000000;
}
</style>
</head>
<body>
<h1>Matemat</h1>
{% extends "base.html" %}
{% block main %}
<form action="/touchkey" method="post">
<input type="hidden" name="username" value="{{ username }}"/><br/>
Touchkey: <input type="password" name="touchkey" /><br/>
<input type="submit" value="Login"/>
</form>
</body>
</html>
{% endblock %}