From 7fb2aa4e001ef6a83ec4268077ac9fe7355129e9 Mon Sep 17 00:00:00 2001 From: SeanChenTaipei Date: Tue, 14 Mar 2023 00:38:54 +0800 Subject: [PATCH] c --- main.py | 8 ++++---- templates/result_view.html | 25 ++----------------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/main.py b/main.py index de81730..f7f2622 100644 --- a/main.py +++ b/main.py @@ -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): diff --git a/templates/result_view.html b/templates/result_view.html index 719299d..b53298a 100644 --- a/templates/result_view.html +++ b/templates/result_view.html @@ -73,9 +73,9 @@ {% for a in data.assets %} {{ a|safe }} {% endfor %} - +
@@ -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); - } - }); - } - }); {% endblock script %} \ No newline at end of file