views.py 1.48 KB
Newer Older
1
2
3
4
from django.views.generic import DetailView
from braces.views import LoginRequiredMixin

from core.models import Student
5
from lookouts.models import Lookout
Daniel W Bond's avatar
Daniel W Bond committed
6
from trades.models import Listing, Bid
7
8


9
10
class DetailStudent(LoginRequiredMixin, DetailView):
    model = Student
11
12
    template_name = 'profile.html'
    context_object_name = 'student'
13
    login_url = 'login'
14
15

    def get_context_data(self, **kwargs):
16
17
18
19
20
21
22
23
24
25
26
27

        def total_sales(listings):
            sales = 0
            for listing in listings:
                if listing.sold:
                    sales = sales + 1
            return sales

        def total_proceeds(listings):
            proceeds = 0
            for listing in listings:
                if listing.sold:
Daniel W Bond's avatar
Daniel W Bond committed
28
29
30
31
                    try:
                        proceeds = proceeds + listing.final_price()
                    except:
                        pass
32
33
34
35
            return proceeds

        student_listings = Listing.objects.filter(seller=self.get_object().pk)

36
        context = super(DetailStudent, self).get_context_data(**kwargs)
37

38
        #context['listings'] = Listing.objects.filter(seller='2')
39
        context['listings'] = student_listings
40
        context['me'] = self.get_object().pk
41
        context['lookouts'] = Lookout.objects.filter(owner=self.get_object())
42
43
44
45

        context['proceeds'] = total_proceeds(student_listings)
        context['sales'] = total_sales(student_listings)

46
        context['bids'] = Bid.objects.filter(bidder=self.get_object())
Daniel W Bond's avatar
Daniel W Bond committed
47

48
        return context