aboutsummaryrefslogtreecommitdiffstats
path: root/python/Dawn/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/Dawn/views.py')
-rw-r--r--python/Dawn/views.py31
1 files changed, 25 insertions, 6 deletions
diff --git a/python/Dawn/views.py b/python/Dawn/views.py
index d1cbee24..dc2e2c25 100644
--- a/python/Dawn/views.py
+++ b/python/Dawn/views.py
@@ -1,6 +1,6 @@
from flask import (request, render_template, redirect,
url_for, send_from_directory, send_file, g, jsonify)
-from .models import ModelForm, BondDeal, CDSDeal, SwaptionDeal, Counterparties
+from .models import ModelForm, BondDeal, CDSDeal, SwaptionDeal, FutureDeal, Counterparties
from sqlalchemy.exc import IntegrityError
from wtforms.fields import BooleanField
import pandas as pd
@@ -20,9 +20,17 @@ fed_cal = get_calendar('USFederalHolidayCalendar')
bond_cal = HolidayCalendarFactory('BondCalendar', fed_cal, GoodFriday)
bus_day = CustomBusinessDay(calendar=bond_cal())
-def cp_choices():
- return Counterparties.query.order_by('name').\
- with_entities(Counterparties.code, Counterparties.name)
+def cp_choices(kind='bond'):
+ if kind == 'bond':
+ return (Counterparties.query.order_by('name').
+ with_entities(Counterparties.code, Counterparties.name))
+ elif kind == 'future':
+ return []
+ elif kind == 'cds':
+ return (Counterparties.query.
+ order_by('name').
+ filter(Counterparties.name.ilike('%CDS%')).
+ with_entities(Counterparties.code, Counterparties.name))
def get_queue():
q = getattr(g, 'queue', None)
@@ -75,6 +83,12 @@ class SwaptionForm(ModelForm):
include_foreign_keys = True
exclude = ['dealid', 'lastupdate']
+class FutureForm(ModelForm):
+ upload_globeop = BooleanField(label="Upload to globeop?")
+ class Meta:
+ model = FutureDeal
+ include_foreign_keys = True
+ exclude = ['dealid', 'lastupdate']
def get_deal(kind):
if kind == 'cds':
@@ -83,6 +97,8 @@ def get_deal(kind):
return BondDeal
elif kind == 'swaption':
return SwaptionDeal
+ elif kind == 'future':
+ return FutureDeal
else:
raise RuntimeError('Unknown Deal type')
@@ -93,6 +109,8 @@ def _get_form(kind):
return BondForm
elif kind == 'swaption':
return SwaptionForm
+ elif kind == 'future':
+ return FutureForm
else:
raise RuntimeError('Unknown Deal type')
@@ -144,7 +162,8 @@ def save_ticket(trade, old_ticket_name):
def trade_manage(tradeid, kind):
trade = get_trade(tradeid, kind)
form = _get_form(kind)()
- form.cp_code.choices = form.cp_code.choices + list(cp_choices())
+
+ form.cp_code.choices = form.cp_code.choices + list(cp_choices(kind))
if kind == 'bond':
old_ticket_name = trade.ticket
if form.validate_on_submit():
@@ -169,7 +188,7 @@ def trade_manage(tradeid, kind):
return redirect(url_for('list_trades', kind=kind))
else:
form = get_form(trade, kind)
- form.cp_code.choices = form.cp_code.choices + list(cp_choices())
+ form.cp_code.choices = form.cp_code.choices + list(cp_choices(kind))
return render_template('trade_entry.html', form=form,
action_url = url_for('trade_manage', tradeid=tradeid, kind=kind))