wcs.xlwt.diff
| wcs/backoffice/root.ptl (copie de travail) | ||
|---|---|---|
|
from wcs.forms.backoffice import FormDefUI
|
||
|
try:
|
||
|
import pyExcelerator
|
||
|
import xlwt
|
||
|
except ImportError:
|
||
|
pyExcelerator = None
|
||
|
xlwt = None
|
||
|
def format_time(t, units = 2):
|
||
|
days = int(t/86400)
|
||
| ... | ... | |
|
'<ul>'
|
||
|
'<li><a href="listing">%s</a></li>' % _('Listing')
|
||
|
'<li><a href="csv">%s</a></li>' % _('Listing in CSV format')
|
||
|
if pyExcelerator:
|
||
|
if xlwt:
|
||
|
'<li><a href="xls">%s</a></li>' % _('Listing in Excel format')
|
||
|
'<li><a href="pending">%s</a></li>' % _('Pending Forms')
|
||
|
'<li><a href="stats">%s</a></li>' % _('Statistics')
|
||
| ... | ... | |
|
return output.getvalue()
|
||
|
def xls(self):
|
||
|
if pyExcelerator is None:
|
||
|
if xlwt is None:
|
||
|
raise errors.TraversalError()
|
||
|
get_logger().info('backoffice - form %s - as excel' % self.formdef.name)
|
||
|
fields = FormDefUI(self.formdef).get_listing_fields()
|
||
|
w = pyExcelerator.Workbook()
|
||
|
pyExcelerator.UnicodeUtils.DEFAULT_ENCODING = 'iso-8859-15'
|
||
|
w = xlwt.Workbook(encoding='utf-8')
|
||
|
ws = w.add_sheet('1')
|
||
|
for i, f in enumerate(self.csv_tuple_heading(fields)):
|
||
| ... | ... | |
|
for j, elem in enumerate(self.csv_tuple(fields, filled)):
|
||
|
ws.write(i+1, j, elem)
|
||
|
output = cStringIO.StringIO()
|
||
|
w.save(output)
|
||
|
response = get_response()
|
||
|
response.set_content_type('application/vnd.ms-excel')
|
||
|
response.set_header('content-disposition', 'attachment; filename=export.xls')
|
||
|
return w.get_biff_data()
|
||
|
return output.getvalue()
|
||
|
def stats [html] (self):
|
||
|
get_logger().info('backoffice - form %s - stats' % self.formdef.name)
|
||