2022-07-30 00:19:30 +02:00
|
|
|
from flask import Flask, render_template, request, redirect, url_for
|
|
|
|
from flask_navigation import Navigation
|
2022-08-15 01:10:34 +02:00
|
|
|
from FileIO import loadZones
|
|
|
|
from Translater import Translater, Language
|
|
|
|
from Zone import getZone
|
2022-07-30 00:19:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-08-15 01:10:34 +02:00
|
|
|
def startWebserver(port, translater, zones):
|
2022-07-30 00:19:30 +02:00
|
|
|
|
|
|
|
|
2022-08-15 01:10:34 +02:00
|
|
|
app = Flask("Bewässerungssystem")
|
|
|
|
nav = Navigation(app)
|
2022-07-30 00:19:30 +02:00
|
|
|
|
2022-08-15 01:10:34 +02:00
|
|
|
nav.Bar('top', [
|
|
|
|
nav.Item(translater.getTranslation('Dashboard'), 'showDashboard'),
|
|
|
|
nav.Item(translater.getTranslation('irrigation zones'), 'showZones'),
|
|
|
|
nav.Item(translater.getTranslation('blocking times'), 'showTimes'),
|
|
|
|
nav.Item(translater.getTranslation('system settings'), 'showSystem')
|
|
|
|
#nav.Item('Gfg', 'gfg', {'page': 5}), #(example with pages)
|
|
|
|
])
|
2022-07-30 00:19:30 +02:00
|
|
|
|
2022-08-15 01:10:34 +02:00
|
|
|
#Example Route with pages:
|
|
|
|
#@app.route('/gfg/<int:page>')
|
|
|
|
#def gfg(page):
|
|
|
|
# return render_template('gfg.html', page=page)
|
2022-07-30 00:19:30 +02:00
|
|
|
|
2022-08-15 01:10:34 +02:00
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
def startPage():
|
|
|
|
return redirect(url_for('showDashboard'))
|
|
|
|
|
|
|
|
@app.route('/dashboard')
|
|
|
|
def showDashboard():
|
|
|
|
return render_template('dashboard.html', translater=translater, zones=zones)
|
|
|
|
|
|
|
|
@app.route('/zones')
|
|
|
|
@app.route('/zones/<zoneNumber>')
|
|
|
|
def showZones(zoneNumber=False):
|
|
|
|
if(zoneNumber):
|
|
|
|
return render_template('zone.html', translater=translater, zone=getZone(zones, zoneNumber))
|
|
|
|
else:
|
|
|
|
return render_template('zones.html', translater=translater, zones=zones)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/times')
|
|
|
|
def showTimes():
|
|
|
|
return render_template('times.html', translater=translater)
|
|
|
|
|
|
|
|
@app.route('/system')
|
|
|
|
def showSystem():
|
|
|
|
return render_template('system.html', translater=translater)
|
|
|
|
|
|
|
|
app.run(debug=True, port=port)
|
2022-07-30 00:19:30 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2022-08-15 01:10:34 +02:00
|
|
|
zones = loadZones()
|
|
|
|
translater = Translater(Language.ENGLISH)
|
|
|
|
startWebserver(80, translater, zones)
|