maniaquerie
[photoprint.git] / skins / my_orders.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 ctool = getToolByName(context, 'portal_catalog')
9 mtool = getToolByName(context, 'portal_membership')
10 utool = getToolByName(context, 'portal_url')
11 portal = utool.getPortalObject()
12 portal_url = utool()
13 member = mtool.getAuthenticatedMember()
14 options = {}
15
16 columns = ( {'key': 'created',
17 'title': _('Date'),
18 'width': None,
19 'colspan': None}
20 , {'key': 'id',
21 'title': _('Reference'),
22 'width': None,
23 'colspan': None}
24 , {'key': 'quantity',
25 'title': _('Prints'),
26 'width': None,
27 'colspan': None}
28 , {'key': 'amount',
29 'title': _('Amount'),
30 'width': None,
31 'colspan': None }
32 , {'key': 'state',
33 'title': _('State'),
34 'width': None,
35 'colspan': None }
36 )
37
38 target = context.absolute_url()
39
40 for column in columns :
41 column['url'] = None
42 column['images'] = None
43
44 options['columns'] = columns
45
46
47 orders = ctool(portal_type='Order', listCreators=member.getId(), sort_on='created', sort_order='reverse')
48
49 def beforeGetItem(item) :
50 item = item.getObject()
51 info = {}
52 info['url'] = item.absolute_url()
53 info['created'] = item.created()
54 info['reference'] = item.getId()
55 info['quantity'] = item.quantity
56 info['price'] = item.amountWithFees
57 info['state'] = wtool.getInfoFor(item, 'review_state', wf_id='order_workflow')
58 return info
59
60 orders = Batch(orders, context.default_batch_size, b_start, orphan=0, quantumleap=1, before_getitem=beforeGetItem)
61 options['orders'] = orders
62
63 breadcrumbs = [
64 { 'id' : 'root'
65 , 'title' : portal.title
66 , 'url' : portal_url},
67
68 {'id' : 'my_orders'
69 ,'title' : _('My orders')
70 , 'url' : '%s/my_orders' % portal_url}
71 ]
72
73 options['breadcrumbs'] = breadcrumbs
74
75 return context.my_orders_template(**options)