Verified Commit 7b563b1a authored by Štěpán Henek's avatar Štěpán Henek 🌩

new plugin format addopted

* installs to regular python directory
* uses jinja2 templates
* uses libsass to compile sass files
parent e862e739
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
# Foris netmetr plugin
# Copyright (C) 2017 CZ.NIC, z. s. p. o. <https://www.nic.cz>
# Copyright (C) 2018 CZ.NIC, z. s. p. o. <https://www.nic.cz>
#
# Foris is distributed under the terms of GNU General Public License v3.
# You should have received a copy of the GNU General Public License
......@@ -69,7 +69,8 @@ class NetmetrPluginConfigHandler(BaseConfigHandler):
class NetmetrPluginPage(ConfigPageMixin, NetmetrPluginConfigHandler):
menu_order = 80
template = "netmetr/netmetr_plugin.tpl"
template = "netmetr/netmetr_plugin"
template_type = "jinja2"
userfriendly_title = gettext("Netmetr")
def save(self, *args, **kwargs):
......
......@@ -27,25 +27,25 @@ Foris.WS["netmetr"] = function(msg) {
switch(msg["action"]) {
case "download_data_finished":
if (msg.data.passed) {
$("#netmetr-control-status").text('{{ trans("Downloading... OK")}}');
$("#netmetr-control-status").text('{% trans %}Downloading... OK{% endtrans %}');
Foris.update_data();
} else {
$("#netmetr-control-status").text('{{ trans("Downloading... FAILED")}}');
$("#netmetr-control-status").text('{% trans %}Downloading... FAILED{% endtrans %}');
}
break;
case "measure_and_download_data_finished":
if (msg.data.passed) {
$("#netmetr-control-status").text('{{ trans("Testing... FINISHED")}}');
$("#netmetr-control-status").text('{% trans %}Testing... FINISHED{% endtrans %}');
Foris.update_data(true);
document.getElementById('netmetr-control-progress').hidden = true;
} else {
$("#netmetr-control-status").text('{{ trans("Testing... FAILED")}}');
$("#netmetr-control-status").text('{% trans %}Testing... FAILED{% endtrans %}');
}
break;
case "measure_and_download_data_notification":
document.getElementById('netmetr-control-progress').hidden = false;
document.getElementById('netmetr-control-progress').value = msg.data.percent;
document.getElementById('netmetr-control-status').firstChild.data = '{{ trans("Testing... ")}}' + msg.data.msg;
document.getElementById('netmetr-control-status').firstChild.data = '{% trans %}Testing... {% endtrans %}' + msg.data.msg;
break;
}
};
......@@ -58,7 +58,7 @@ $(document).ready(function() {
Foris.watched_process = response["async_id"];
$("#start-trigger").hide()
$("#redownload-trigger").hide()
$("#netmetr-control-status").text('{{ trans("Downloading...")}}');
$("#netmetr-control-status").text('{% trans %}Downloading...{% endtrans %}');
});
});
$("#start-trigger").click(function(e) {
......@@ -68,7 +68,7 @@ $(document).ready(function() {
Foris.watched_process = response["async_id"];
$("#start-trigger").hide()
$("#redownload-trigger").hide()
$("#netmetr-control-status").text('{{ trans("Testing...")}}');
$("#netmetr-control-status").text('{% trans %}Testing...{% endtrans %}');
document.getElementById('netmetr-control-progress').hidden = false;
});
});
......
{% set ns = namespace(my_url=None,detail_url=None) %}
{% if lang() == "cs" %}
{% set ns.my_url = "https://www.netmetr.cz/cs/moje.html" %}
{% set ns.detail_url = "https://www.netmetr.cz/cs/detail.html" %}
{% else %}
{% set ns.my_url = "https://www.netmetr.cz/en/my.html" %}
{% set ns.detail_url = "https://www.netmetr.cz/en/detail.html" %}
{% endif %}
<div id="netmetr-results">
{% if results %}
<table id="netmetr-results-table">
<thead>
<tr>
<th>{% trans %}Date and Time{% endtrans %}</th>
<th>{% trans %}Download [Mb/s]{% endtrans %}</th>
<th>{% trans %}Upload [Mb/s]{% endtrans %}</th>
<th>{% trans %}Ping [ms]{% endtrans %}</th>
<th>{% trans %}Link{% endtrans %}</th>
</tr>
</thead>
<tbody>
{% for record in results %}
<tr>
<td>{{ record["time"] }}</td>
<td>{{ record["speed_download"] }}</td>
<td>{{ record["speed_upload"] }}</td>
<td>{{ record["ping"] }}</td>
<td>
<a href="{{ "%s?%s" % (ns.detail_url, record["test_uuid"]) }}">{% trans %}Details{% endtrans %}</a>
&nbsp;
<a href="{{ "%s?%s" % (ns.detail_url, record["test_uuid"]) }}" title="{% trans %}Details in new window{% endtrans %}" onclick="return !window.open(this.href)"><i class="far fa-clone"></i></a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<br>
<p>{% trans sync_code=sync_code, url=ns.my_url %}For more information you need to enter your syncode <strong>{{ sync_code }}</strong> <a href='{{ url }}'>here</a>.{% endtrans %}</p>
{% else %}
<p>{% trans %}No results found.{% endtrans %}</p>
{% endif %}
</div>
%rebase("config/base.tpl", **locals())
{% extends 'config/base.html.j2' %}
{% block config_base %}
<div id="page-netmetr-plugin" class="config-page">
%include("_messages.tpl")
{% include '_messages.html.j2' %}
<form action="{{ request.fullpath }}" class="config-form" method="post" id="netmetr-main-form">
<input type="hidden" name="csrf_token" value="{{ get_csrf_token() }}">
<p class="config-description">
{{ trans("Netmeter measures your internet parameters like upload, download and response time.") }}
{% trans %}Netmeter measures your internet parameters like upload, download and response time.{% endtrans %}
</p>
<hr>
<h3>{{ form.sections[0].sections[0].title }}</h3>
%for field in form.sections[0].sections[0].active_fields:
%include("_field.tpl", field=field)
%end
%if form.active_fields[0].field.get_value():
{% for field in form.sections[0].sections[0].active_fields %}
{% include '_field.html.j2' %}
{% endfor %}
{% if form.active_fields[0].field.get_value() %}
<br>
<h5>{{ form.sections[0].sections[1].title }}</h5>
%end
{% endif %}
<div class="times row">
%for field in form.sections[0].sections[1].active_fields:
{% for field in form.sections[0].sections[1].active_fields %}
<div class="netmetr-time-box">
{{! field.render() }}
{{ field.render()|safe }}
<br>
{{! field.label_tag }}
{{ field.label_tag|safe }}
</div>
%end
{% endfor %}
</div>
<div class="form-buttons">
<button type="submit" name="send" class="button">{{ trans("Save") }}</button>
<button type="submit" name="send" class="button">{% trans %}Save{% endtrans %}</button>
</div>
</form>
<hr>
<h3>{{ trans("Controls") }}</h3>
<h3>{% trans %}Controls{% endtrans %}</h3>
<p id="netmetr-control-status"></p>
<progress id="netmetr-control-progress" max="100" value="0" hidden></progress>
<form action="{{ url("config_action", page_name="netmetr_plugin", action="perform") }}" class="config-form" id="netmetr-controls" method="post">
<input type="hidden" name="csrf_token" value="{{ get_csrf_token() }}">
<button type="submit" name="action" id="redownload-trigger" value="redownload" class="button">{{ trans("Redownload data") }}</button>
<button type="submit" name="action" id="start-trigger" value="start" class="button">{{ trans("Start test") }}</button>
<button type="submit" name="action" id="redownload-trigger" value="redownload" class="button">{% trans %}Redownload data{% endtrans %}</button>
<button type="submit" name="action" id="start-trigger" value="start" class="button">{% trans %}Start test{% endtrans %}</button>
</form>
<hr>
<h3>{{ trans("Results") }}</h3>
%include("netmetr/_results.tpl", results=results, sync_code=form._request_data["sync_code"])
<h3>{% trans %}Results{% endtrans %}</h3>
{% set sync_code=form._request_data["sync_code"] %}
{% include 'netmetr/_results.html.j2' %}
</div>
{% endblock %}
#!/usr/bin/env python
import copy
from setuptools import setup
from setuptools.command.build_py import build_py
class BuildCmd(build_py):
def run(self):
# build foris plugin files
from foris_plugins_distutils import build
cmd = build(copy.copy(self.distribution))
cmd.finalize_options()
cmd.run()
# build package
build_py.run(self)
setup(
name="Foris Netmetr Plugin",
version="3",
description="Netmetr plugin for foris web interfce",
author="CZ.NIC, z. s. p. o.",
author_email="stepan.henek@nic.cz",
url="https://gitlab.labs.nic.cz/turris/foris-netmetr-plugin/",
license="GPL-3.0",
requires=[
"foris",
],
setup_requires=[
'babel',
'jinja2',
'libsass',
'foris_plugins_distutils',
],
provides=[
"foris_plugins.netmetr",
],
packages=[
"foris_plugins.netmetr",
],
package_data={
'': [
"templates/**",
"templates/**/*",
"templates/javascript/**",
"templates/javascript/**/*",
"locale/**/LC_MESSAGES/*.mo",
"static/css/*.css",
"static/fonts/*",
"static/img/*",
"static/js/*.js",
"static/js/contrib/*",
],
},
cmdclass={
"build_py": BuildCmd, # modify build_py to build the foris files as well
}
)
<%
if lang() == "cs":
my_url = "https://www.netmetr.cz/cs/moje.html"
detail_url = "https://www.netmetr.cz/cs/detail.html"
else:
my_url = "https://www.netmetr.cz/en/my.html"
detail_url = "https://www.netmetr.cz/en/detail.html"
end
%>
<div id="netmetr-results">
%if results:
<table id="netmetr-results-table">
<thead>
<tr>
<th>{{ trans("Date and Time") }}</th>
<th>{{ trans("Download [Mb/s]") }}</th>
<th>{{ trans("Upload [Mb/s]") }}</th>
<th>{{ trans("Ping [ms]") }}</th>
<th>{{ trans("Link") }}</th>
</tr>
</thead>
<tbody>
%for record in results:
<tr>
<td>{{ record["time"] }}</td>
<td>{{ record["speed_download"] }}</td>
<td>{{ record["speed_upload"] }}</td>
<td>{{ record["ping"] }}</td>
<td>
<a href="{{ "%s?%s" % (detail_url, record["test_uuid"]) }}">{{ trans("Details") }}</a>
&nbsp;
<a href="{{ "%s?%s" % (detail_url, record["test_uuid"]) }}" title="{{ trans("Details in new window") }}" onclick="return !window.open(this.href)"><i class="far fa-clone"></i></a>
</td>
</tr>
%end
</tbody>
</table>
<br>
<p>{{! trans("For more information you need to enter your syncode <strong>%(sync_code)s</strong> <a href='%(url)s'>here</a>.") % dict(sync_code=sync_code, url=my_url) }}</p>
%else:
<p>{{ trans("No results found.") }}</p>
%end
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment