Path: blob/master/ invest-robot-contest_tinkoff_trading_contest-main/tinkoff_contest/backtesting_app/views.py
5929 views
from django.shortcuts import render, redirect1from django.views import View2import json34from .forms import StrategyForm, BacktestStockForm5from .models import StrategyConfig67# Create your views here.8910class Backtest(View):1112@staticmethod13def get(request):14context = {15'Strategies': 1,16'StrategyForm': StrategyForm(),17}1819return render(request, "backtesting_app/choose_strat.html", context)2021@staticmethod22def post(request):23return redirect(to='backtest_config', pk=request.POST['strategy'])242526class BacktestConfig(View):2728@staticmethod29def get(request, pk):30try:31choosen_config = StrategyConfig.objects.filter(strategy__id=pk)[0].configuration32context = {33'config': choosen_config,34'time': BacktestStockForm(),35'button': 'Применить',36}37except IndexError:38context = {39'error': 'Стратегии с таким id не существует',40'button': 'Назад',41}4243return render(request, "backtesting_app/strategy_config.html", context)4445@staticmethod46def post(request, pk):47if len(request.POST) == 1:48return redirect(to='backtest')4950return redirect(to='backtest')5152535455