aboutsummaryrefslogtreecommitdiffstats
path: root/python/Dawn/dawn.py
blob: 88c095963470a866467e199b96981ff0e22de921 (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
39
40
41
42
from flask import Flask, request, render_template
from models import db, ModelForm, BondDeal, Counterparties

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://dawn_user@debian/dawndb'
app.config['SECRET_KEY'] = 'papa'
app.config['UPLOAD_FOLDER'] = 'tickets'

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
        exclude = ['dealid'] #we generate it with a trigger at the server level

@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.ticket.save('test.pdf')
            bond.ticket='test.pdf'
            bond_form.get_session().add(bond)
            bond_form.get_session().commit()
            return "Success!"
        else:
            print(bond_form.errors)
    return render_template("trade_entry.html", form=bond_form)

if __name__=="__main__":
    #db.drop_all(app=app)
    #db.create_all(app=app)
    db.init_app(app)
    app.run(debug=True)