37a0e4c90d576073027311fb3e400cf9e68e242a
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
7 wtool
= getToolByName(context
, 'portal_workflow')
8 mtool
= getToolByName(context
, 'portal_membership')
10 folders
= context
.contentValues({'portal_type':'Order Folder'})
11 options
['folders'] = folders
13 columns
= ( {'key': 'created',
18 'title': _('Customer'),
22 'title': _('Reference'),
39 target
= context
.absolute_url()
41 for column
in columns
:
43 if key
== column
['key']:
45 toggleImg
= getattr(context
, 'arrowDown.gif')
46 alt
= _('descending sort')
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
} )
53 query
= make_query(key
=column
['key'], reverse
= reverse
)
55 column
['url'] = '%s?%s' % (target
, query
)
56 column
['images'] = images
58 options
['columns'] = columns
60 def getReviewState(item
) :
61 return wtool
.getInfoFor(item
, 'review_state', wf_id
='order_workflow')
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
))}
70 orders
= context
.contentValues({'portal_type':'Order'})
71 step
= reverse
and -1 or 1
72 orders
.sort(sortFuncs
[key
])
73 orders
= orders
[::step
]
75 options
['reverse'] = reverse
77 def beforeGetItem(item
) :
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())
87 info
['customer'] = customer
.getMemberFullName()
89 info
['customer'] = item
.Creator()
92 orders
= Batch(orders
, 40, b_start
, orphan
=0, quantumleap
=1, before_getitem
=beforeGetItem
)
93 options
['orders'] = orders
95 return context
.order_list_template(**options
)