begonnen aan zuil en scherm
This commit is contained in:
parent
1cd5e514c5
commit
ca26664d29
@ -0,0 +1,32 @@
|
|||||||
|
import database_connector
|
||||||
|
from flask import Flask, request, render_template, session, redirect, url_for, flash
|
||||||
|
|
||||||
|
"""
|
||||||
|
test var, het het nogmaal gesproken op False
|
||||||
|
"""
|
||||||
|
debug = True
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
database objecten, om minder te typen
|
||||||
|
"""
|
||||||
|
conn = database_connector.conn
|
||||||
|
cur = database_connector.cur
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
stel flask in
|
||||||
|
"""
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def root():
|
||||||
|
return render_template('scherm.html')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run('0.0.0.0', debug=debug)
|
@ -1,23 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Add Moderator</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
{% include 'flash_template.html' %}
|
|
||||||
<h1>Enter new moderator details</h1>
|
|
||||||
<form method="POST">
|
|
||||||
<label>
|
|
||||||
<input type="text" placeholder="Username" name="uname" required>
|
|
||||||
</label>
|
|
||||||
<label>
|
|
||||||
<input type="password" placeholder="Password" name="pword" required>
|
|
||||||
</label>
|
|
||||||
<label>
|
|
||||||
<input type="password" placeholder="Password again" name="pword2" required>
|
|
||||||
</label>
|
|
||||||
<button type="submit">Login</button>
|
|
||||||
</form>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
10
templates/scherm.html
Normal file
10
templates/scherm.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>NS Scherm</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
19
templates/zuil.html
Normal file
19
templates/zuil.html
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>{{ locatie[1] }}</title>
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Welkom op {{ locatie[1] }}</h1>
|
||||||
|
{% include 'flash_template.html' %}
|
||||||
|
<p>Heeft u feedback voor ons?</p>
|
||||||
|
<form method="POST" action="/zuil/post">
|
||||||
|
<input type="text" placeholder="Wat is uw feedback" name="bericht" required>
|
||||||
|
<input type="text" placeholder="Wat is uw naam" name="naam" required>
|
||||||
|
<button type="submit">Verstuur</button>
|
||||||
|
</form>
|
||||||
|
<p>Feedback wordt openbaar gemaakt op Twitter na goedkeuring</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
89
zuil_web.py
Normal file
89
zuil_web.py
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
import database_connector
|
||||||
|
from flask import Flask, request, render_template, session, redirect, url_for, flash
|
||||||
|
import datetime
|
||||||
|
import secrets
|
||||||
|
|
||||||
|
"""
|
||||||
|
pas de locatie id aan zoals weergeven in moderator scherm
|
||||||
|
"""
|
||||||
|
locatieid = 1
|
||||||
|
|
||||||
|
"""
|
||||||
|
test var, het het nogmaal gesproken op False
|
||||||
|
"""
|
||||||
|
debug = True
|
||||||
|
|
||||||
|
"""
|
||||||
|
database objecten, om minder te typen
|
||||||
|
"""
|
||||||
|
conn = database_connector.conn
|
||||||
|
cur = database_connector.cur
|
||||||
|
|
||||||
|
"""
|
||||||
|
stel flask in
|
||||||
|
"""
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
"""
|
||||||
|
als debug op true is een vaste secret key gebruiken, dit is zodat we niet elke keer in hoefen te loggen na een
|
||||||
|
code wijziging. Maar in productie elke start een nieuwe token genereren
|
||||||
|
"""
|
||||||
|
if debug == True:
|
||||||
|
app.secret_key = 'jdndhsyh83r90hfeqwf' # dit is om live te testen
|
||||||
|
else:
|
||||||
|
app.secret_key = secrets.token_hex(32)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def func_getlocaties(locatieid):
|
||||||
|
cur.execute('SELECT * FROM locaties WHERE locatieid = (%s)', [locatieid])
|
||||||
|
return cur.fetchall()[0]
|
||||||
|
|
||||||
|
def func_invoerdatabase(bericht, naamposter, locatieid):
|
||||||
|
date = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
try:
|
||||||
|
QUERY = 'INSERT INTO berichten(bericht, datumontvangen, locatieid, naamposter, statusid) VALUES (%s, %s, %s, %s, %s)'
|
||||||
|
DATA = (bericht, date, locatieid, naamposter, '1')
|
||||||
|
cur.execute(QUERY, DATA)
|
||||||
|
conn.commit()
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def func_checkinvoer(bericht, naamposter):
|
||||||
|
if len(bericht) > 140:
|
||||||
|
return False
|
||||||
|
elif len(bericht) < 16:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if len(naamposter) > 32:
|
||||||
|
return False
|
||||||
|
elif len(naamposter) < 3:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def root():
|
||||||
|
return redirect(url_for('zuil'))
|
||||||
|
|
||||||
|
@app.route('/zuil')
|
||||||
|
def zuil():
|
||||||
|
|
||||||
|
return render_template('zuil.html', locatie=func_getlocaties(locatieid))
|
||||||
|
|
||||||
|
@app.route('/zuil/post', methods=['POST'])
|
||||||
|
def zuil_post():
|
||||||
|
flash('We hebben uw bericht ontvangen')
|
||||||
|
|
||||||
|
return redirect(url_for('zuil'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run('0.0.0.0', debug=debug)
|
Reference in New Issue
Block a user