aboutsummaryrefslogtreecommitdiffstats
path: root/python/Dawn/dawn.py
blob: 2f1f3909c3c695f3627a20b6ac81a15427f4ae62 (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
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

engine = create_engine('postgresql://dawn_user@debian/dawndb')
Session = sessionmaker(bind=engine)
session = Session()

def list_counterparties():
    return session.query(Counterparties).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

form = BondForm()
form.counterparty.choices = list_counterparties()
jinja_env = Environment(loader = FileSystemLoader("."))
print(jinja_env.get_template("trade_entry.html").render(form = form))