Update app.py
This commit is contained in:
parent
c7c1aa3e7e
commit
afa18cb3bb
35
app.py
35
app.py
@ -1,29 +1,14 @@
|
||||
from flask import Flask, render_template, request, redirect
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from discord_lnbits_bot import Base, engine, Config, Plan
|
||||
import os
|
||||
from flask import Flask, render_template, request, redirect, flash
|
||||
from dotenv import load_dotenv # Optional: can be removed now
|
||||
|
||||
from models import db, Config, Plan
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = os.getenv("FLASK_SECRET")
|
||||
|
||||
Session = sessionmaker(bind=engine)
|
||||
# Flask config from env vars
|
||||
app.secret_key = os.environ.get("FLASK_SECRET", "dev-only-key")
|
||||
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get("DATABASE_URL")
|
||||
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
||||
|
||||
@app.route("/", methods=["GET","POST"])
|
||||
def settings():
|
||||
db = Session()
|
||||
if request.method=="POST":
|
||||
# update Config
|
||||
for key in ("discord_token","guild_id","lnbits_url","lnbits_api_key"):
|
||||
cfg = db.get(Config, key)
|
||||
cfg.value = request.form.get(key, "")
|
||||
db.commit()
|
||||
return redirect("/")
|
||||
|
||||
config_rows = db.query(Config).all()
|
||||
plan_rows = db.query(Plan).all()
|
||||
db.close()
|
||||
return render_template("settings.html", config=config_rows, plans=plan_rows)
|
||||
|
||||
# you can add routes for adding/editing/deleting plans...
|
||||
|
||||
if __name__=="__main__":
|
||||
app.run(host="0.0.0.0", port=3000)
|
||||
db.init_app(app)
|
||||
|
Loading…
x
Reference in New Issue
Block a user