format html + put js in static
This commit is contained in:
parent
0ed9acd405
commit
7fb593c98a
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,6 +2,6 @@
|
||||
__pycache__
|
||||
db.sqlite3
|
||||
venv
|
||||
static
|
||||
/static
|
||||
*.log
|
||||
*.pid
|
||||
39
deployment/static/deployment/js/event_source.js
Normal file
39
deployment/static/deployment/js/event_source.js
Normal 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);
|
||||
};
|
||||
@ -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>
|
||||
@ -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 %}
|
||||
@ -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 %}
|
||||
Loading…
x
Reference in New Issue
Block a user