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__
|
__pycache__
|
||||||
db.sqlite3
|
db.sqlite3
|
||||||
venv
|
venv
|
||||||
static
|
/static
|
||||||
*.log
|
*.log
|
||||||
*.pid
|
*.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>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>{% block title %}mumui{% endblock %}</title>
|
<title>{% block title %}mumui{% endblock %}</title>
|
||||||
{% block headscript %}{% endblock %}
|
{% block headscript %}{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body {% block bodyattr %}{% endblock %}>
|
<body {% block bodyattr %}{% endblock %}>
|
||||||
<main>
|
<main>
|
||||||
{% if user.is_authenticated or "login" in request.path %}
|
{% if user.is_authenticated or "login" in request.path %}
|
||||||
@ -20,4 +22,5 @@
|
|||||||
</main>
|
</main>
|
||||||
{% block script %}{% endblock %}
|
{% block script %}{% endblock %}
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@ -11,7 +11,7 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block bodyattr %}
|
{% block bodyattr %}
|
||||||
onload="start();"
|
onload="start('{{ url|safe }}');"
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
@ -72,45 +72,6 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block script %}
|
{% block script %}
|
||||||
<script>
|
<script src="{% static 'deployment/js/event_source.js' %}" />
|
||||||
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>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@ -11,6 +11,6 @@
|
|||||||
<button type="submit">log in</button>
|
<button type="submit">log in</button>
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
you're already log in !
|
<div>you're already log in !</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Loading…
x
Reference in New Issue
Block a user