diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/Dawn/templates/base.html | 8 | ||||
| -rw-r--r-- | python/Dawn/views.py | 42 |
2 files changed, 32 insertions, 18 deletions
diff --git a/python/Dawn/templates/base.html b/python/Dawn/templates/base.html index 85db01c0..924c9ea0 100644 --- a/python/Dawn/templates/base.html +++ b/python/Dawn/templates/base.html @@ -30,7 +30,13 @@ <li><a href="{{url_for('trade_manage', kind = 'cds')}}">CDS</a></li> </ul> </li> - <li><a href="../counterparties">Counterparties</a></li> + <li class="dropdown"> + <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Counterparties <span class="caret"></span></a> + <ul class="dropdown-menu"> + <li><a href="../counterparties">List</a></li> + <li><a href="{{url_for('edit_counterparty', cpcode= None)}}">New</a></li> + </ul> + </li> </ul> </div> </nav> 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(): |
