summaryrefslogtreecommitdiff
path: root/app/trading/views.py
blob: a2bc5eb9285a3b14a75ff509a9b6e4642860191c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from django.shortcuts import render
from django.views.generic.edit import FormView
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from utils.views import PaginatedListView

from .models import OptionsTrade, LuxTrade


class OptionsTradeResultsView(PaginatedListView):
    model = OptionsTrade

    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(OptionsTradeResultsView, self).get_context_data(**kwargs)
        return context

class TradeModelFormView(CreateView):
    model = LuxTrade
    fields = ['symbol', 'status', 'entry_price', 'stop_price', 'target_price', 'shares']
    success_url = '/trading/'
    template_name = 'trading/create_form.html'

class LuxTradeDetailView(UpdateView):
    model = LuxTrade
    fields = ['symbol', 'status', 'entry_price', 'stop_price', 'target_price', 'shares', 'close_price']
    template_name = 'trading/update_form.html'
    success_url = '/trading/'


class LuxTradeListView(PaginatedListView):
    model = LuxTrade
    template_name = 'trading/list.html'

    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(LuxTradeListView, self).get_context_data(**kwargs)
        context['open_trades'] = LuxTrade.objects.filter(status=0)
        context['watch_trades'] = LuxTrade.objects.filter(status=2)
        return context

    def get_queryset(self):
        queryset = super(LuxTradeListView, self).get_queryset()
        return queryset.filter(status=1)