Prise en compte de la nouvelle signature de « translate » et prise en charge des...
[photoprint.git] / skins / order_list.py
1 ##parameters=b_start=0, key='created', reverse=False
2 from Products.CMFCore.utils import getToolByName
3 from Products.Plinn.PloneMisc import Batch
4 from Products.photoprint.utils import Message as _
5 from ZTUtils import make_query
6
7 wtool = getToolByName(context, 'portal_workflow')
8 mtool = getToolByName(context, 'portal_membership')
9 options = {}
10 folders = context.contentValues({'portal_type':'Order Folder'})
11 options['folders'] = folders
12
13 columns = ( {'key': 'created',
14 'title': _('Date'),
15 'width': None,
16 'colspan': None}
17 , {'key': 'customer',
18 'title': _('Customer'),
19 'width': None,
20 'colspan': None}
21 , {'key': 'id',
22 'title': _('Reference'),
23 'width': None,
24 'colspan': None}
25 , {'key': 'quantity',
26 'title': _('Prints'),
27 'width': None,
28 'colspan': None}
29 , {'key': 'amount',
30 'title': _('Amount'),
31 'width': None,
32 'colspan': None }
33 , {'key': 'state',
34 'title': _('State'),
35 'width': None,
36 'colspan': None }
37 )
38
39 target = context.absolute_url()
40
41 for column in columns :
42 images = []
43 if key == column['key']:
44 if reverse :
45 toggleImg = getattr(context, 'arrowDown.gif')
46 alt = _('descending sort')
47 else :
48 toggleImg = getattr(context, 'arrowUp.gif')
49 alt = _('ascending sort')
50 query = make_query(key=column['key'], reverse = not reverse)
51 images.append( {'src' : toggleImg.absolute_url(), 'alt' : alt} )
52 else :
53 query = make_query(key=column['key'], reverse = reverse)
54
55 column['url'] = '%s?%s' % (target, query)
56 column['images'] = images
57
58 options['columns'] = columns
59
60 def getReviewState(item) :
61 return wtool.getInfoFor(item, 'review_state', wf_id='order_workflow')
62
63 sortFuncs = {'created' : lambda a, b : cmp(a.created(), b.created())
64 ,'customer' : lambda a, b : cmp(a.Creator(), b.Creator())
65 ,'id' : lambda a, b : cmp(a.getId(), b.getId())
66 ,'quantity' : lambda a, b : cmp(a.quantity, b.quantity)
67 ,'amount' : lambda a, b : cmp(a.amountWithFees.getValues()['taxed'], b.amountWithFees.getValues()['taxed'])
68 ,'state' : lambda a, b : cmp(getReviewState(a), getReviewState(b))}
69
70 orders = context.contentValues({'portal_type':'Order'})
71 step = reverse and -1 or 1
72 orders.sort(sortFuncs[key])
73 orders = orders[::step]
74 options['key'] = key
75 options['reverse'] = reverse
76
77 def beforeGetItem(item) :
78 info = {}
79 info['url'] = item.absolute_url()
80 info['created'] = item.created()
81 info['reference'] = item.getId()
82 info['quantity'] = item.quantity
83 info['price'] = item.amountWithFees
84 info['state'] = wtool.getInfoFor(item, 'review_state', wf_id='order_workflow')
85 customer = mtool.getMemberById(item.Creator())
86 if customer :
87 info['customer'] = customer.getMemberFullName()
88 else :
89 info['customer'] = item.Creator()
90 return info
91
92 orders = Batch(orders, context.default_batch_size, b_start, orphan=0, quantumleap=1, before_getitem=beforeGetItem)
93 options['orders'] = orders
94
95 return context.order_list_template(**options)