SeanChenTaipei 2 years ago
parent eade5dd009
commit 7fb2aa4e00
  1. 8
      main.py
  2. 25
      templates/result_view.html

@ -145,6 +145,7 @@ def login_post():
session['update_freq'] = 100
session['lastCreateTime'] = time.time()
session['tw'] = 1
session['currStockList'] = []
return redirect(url_for('index'))
else:
flash('使用者代號不對或密碼不對,請再試一次。', 'danger')
@ -515,8 +516,9 @@ def result_view():
fig = px.bar(ret_hist)
fig['layout'] = {}
data['bar'] = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
session['currStockList'] = data['assets']
return render_template('result_view.html', data=data)
@app.route('/copyPort', methods=['POST'])
@app.route('/copy_portfolio')
def copy_portfolio():
if login_required():
pass
@ -525,10 +527,8 @@ def copy_portfolio():
return redirect(url_for('login'))
if not 'tw' in session:
return redirect(url_for('index'))
stock_list = request.form.get('stockList')
stock_list = json.loads(stock_list)
session['tw'] = 0
return render_template('strategy_tw.html', data_us = data_us, data_tw=data_tw, stock=stock_list)
return render_template('strategy_tw.html', data_us = data_us, data_tw=data_tw, stock=session['currStockList'])
@app.errorhandler(404)
def page_not_found(e):

@ -73,9 +73,9 @@
{% for a in data.assets %}
<span class="badge text-bg-warning asset" name="stock" value="{{ a|safe }}">{{ a|safe }}</span>
{% endfor %}
<button type="button" class="btn btn-outline-primary btn-sm" id="copy-port">
<a class="btn btn-outline-primary btn-sm" href="{{ url_for('copy_portfolio') }}">
複製投資組合
</button>
</a>
</div>
</div>
<div class="row">
@ -186,26 +186,5 @@
Plotly.newPlot("weight", w.data, wlayout, {responsive: true});
Plotly.newPlot("price", r.data, rlayout, {responsive: true});
Plotly.newPlot("bar", b.data, blayout, {responsive: true});
$('#copy-port').click(function(event) {
alert('投資組合即將複製。')
var stockList = [];
$('.asset').each(function(){
stockList.push($(this).text());
});
if (stockList.length > 1) {
$.ajax({
url: '/copyPort',
method: 'POST',
data: { stockList: JSON.stringify(stockList) },
success: function(response) {
console.log('success');
$(document.body).html(response);
},
error: function(xhr) {
console.log('Error submitting stock list: ' + xhr.responseText);
}
});
}
});
</script>
{% endblock script %}
Loading…
Cancel
Save