blob: f227593e8b103c3334f17617df370ea777227194 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
from flask import Flask, request, render_template
from models import db, ModelForm, BondDeal, Counterparties
import pdb
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 Counterparties.query.order_by('name').\
with_entities(Counterparties.code, Counterparties.name)
# Base.metadata.create_all(engine)
class BondForm(ModelForm):
class Meta:
model = BondDeal
include_foreign_keys = True
@app.route('/', methods=['GET', 'POST'])
def trade_entry():
bond_form = BondForm()
bond_form.counterparty.choices = list_counterparties()
if bond_form.is_submitted():
if bond_form.validate():
bond = BondDeal()
bond_form.populate_obj(bond)
bond.dealid = 'uniqid'
db.session.add(bond)
db.session.commit()
return "Success!"
else:
print(bond_form.errors)
return render_template("trade_entry.html", form=bond_form)
if __name__=="__main__":
app.run(debug=True)
|