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__ __pycache__
db.sqlite3 db.sqlite3
venv venv
static /static
*.log *.log
*.pid *.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,23 +1,26 @@
<!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 %}
{% block content %} {% block content %}
{% endblock %} {% endblock %}
{% if user.is_authenticated %} {% if user.is_authenticated %}
<p><a href="{% url 'logout' %}">log out</a></p> <p><a href="{% url 'logout' %}">log out</a></p>
{% endif %} {% endif %}
{% else %} {% else %}
<p>You are not logged in</p> <p>You are not logged in</p>
<a href="{% url 'login' %}">log In</a> <a href="{% url 'login' %}">log In</a>
{% endif %} {% endif %}
</main> </main>
{% block script %}{% endblock %} {% block script %}{% endblock %}
</body> </body>
</html> </html>

View File

@ -2,16 +2,16 @@
{% load static %} {% load static %}
{% block title %}deployment's board{% endblock %} {% block title %} deployment's board {% endblock %}
{% block headscript %} {% block headscript %}
<script src="{% static 'django_eventstream/json2.js' %}"></script> <script src="{% static 'django_eventstream/json2.js' %}"></script>
<script src="{% static 'django_eventstream/eventsource.min.js' %}"></script> <script src="{% static 'django_eventstream/eventsource.min.js' %}"></script>
<script src="{% static 'django_eventstream/reconnecting-eventsource.js' %}"></script> <script src="{% static 'django_eventstream/reconnecting-eventsource.js' %}"></script>
{% endblock %} {% endblock %}
{% block bodyattr %} {% block bodyattr %}
onload="start();" onload="start('{{ url|safe }}');"
{% endblock %} {% endblock %}
{% block content %} {% block content %}
@ -48,19 +48,19 @@
</table> </table>
<div class="pagination"> <div class="pagination">
<span class="step-links"> <span class="step-links">
{% if page_obj.has_previous %} {% if page_obj.has_previous %}
<a href="?page=1">&laquo; first</a> <a href="?page=1">&laquo; first</a>
<a href="?page={{ page_obj.previous_page_number }}">previous</a> <a href="?page={{ page_obj.previous_page_number }}">previous</a>
{% endif %} {% endif %}
<span class="current"> <span class="current">
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}. Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
</span> </span>
{% if page_obj.has_next %} {% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}">next</a> <a href="?page={{ page_obj.next_page_number }}">next</a>
<a href="?page={{ page_obj.paginator.num_pages }}">last &raquo;</a> <a href="?page={{ page_obj.paginator.num_pages }}">last &raquo;</a>
{% endif %} {% endif %}
</span> </span>
</div> </div>
{% else %} {% else %}
@ -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 %}

View File

@ -1,6 +1,6 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block title %}new deployment{% endblock %} {% block title %} new deployment {% endblock %}
{% block content %} {% block content %}
{{ user.username }}'s new deployment {{ user.username }}'s new deployment

View File

@ -1,24 +1,24 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block title %}deployment details: {{ deployment.name }}{% endblock %} {% block title %} deployment details: {{ deployment.name }} {% endblock %}
{% block content %} {% block content %}
<table> <table>
<tr> <tr>
<th>id</th> <th>id</th>
<th>name</th> <th>name</th>
<th>type</th> <th>type</th>
<th>status</th> <th>status</th>
</tr> </tr>
<tr id="{{ deployment.id }}"> <tr id="{{ deployment.id }}">
<th name="id">{{ deployment.id }}</th> <th name="id">{{ deployment.id }}</th>
<th name="name">{{ deployment.name }}</th> <th name="name">{{ deployment.name }}</th>
<th name="type">{{ deployment.type }}</th> <th name="type">{{ deployment.type }}</th>
<th name="status">{{ deployment.status }}</th> <th name="status">{{ deployment.status }}</th>
</tr> </tr>
</table> </table>
<form action="" method="post"> <form action="" method="post">
{% csrf_token %} {% csrf_token %}
<input type="submit" value="delete"> <input type="submit" value="delete">
</form> </form>
{% endblock %} {% endblock %}

View File

@ -1,16 +1,16 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block title %}login{% endblock %} {% block title %} login {% endblock %}
{% block content %} {% block content %}
{% if not user.is_authenticated %} {% if not user.is_authenticated %}
<h2>log in</h2> <h2>log in</h2>
<form method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{{ form.as_p }} {{ form.as_p }}
<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 %}