format html + put js in static

This commit is contained in:
rmanach 2023-09-19 12:03:36 +02:00
parent 0ed9acd405
commit 7fb593c98a
7 changed files with 85 additions and 82 deletions

2
.gitignore vendored
View File

@ -2,6 +2,6 @@
__pycache__
db.sqlite3
venv
static
/static
*.log
*.pid

View File

@ -0,0 +1,39 @@
var start = function (url) {
var es = new ReconnectingEventSource(url);
es.onopen = function () {
console.log('connected');
};
es.addEventListener('stream-error', function (e) {
es.close();
message = JSON.parse(e.data);
console.log('stream error: ' + message.condition + ': ' + message.text);
}, false);
es.onerror = function (e) {
console.log('connection error');
};
// listening on `message` events and update the corresponding table line.
// If the status is `FAILED`, we reload the window to ensure a new csrf_token.
es.addEventListener('message', function (e) {
message = JSON.parse(e.data);
console.log("id: " + message.id);
console.log("status: " + message.status);
const tr = document.getElementById(message.id);
if (tr) {
var th = tr.querySelector("th[name='status']");
th.innerHTML = message.status;
if (message.status == "FAILED") {
setTimeout(() => {
window.location.reload();
}, 2000);
}
}
}, false);
};

View File

@ -1,10 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{% block title %}mumui{% endblock %}</title>
{% block headscript %}{% endblock %}
</head>
<body {% block bodyattr %}{% endblock %}>
<main>
{% if user.is_authenticated or "login" in request.path %}
@ -20,4 +22,5 @@
</main>
{% block script %}{% endblock %}
</body>
</html>

View File

@ -11,7 +11,7 @@
{% endblock %}
{% block bodyattr %}
onload="start();"
onload="start('{{ url|safe }}');"
{% endblock %}
{% block content %}
@ -72,45 +72,6 @@
{% endblock %}
{% block script %}
<script>
var start = function () {
var es = new ReconnectingEventSource('{{ url|safe }}');
es.onopen = function () {
console.log('connected');
};
es.addEventListener('stream-error', function (e) {
es.close();
message = JSON.parse(e.data);
console.log('stream error: ' + message.condition + ': ' + message.text);
}, false);
es.onerror = function (e) {
console.log('connection error');
};
// listening on `message` events and update the corresponding table line.
// If the status is `FAILED`, we reload the window to ensure a new csrf_token.
es.addEventListener('message', function (e) {
message = JSON.parse(e.data);
console.log("id: " + message.id);
console.log("status: " + message.status);
const tr = document.getElementById(message.id);
if (tr) {
var th = tr.querySelector("th[name='status']");
th.innerHTML = message.status;
if (message.status == "FAILED") {
setTimeout(() => {
window.location.reload();
}, 2000);
}
}
}, false);
};
<script src="{% static 'deployment/js/event_source.js' %}" />
</script>
{% endblock %}

View File

@ -11,6 +11,6 @@
<button type="submit">log in</button>
</form>
{% else %}
you're already log in !
<div>you're already log in !</div>
{% endif %}
{% endblock %}