~richies/+junk/unishop

« back to all changes in this revision

Viewing changes to unishop/widgets.py

  • Committer: RichieS at GMail
  • Date: 2011-12-11 21:23:44 UTC
  • Revision ID: richies@gmail.com-20111211212344-3k5nk1109g7f0lo6
Add a product listing
Make basket work correctly
Add ability to remove items from basket

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from .models import DBSession, ShopCategory, ShopSubCategory
 
1
from .models import DBSession, ShopCategory, ShopSubCategory, ShopBasket
 
2
from .userlib import UserLib
2
3
from pyramid.security import authenticated_userid
3
4
 
 
5
u = UserLib()
 
6
 
4
7
class WidgetLib():
5
8
    def logged_in(self, request):
6
9
        return authenticated_userid(request)
12
15
            for sub_row in row.category:
13
16
                row_data.append(sub_row.name)
14
17
            result[row.name] = row_data
15
 
        return result
 
 
b'\\ No newline at end of file'
 
18
        return result
 
19
    
 
20
    def right_menu(self, request):
 
21
        user = u.show(self.logged_in(request))
 
22
        result_dict = {}
 
23
        total = 0.00
 
24
        for row in DBSession.query(ShopBasket).filter_by(user_id=user.id):
 
25
            item = row.item
 
26
            total += item.price
 
27
            if not item.id in result_dict:
 
28
                result_dict[item.id] = [1, item.price, item]
 
29
            else:
 
30
                result_dict[item.id][0] += 1
 
31
                result_dict[item.id][1] += item.price
 
32
        return result_dict, round(total, 2)
 
 
b'\\ No newline at end of file'