Minimal first version

Currently prints "dring" to stdout, and does not ring.
This commit is contained in:
Théophile Bastian 2018-02-05 23:25:32 +01:00
parent 3e795ccb48
commit 88e42032df
4 changed files with 83 additions and 0 deletions

1
.gitignore vendored
View file

@ -58,3 +58,4 @@ docs/_build/
# PyBuilder
target/
venv

43
sonnette.py Normal file
View file

@ -0,0 +1,43 @@
""" Sonnetteweb — Enfin une sonnette à l'Arcoloc
Sonnez via le réseau local. C'est cool, hein ?
"""
from datetime import datetime, timedelta
from flask import Flask, render_template, request
app = Flask('sonnetteweb')
class Ringer:
_instance = None
def __init__(self):
self.last_rung = datetime.fromtimestamp(0)
@staticmethod
def get():
if Ringer._instance is None:
Ringer._instance = Ringer()
return Ringer._instance
def ring(self):
if datetime.now() - self.last_rung < timedelta(seconds=5):
return False
self.last_rung = datetime.now()
print('dring')
return True
@app.route('/', methods=['GET', 'POST'])
def view_home():
context = {}
if request.method == 'POST':
if request.form['ding'] == 'dong':
if Ringer.get().ring():
context['has_rung'] = True
else:
context['too_much_dring'] = True
return render_template('homepage.html', **context)

15
templates/base.html Normal file
View file

@ -0,0 +1,15 @@
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Sonnette de l'Arcoloc</title>
<meta name="author" content="Arcoloc.eu">
<!-- <link rel="stylesheet" href="static/style.css"> -->
</head>
<body>
{% block content %}
{% endblock content %}
</body>
</html>

24
templates/homepage.html Normal file
View file

@ -0,0 +1,24 @@
{% extends "base.html" %}
{% block content %}
<h1>Sonnette de l'Arcoloc</h1>
{% if has_rung %}
<div id="hasrung">
<p>Dring :)</p>
</div>
{% endif %}
{% if too_much_dring %}
<div id="toomuch">
<p>Non mais on est pas sourd·e·s, hein. Nonmaisoh.</p>
</div>
{% endif %}
<form method="post">
<input type="hidden" name='ding' value='dong' />
<input type="submit" value="Dring !" />
</form>
{% endblock content %}