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
14

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

        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
27
28
29
30
                    try:
                        proceeds = proceeds + listing.final_price()
                    except:
                        pass
31
32
33
34
            return proceeds

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

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

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

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

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

47
48
        return context

49
    login_url = '/'