summaryrefslogtreecommitdiff
path: root/addons/web/controllers/pivot.py
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2014-12-19 13:38:37 +0100
committerGéry Debongnie <ged@odoo.com>2014-12-19 14:34:23 +0100
commit2c08dc0ba610db61fe349d1602c12528ca8fc715 (patch)
tree143cb7f61e45e027c63be321ee3d4031963df1e7 /addons/web/controllers/pivot.py
parent9f7a0c096f0d3deabf8baf7be33b108f5b7884b5 (diff)
[IMP] web: new pivot view, full rewrite of graph view
This commit is a split of the former graphview into a pivot view (the tabular view) and graph view (the various charts). The code was fully rewritten. * pivot view should be faster (better underlying data structure and better algorithm) * better integration with the web client (use of sidebar, of menu buttons, bettor style) * new feature: pivot view can be sorted * new feature: pivot view cells can be clicked to open a list view with the corresponding domain * web_graph addon was removed, and the graph view code has been moved to the addon web. * the interaction with the searchbar was changed (no more column facet) * better and simpler code for graph view * mary corner cases in graph charts have been corrected (for ex, pie chart with positive and negative numbers) * graph/pivot correctly save their state when added to dashboard/saved (state such as current measure, chart mode, column groupbys, ...)
Diffstat (limited to 'addons/web/controllers/pivot.py')
-rw-r--r--addons/web/controllers/pivot.py88
1 files changed, 88 insertions, 0 deletions
diff --git a/addons/web/controllers/pivot.py b/addons/web/controllers/pivot.py
new file mode 100644
index 00000000000..3ec3dbd91be
--- /dev/null
+++ b/addons/web/controllers/pivot.py
@@ -0,0 +1,88 @@
+from openerp import http
+import simplejson
+from openerp.http import request, serialize_exception as _serialize_exception
+from cStringIO import StringIO
+from collections import deque
+
+try:
+ import xlwt
+except ImportError:
+ xlwt = None
+
+class TableExporter(http.Controller):
+
+ @http.route('/web/pivot/check_xlwt', type='json', auth='none')
+ def check_xlwt(self):
+ return xlwt is not None
+
+
+ @http.route('/web/pivot/export_xls', type='http', auth="user")
+ def export_xls(self, data, token):
+ jdata = simplejson.loads(data)
+ nbr_measures = jdata['nbr_measures']
+ workbook = xlwt.Workbook()
+ worksheet = workbook.add_sheet(jdata['title'][:30])
+ header_bold = xlwt.easyxf("font: bold on; pattern: pattern solid, fore_colour gray25;")
+ header_plain = xlwt.easyxf("pattern: pattern solid, fore_colour gray25;")
+ bold = xlwt.easyxf("font: bold on;")
+
+ # Step 1: writing headers
+ headers = jdata['headers']
+
+ # x,y: current coordinates
+ # carry: queue containing cell information when a cell has a >= 2 height
+ # and the drawing code needs to add empty cells below
+ x, y, carry = 1, 0, deque()
+ for i, header_row in enumerate(headers):
+ worksheet.write(i,0, '', header_plain)
+ for header in header_row:
+ while (carry and carry[0]['x'] == x):
+ cell = carry.popleft()
+ for i in range(nbr_measures):
+ worksheet.write(y, x+i, '', header_plain)
+ if cell['height'] > 1:
+ carry.append({'x': x, 'height':cell['height'] - 1})
+ x = x + nbr_measures
+ style = header_plain if 'expanded' in header else header_bold
+ for i in range(header['width']):
+ worksheet.write(y, x + i, header['title'] if i == 0 else '', style)
+ if header['height'] > 1:
+ carry.append({'x': x, 'height':header['height'] - 1})
+ x = x + header['width'];
+ while (carry and carry[0]['x'] == x):
+ cell = carry.popleft()
+ for i in range(nbr_measures):
+ worksheet.write(y, x+i, '', header_plain)
+ if cell['height'] > 1:
+ carry.append({'x': x, 'height':cell['height'] - 1})
+ x = x + nbr_measures
+ x, y = 1, y + 1
+
+ # Step 2: measure row
+ if nbr_measures > 1:
+ worksheet.write(y,0, '', header_plain)
+ for measure in jdata['measure_row']:
+ style = header_bold if measure['is_bold'] else header_plain
+ worksheet.write(y, x, measure['measure'], style);
+ x = x + 1
+ y = y + 1
+
+ # Step 3: writing data
+ x = 0
+ for row in jdata['rows']:
+ worksheet.write(y, x, row['indent'] * ' ' + row['title'], header_plain)
+ for cell in row['values']:
+ x = x + 1
+ if cell.get('is_bold', False):
+ worksheet.write(y, x, cell['value'], bold)
+ else:
+ worksheet.write(y, x, cell['value'])
+ x, y = 0, y + 1
+
+ response = request.make_response(None,
+ headers=[('Content-Type', 'application/vnd.ms-excel'),
+ ('Content-Disposition', 'attachment; filename=table.xls;')],
+ cookies={'fileToken': token})
+ workbook.save(response.stream)
+
+ return response