aboutsummaryrefslogtreecommitdiffstats
path: root/python/Dawn
diff options
context:
space:
mode:
Diffstat (limited to 'python/Dawn')
-rw-r--r--python/Dawn/dawn.py60
-rw-r--r--python/Dawn/models.py52
-rw-r--r--python/Dawn/trade_entry.html12
3 files changed, 69 insertions, 55 deletions
diff --git a/python/Dawn/dawn.py b/python/Dawn/dawn.py
index 1e951c10..2f1f3909 100644
--- a/python/Dawn/dawn.py
+++ b/python/Dawn/dawn.py
@@ -1,65 +1,25 @@
-from sqlalchemy import Table, MetaData, create_engine
-from sqlalchemy.ext.declarative import declarative_base
-from sqlalchemy import Boolean, Sequence, Column, Integer, String, Date, Float, ForeignKey
-from sqlalchemy.dialects.postgresql import ENUM, OID
-from sqlalchemy import create_engine
+from models import BondDeal, Counterparties
from wtforms_alchemy import ModelForm
-from wtforms import IntegerField
+from sqlalchemy import create_engine, MetaData
+from sqlalchemy.orm import sessionmaker
from jinja2 import Environment, FileSystemLoader
engine = create_engine('postgresql://dawn_user@debian/dawndb')
-Base = declarative_base(engine)
+Session = sessionmaker(bind=engine)
+session = Session()
-class Counterparties(Base):
- __tablename__ = 'counterparties'
- code = Column(String(12), primary_key=True)
- name = Column(String)
- city = Column(String)
- state = Column(String(2))
- dtc_number = Column(Integer)
- sales_contact = Column(String)
- sales_email = Column(String)
- sales_phone = Column(String)
- valuation_contact1 = Column(String)
- valuation_email1 = Column(String)
- valuation_contact2 = Column(String)
- valuation_email2 = Column(String)
- valuation_contact3 = Column(String)
- valuation_email3 = Column(String)
- notes = Column(String)
-
-BOND_STRAT = ENUM('M_STR_MAV', 'M_STR_SMEZZ', 'CSO_TRANCH',
- 'M_CLO_BB20', 'M_CLO_AAA', 'M_CLO_BBB', 'M_MTG_IO', 'M_MTG_THRU',
- 'M_MTG_GOOD', 'M_MTG_B4PR', 'M_MTG_RW', name='bond_strat', metadata=Base.metadata)
-ASSET_CLASS = ENUM('CSO', 'Subprime', 'CLO', 'Tranches', 'Futures', 'Cash', 'FX', 'Cleared',
- name='asset_class', metadata=Base.metadata)
-
-class BondDeal(Base):
- __tablename__ = 'bonds'
- dealid = Column(String(28), primary_key=True)
- folder = Column(BOND_STRAT, nullable=False)
- custodian = Column(String(12), nullable=False)
- cashaccount = Column(String(10), nullable=False)
- counterparty = Column(String, ForeignKey("counterparties.code"), nullable=False)
- trade_date = Column(Date, nullable = False)
- settle_date = Column(Date, nullable = False)
- cusip = Column(String(9))
- isin = Column(String(12))
- description = Column(String(32))
- buysell = Column(Boolean, nullable = False)
- faceamount = Column(Float, nullable=False)
- price = Column(Float, nullable=False)
- account = Column(String(10))
- accrued = Column(Float)
- asset_class = Column(ASSET_CLASS)
- ticket = Column(OID, info={'form_field_class': IntegerField})
+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))
diff --git a/python/Dawn/models.py b/python/Dawn/models.py
new file mode 100644
index 00000000..efcd2703
--- /dev/null
+++ b/python/Dawn/models.py
@@ -0,0 +1,52 @@
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy import Boolean, Sequence, Column, Integer, String, Date, Float, ForeignKey
+from sqlalchemy.dialects.postgresql import ENUM, OID
+from wtforms import FileField, SelectField
+import datetime
+
+Base = declarative_base()
+
+class Counterparties(Base):
+ __tablename__ = 'counterparties'
+ code = Column(String(12), primary_key=True)
+ name = Column(String)
+ city = Column(String)
+ state = Column(String(2))
+ dtc_number = Column(Integer)
+ sales_contact = Column(String)
+ sales_email = Column(String)
+ sales_phone = Column(String)
+ valuation_contact1 = Column(String)
+ valuation_email1 = Column(String)
+ valuation_contact2 = Column(String)
+ valuation_email2 = Column(String)
+ valuation_contact3 = Column(String)
+ valuation_email3 = Column(String)
+ notes = Column(String)
+
+BOND_STRAT = ENUM('M_STR_MAV', 'M_STR_SMEZZ', 'CSO_TRANCH',
+ 'M_CLO_BB20', 'M_CLO_AAA', 'M_CLO_BBB', 'M_MTG_IO', 'M_MTG_THRU',
+ 'M_MTG_GOOD', 'M_MTG_B4PR', 'M_MTG_RW', name='bond_strat', metadata=Base.metadata)
+ASSET_CLASS = ENUM('CSO', 'Subprime', 'CLO', 'Tranches', 'Futures', 'Cash', 'FX', 'Cleared',
+ name='asset_class', metadata=Base.metadata)
+
+class BondDeal(Base):
+ __tablename__ = 'bonds'
+ dealid = Column(String(28), primary_key=True)
+ folder = Column(BOND_STRAT, nullable=False)
+ custodian = Column(String(12), nullable=False)
+ cashaccount = Column(String(10), nullable=False)
+ counterparty = Column(String, ForeignKey("counterparties.code"),
+ info={'choices': [(None, None)]})
+ trade_date = Column(Date, nullable = False, default = datetime.date.today)
+ settle_date = Column(Date, nullable = False, default = datetime.date.today)
+ cusip = Column(String(9))
+ isin = Column(String(12))
+ description = Column(String(32))
+ buysell = Column(Boolean, nullable = False, info={'choices':[(0, 'sell'), (1, 'buy')]})
+ faceamount = Column(Float, nullable=False)
+ price = Column(Float, nullable=False)
+ account = Column(String(10))
+ accrued = Column(Float)
+ asset_class = Column(ASSET_CLASS)
+ ticket = Column(OID, info={'form_field_class': FileField})
diff --git a/python/Dawn/trade_entry.html b/python/Dawn/trade_entry.html
index 3fb8248a..1ff23556 100644
--- a/python/Dawn/trade_entry.html
+++ b/python/Dawn/trade_entry.html
@@ -4,15 +4,17 @@
<meta charset="utf-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
</head>
- <body>
- <form class="form-inline" method="POST" action="/submit">
+ <body style="max-width:1024px; margin:0 auto">
+ <form method="POST" class="form-horizontal" action="/submit">
{% for field in form %}
<div class="form-group">
- <label for="{{ field.id }}" class="sr-only">
+ <label class="control-label col-md-2" for="{{ field.id }}">
{{ field.label.text }}
</label>
- {{ field(class_="form-control") }}</div>
-
+ <div class="col-md-3">
+ {{ field(class_="form-control") }}
+ </div>
+ </div>
{% endfor %}
</form>
</body>