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.py42
1 files changed, 25 insertions, 17 deletions
diff --git a/python/Dawn/views.py b/python/Dawn/views.py
index f73e1e10..dc37640b 100644
--- a/python/Dawn/views.py
+++ b/python/Dawn/views.py
@@ -51,6 +51,7 @@ def close_connection(exception):
class CounterpartyForm(ModelForm):
class Meta:
model = Counterparties
+ include_primary_keys = True
class BondForm(ModelForm):
upload_globeop = BooleanField(label="Upload to globeop?")
@@ -178,24 +179,31 @@ def list_counterparties(instr):
return render_template('counterparties.html', counterparties = cp_list.all())
@app.route('/edit_cp/<cpcode>', methods=['GET', 'POST'])
+@app.route('/edit_cp/', defaults={'cpcode': None}, methods=['GET', 'POST'])
def edit_counterparty(cpcode):
- cp = Counterparties.query.get(cpcode)
- cp_form = CounterpartyForm(obj = cp)
- old_instructions = cp.instructions
- if cp_form.is_submitted():
- if cp_form.validate():
- cp_form.populate_obj(cp)
- session = cp_form.get_session()
- instructions = cp.instructions
- if instructions.filename == '':
- cp.instructions = old_instructions
- else:
- cp.instructions = cp.name + '.pdf'
- instructions.save(os.path.join(app.config['CP_FOLDER'],
- cp.instructions))
- session.commit()
- return redirect(url_for('list_counterparties'))
- return render_template('edit_cp.html', form=cp_form, code=cpcode)
+ if cpcode:
+ cp = Counterparties.query.get(cpcode)
+ cp_form = CounterpartyForm(obj = cp)
+ else:
+ cp = Counterparties()
+ 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.filename == '':
+ cp.instructions = old_instructions
+ else:
+ cp.instructions = cp.name + '.pdf'
+ instructions.save(os.path.join(app.config['CP_FOLDER'],
+ cp.instructions))
+ session.commit()
+ return redirect(url_for('list_counterparties'))
+ else:
+ return render_template('edit_cp.html', form=cp_form, code=cpcode)
@app.route('/_ajax', methods=['GET'])
def get_bbg_id():