Redid the index to use flask forms. Removed un-needed html pages. Started adding database.
This commit is contained in:
75
app.py
75
app.py
@@ -1,11 +1,80 @@
|
|||||||
from flask import Flask, render_template
|
from flask import Flask, render_template, request, flash, redirect
|
||||||
|
import datetime
|
||||||
|
from sqlalchemy import create_engine, Column, Integer, Date, String
|
||||||
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
app.config['SECRET_KEY'] = 'fa6166b0218186fb852429060105aca18e0f979240be8ebf'
|
||||||
|
|
||||||
|
Base = declarative_base()
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
class Dates(Base):
|
||||||
|
__tablename__ = 'Dates'
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
dateType = Column(Integer),
|
||||||
|
dateValue = Column(Date)
|
||||||
|
|
||||||
|
|
||||||
|
class DatesMetadata(Base):
|
||||||
|
__tablename__ = 'DatesMetadata'
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
dateTypeID = Column(Integer)
|
||||||
|
DateTypeName = Column(String)
|
||||||
|
|
||||||
|
|
||||||
|
class Settings(Base):
|
||||||
|
__tablename__ = 'Settings'
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
settingType = Column(Integer)
|
||||||
|
settingVale = Column(String)
|
||||||
|
|
||||||
|
|
||||||
|
class SettingsMetadata(Base):
|
||||||
|
__tablename__ = 'SettingsMetadata'
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
settingTypeID = Column(Integer)
|
||||||
|
settingTypeName = Column(String)
|
||||||
|
|
||||||
|
|
||||||
|
engine = create_engine('sqlite:///static/db.db')
|
||||||
|
Dates.__table__.create(bind=engine, checkfirst=True)
|
||||||
|
Settings.__table__.create(bind=engine, checkfirst=True)
|
||||||
|
DatesMetadata.__table__.create(bind=engine, checkfirst=True)
|
||||||
|
SettingsMetadata.__table__.create(bind=engine, checkfirst=True)
|
||||||
|
|
||||||
|
Session = sessionmaker(bind=engine)
|
||||||
|
session = Session()
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/', methods=('GET', 'POST'))
|
||||||
|
@app.route('/index.html', methods=('GET', 'POST'))
|
||||||
def index():
|
def index():
|
||||||
return render_template("index.html")
|
|
||||||
|
plantdate = datetime.datetime(2022, 1,19)
|
||||||
|
last = datetime.datetime(2022, 1,19)
|
||||||
|
freq = 7
|
||||||
|
next = last + datetime.timedelta(days=freq)
|
||||||
|
|
||||||
|
alerts = {'text': False, 'email': True}
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
plantdate = request.form['plantDate']
|
||||||
|
last = request.form['lastDate']
|
||||||
|
next = datetime.datetime.strptime(last,'%Y-%m-%d') + datetime.timedelta(days=freq)
|
||||||
|
|
||||||
|
plant = {'plant': plantdate, 'last': last, 'next': next, 'freq': freq}
|
||||||
|
return render_template("index.html", plant=plant, alerts=alerts)
|
||||||
|
|
||||||
|
else:
|
||||||
|
dates = {'plant': '', 'last': '', 'next':'', 'freq': ''}
|
||||||
|
dates['plant'] = session.query(Dates.dateValue).filter(Dates.dateType == 1).first()
|
||||||
|
dates['last'] = session.query(Dates.dateValue).filter(Dates.dateType == 2).first()
|
||||||
|
dates['next'] = session.query(Dates.dateValue).filter(Dates.dateType == 3).first()
|
||||||
|
dates['freq'] = session.query(Dates.dateValue).filter(Dates.dateType == 4).first()
|
||||||
|
flash(dates['plant'])
|
||||||
|
return render_template("index.html", plant=dates, alerts=alerts)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
18
templates/base.html
Normal file
18
templates/base.html
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Hydro</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div>Hydro: <a href="index.html">home</a></div>
|
||||||
|
<br>
|
||||||
|
{% with messages = get_flashed_messages() %}
|
||||||
|
{% if messages %}
|
||||||
|
{% for message in messages %}
|
||||||
|
{{ message }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% endwith %}
|
||||||
|
<br>
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Title</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,41 +1,38 @@
|
|||||||
<!DOCTYPE html>
|
{% extends "base.html" %}
|
||||||
<html lang="en">
|
{% block content %}
|
||||||
<script src="../static/scripts.js"></script>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Hydro</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
<body>
|
||||||
<h1>Information</h1>
|
<h1>Information</h1>
|
||||||
<div>
|
<form method="post">
|
||||||
Plant Date:
|
<label>Plant Date</label>
|
||||||
1/19/2022
|
<input type="date" name="plantDate"
|
||||||
<a href="plantdate.html">Change</a>
|
value= {{ plant.plant }}>
|
||||||
</div>
|
<br>
|
||||||
<div>
|
<label>Last Feed Date</label>
|
||||||
Last Feed Date:
|
<input type="date" name="lastDate"
|
||||||
<a href="lastfeeddate.html">Change</a>
|
value= {{ plant.last }}>
|
||||||
</div>
|
<br>
|
||||||
<div>
|
<label>Next Feed Date</label>
|
||||||
Next Feed Date:
|
<input type="date" name="nextDate"
|
||||||
<a href="nextfeeddate.html">Change</a>
|
value= {{ plant.next }}>
|
||||||
</div>
|
<br>
|
||||||
<div>
|
Feed Frequency: {{ plant.freq }} days
|
||||||
Feed Frequency:
|
<br>
|
||||||
<a href="freedfreq.html">Change</a>
|
<button type="submit">Update</button>
|
||||||
</div>
|
</form>
|
||||||
|
|
||||||
<h1>Alerts</h1>
|
<h1>Alerts</h1>
|
||||||
<div>
|
<div>
|
||||||
<input type="checkbox" id="alert_text" name="AlertText" value=true>
|
<form method="post">
|
||||||
|
<input type="checkbox" id="alert_text" name="AlertText" value=alerts.text {{ "checked" if alerts.text else "" }}>
|
||||||
<label for="alert_text">Text Message</label>
|
<label for="alert_text">Text Message</label>
|
||||||
<input type="checkbox" id="alert_email" name="AlertEmail" value=true>
|
<input type="checkbox" id="alert_email" name="AlertEmail" value=alerts.email {{ "checked" if alerts.email else "" }}>
|
||||||
<label for="alert_email">Email</label><br>
|
<label for="alert_email">Email</label><br>
|
||||||
<button class=button onclick="updateAlerts()">Save</button>
|
<button type="submit">Save</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<br><br>
|
<br><br>
|
||||||
<div>
|
<div>
|
||||||
<button class=button onclick="updateFeed()">Update Feed</button>
|
<button class=button onclick="updateFeed()">Update Feed</button>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
{% endblock %}
|
||||||
</html>
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Title</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Title</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Title</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Reference in New Issue
Block a user