aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/Dawn/models.py4
-rw-r--r--python/Dawn/views.py52
2 files changed, 31 insertions, 25 deletions
diff --git a/python/Dawn/models.py b/python/Dawn/models.py
index 4a15185b..7e556f15 100644
--- a/python/Dawn/models.py
+++ b/python/Dawn/models.py
@@ -1,4 +1,4 @@
-from flask_wtf import Form
+from flask_wtf import FlaskForm
from flask_wtf.file import FileField
from sqlalchemy.dialects.postgresql import ENUM
from wtforms import SelectField
@@ -206,7 +206,7 @@ class SwaptionDeal(db.Model):
currency = db.Column(CCY, nullable = False)
counterparty = db.relationship(Counterparties)
-BaseModelForm = model_form_factory(Form)
+BaseModelForm = model_form_factory(FlaskForm)
class ModelForm(BaseModelForm):
@classmethod
def get_session(self):
diff --git a/python/Dawn/views.py b/python/Dawn/views.py
index f6eae147..e9f49a1f 100644
--- a/python/Dawn/views.py
+++ b/python/Dawn/views.py
@@ -86,27 +86,30 @@ def get_deal(kind):
else:
raise RuntimeError('Unknown Deal type')
-def get_form(trade, kind):
+def _get_form(kind):
if kind == 'cds':
- Form = CDSForm
+ return CDSForm
elif kind == 'bond':
- Form = BondForm
+ return BondForm
elif kind == 'swaption':
- Form = SwaptionForm
+ return SwaptionForm
else:
raise RuntimeError('Unknown Deal type')
+
+def get_form(trade, kind):
+ Form = _get_form(kind)
if trade.id:
- form = Form(obj = trade)
+ form = Form(obj=trade)
else:
today = pd.datetime.today()
if kind == 'cds':
tomorrow = today + pd.DateOffset(1)
- form = Form(trade_date = today.date(),
- effective_date = tomorrow.date(),
- upfront_settle_date = today.date() + 3 * bus_day)
+ form = Form(trade_date=today.date(),
+ effective_date=tomorrow.date(),
+ upfront_settle_date=today.date() + 3 * bus_day)
else:
- form = Form(trade_date = today.date(),
- settle_date = today.date() + 3 * bus_day)
+ form = Form(trade_date=today.date(),
+ settle_date=today.date() + 3 * bus_day)
#add extra empty fields
empty_choice = (None, '')
for attr in ['folder', 'buysell', 'asset_class', 'swaption_type']:
@@ -123,7 +126,7 @@ def get_trade(tradeid, kind):
return Deal.query.get(tradeid) if tradeid else Deal()
def save_ticket(trade, old_ticket_name):
- if trade.ticket.filename:
+ if trade.ticket:
if old_ticket_name:
new_name = bump_rev(old_ticket_name)
else:
@@ -140,10 +143,10 @@ def save_ticket(trade, old_ticket_name):
@app.route('/trades/', defaults = {'tradeid': None, 'kind': 'bond'}, methods = ['GET', 'POST'])
def trade_manage(tradeid, kind):
trade = get_trade(tradeid, kind)
- form = get_form(trade, kind)
+ form = _get_form(kind)()
+ form.cp_code.choices = form.cp_code.choices + list(cp_choices())
if kind == 'bond':
old_ticket_name = trade.ticket
- form.cp_code.choices = form.cp_code.choices + list(cp_choices())
if form.validate_on_submit():
form.populate_obj(trade)
session = form.get_session()
@@ -156,16 +159,19 @@ def trade_manage(tradeid, kind):
except IntegrityError as e:
app.logger.error(e)
session.rollback()
- return render_template('trade_entry.html', form = form,
- action_url =
- url_for('trade_manage', tradeid = tradeid, kind = kind))
+ return render_template('trade_entry.html', form=form,
+ action_url=
+ url_for('trade_manage', tradeid=tradeid, kind=kind))
else:
if form.upload_globeop.data:
q = get_queue()
q.rpush('{0}_trades'.format(kind), simple_serialize(trade))
return redirect(url_for('list_trades', kind=kind))
- return render_template('trade_entry.html', form=form,
- action_url = url_for('trade_manage', tradeid = tradeid, kind = kind))
+ else:
+ form = get_form(trade, kind)
+ form.cp_code.choices = form.cp_code.choices + list(cp_choices())
+ return render_template('trade_entry.html', form=form,
+ action_url = url_for('trade_manage', tradeid=tradeid, kind=kind))
@app.route('/', defaults = {'kind': 'bond'})
@app.route('/blotter/<kind>')
@@ -204,18 +210,18 @@ def list_counterparties(instr):
def edit_counterparty(cpcode):
if cpcode:
cp = Counterparties.query.get(cpcode)
- cp_form = CounterpartyForm(obj = cp)
else:
cp = Counterparties()
- cp_form = CounterpartyForm()
+ cp_form = CounterpartyForm()
+
old_instructions = cp.instructions or None
if cp_form.validate_on_submit():
cp_form.populate_obj(cp)
session = cp_form.get_session()
if not cpcode:
session.add(cp)
- instructions = cp.instructions
- if instructions is None or instructions.filename == '':
+ instructions = cp_form.instructions
+ if not instructions.data:
cp.instructions = old_instructions
else:
cp.instructions = cp.name + '.pdf'
@@ -224,7 +230,7 @@ def edit_counterparty(cpcode):
session.commit()
return redirect(url_for('list_counterparties'))
else:
- return render_template('edit_cp.html', form=cp_form, code=cpcode)
+ return render_template('edit_cp.html', form=CounterpartyForm(obj=cp), code=cpcode)
@app.route('/_ajax', methods = ['GET'])
def get_bbg_id():