1 | ## Script (Python) "pin_statistics"
|
---|
2 | ##bind container=container
|
---|
3 | ##bind context=context
|
---|
4 | ##bind namespace=
|
---|
5 | ##bind script=script
|
---|
6 | ##bind subpath=traverse_subpath
|
---|
7 | ##parameters=
|
---|
8 | ##title=
|
---|
9 | ##
|
---|
10 | # $Id: pin_statistics.py 5657 2011-01-24 16:24:16Z henrik $
|
---|
11 | request = context.REQUEST
|
---|
12 | setheader = request.RESPONSE.setHeader
|
---|
13 | fields = ("id",
|
---|
14 | "date",
|
---|
15 | "used",
|
---|
16 | "total",
|
---|
17 | "cost",
|
---|
18 | )
|
---|
19 |
|
---|
20 | lines = []
|
---|
21 | lines.append(','.join(fields))
|
---|
22 | format = '"%(' + ')s","%('.join(fields) + ')s"'
|
---|
23 |
|
---|
24 | batches = []
|
---|
25 | for id, object in context.objectItems():
|
---|
26 | batch = {}
|
---|
27 | batch['id'] = id
|
---|
28 | batch['date'] = object.creation_date.strftime("%d/%m/%y")
|
---|
29 | batch_doc = object.getContent()
|
---|
30 | batch['used'] = batch_doc.getNumberOfUsedPins()
|
---|
31 | batch['total'] = batch_doc.no_of_pins
|
---|
32 | batch['cost'] = batch_doc.cost
|
---|
33 | lines.append(format % batch)
|
---|
34 |
|
---|
35 | setheader('Content-type','text/semicolon-seperated-values')
|
---|
36 | setheader('Content-Disposition:', 'attachment; filename="PinStatistics.csv"')
|
---|
37 | setheader('Expires', 'Mon, 26 Jul 1997 05:00:00GMT') # Date in the past
|
---|
38 | setheader('Cache-Control', 'no-store, no-cache,must-revalidate') # HTTP/1.1
|
---|
39 | setheader('Cache-Control', 'post-check=0,pre-check=0')
|
---|
40 | return '\n'.join(lines)
|
---|
41 |
|
---|