Skip to content

Commit

Permalink
fix(sample_project): show countdown until redeployment
Browse files Browse the repository at this point in the history
Closes: #976
  • Loading branch information
b1rger committed Jun 20, 2024
1 parent 1b76d14 commit 278ef1b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
40 changes: 33 additions & 7 deletions sample_project/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,43 @@
{% block content %}

{% if not user.is_authenticated %}
<script>
/* copied from https://www.w3schools.com/howto/howto_js_countdown.asp */
// Set the date we're counting down to
var countDownDate = new Date("{% teardown %}");

var x = setInterval(function() {

// Get today's date and time
var now = new Date().getTime();

// Find the distance between now and the count down date
var distance = countDownDate - now;

// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);

// Display the result in the element with id="demo"
document.getElementById("demo").innerHTML = hours + "h " + minutes + "m " + seconds + "s ";

// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
</script>
<div class="container">
<div class="card card-index">
<div class="card-body">
<p class="text-center">Username:</p>
<pre class="text-center">admin</pre>
<p class="text-center">Login:</p>
<pre class="text-center">admin / {% password %}</pre>
<hr class="hr-index" />
<p class="text-center">Current password:</p>
<pre class="text-center">{% password %}</pre>
<hr class="hr-index" />
<p class="text-center">Startup time:</p>
<pre class="text-center">{% startup %}</pre>
<p class="text-center">This instance will be redeployed in</p>
<pre id="demo" class="text-center"></pre>
</div>
</div>
</div>
Expand Down
7 changes: 5 additions & 2 deletions sample_project/templatetags/sample_project.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import pathlib
from django import template

Expand All @@ -10,5 +11,7 @@ def password():


@register.simple_tag
def startup():
return pathlib.Path("/tmp/startup.txt").read_text()
def teardown():
date = datetime.datetime.fromisoformat(pathlib.Path("/tmp/startup.txt").read_text())
until = date + datetime.timedelta(hours=6)
return until

0 comments on commit 278ef1b

Please sign in to comment.