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

from core.models import Student
5
6
from lookouts.models import Lookout
from trades.models import Listing
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
45
46
47
48
49

        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:
                    proceeds = proceeds + listing.finalPrice
            return proceeds

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

50
        context = super(DetailStudent, self).get_context_data(**kwargs)
51

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

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

60
61
        return context

62
    login_url = '/'
63

Daniel W Bond's avatar
Daniel W Bond committed
64
65
# 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