views.py 2.15 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

# seller's rating
9
"""def ratingsAverage(seller):
10
11
12
13
14
15
16
17
    sellerRating = Seller.objects.filter(user__username=seller)
    ratingNumber = 0
    ratingTotal = 0
    ratingAverage = 0
    for rating in sellerRating:
        ratingNumber += 1
        ratingTotal += rating
    ratingAverage = ratingTotal/ratingNumber
18
    return ratingNumber"""
19
20
21

### VIEWS ###

Daniel W Bond's avatar
Daniel W Bond committed
22
23
24
25
26
27
def privacy_opt_out(request):
    # merely forms
    return render(request, 'privacy_opt_out.html', {
   },
   )

28
# User profile page
29
30
class DetailStudent(LoginRequiredMixin, DetailView):
    model = Student
31
32

    def get_context_data(self, **kwargs):
33
34
35
36
37
38
39
40
41
42
43
44

        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
45
46
47
48
                    try:
                        proceeds = proceeds + listing.final_price()
                    except:
                        pass
49
50
51
52
            return proceeds

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

53
        context = super(DetailStudent, self).get_context_data(**kwargs)
54

55
        #context['listings'] = Listing.objects.filter(seller='2')
56
        context['listings'] = student_listings
57
        context['me'] = self.get_object().pk
58
        context['lookouts'] = Lookout.objects.filter(owner=self.get_object())
59
60
61
62

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

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

65
66
        return context

67
    login_url = '/'
68

Daniel W Bond's avatar
Daniel W Bond committed
69
70
# manage all listings -- close your listings, delete your listings, see your bids, remove your bids, close your bids, etc -- on both sides of the transactions, and the ratings
# other students see all of your previous transactions but without the editing options ofc