aboutsummaryrefslogtreecommitdiffstats
path: root/python/Dawn/dawn.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/Dawn/dawn.py')
-rw-r--r--python/Dawn/dawn.py30
1 files changed, 17 insertions, 13 deletions
diff --git a/python/Dawn/dawn.py b/python/Dawn/dawn.py
index 2f1f3909..1f1e578b 100644
--- a/python/Dawn/dawn.py
+++ b/python/Dawn/dawn.py
@@ -1,15 +1,13 @@
-from models import BondDeal, Counterparties
-from wtforms_alchemy import ModelForm
-from sqlalchemy import create_engine, MetaData
-from sqlalchemy.orm import sessionmaker
-from jinja2 import Environment, FileSystemLoader
+from flask import Flask, request, render_template
+from models import db, ModelForm, BondDeal, Counterparties
-engine = create_engine('postgresql://dawn_user@debian/dawndb')
-Session = sessionmaker(bind=engine)
-session = Session()
+app = Flask(__name__)
+app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://dawn_user@debian/dawndb'
+app.config['SECRET_KEY'] = 'papa'
+db.init_app(app)
def list_counterparties():
- return session.query(Counterparties).order_by('name').\
+ return Counterparties.query.order_by('name').\
with_entities(Counterparties.code, Counterparties.name)
# Base.metadata.create_all(engine)
@@ -19,7 +17,13 @@ class BondForm(ModelForm):
model = BondDeal
include_foreign_keys = True
-form = BondForm()
-form.counterparty.choices = list_counterparties()
-jinja_env = Environment(loader = FileSystemLoader("."))
-print(jinja_env.get_template("trade_entry.html").render(form = form))
+@app.route('/', methods=['GET', 'POST'])
+def trade_entry():
+ form = BondForm()
+ form.counterparty.choices = list_counterparties()
+ if form.validate_on_submit():
+ return "Success!"
+ return render_template("trade_entry.html", form=form)
+
+if __name__=="__main__":
+ app.run(debug=True)