summaryrefslogtreecommitdiff
path: root/addons/web_graph/controllers
diff options
context:
space:
mode:
authorFabien Pinckaers <fp@openerp.com>2012-05-07 22:02:50 +0200
committerFabien Pinckaers <fp@openerp.com>2012-05-07 22:02:50 +0200
commit353f8ef8ee4965e7ec044e8302b1a34787b5a5cb (patch)
tree7a3b9bb02b8a93aabab4c6c7791b6fa31d060b92 /addons/web_graph/controllers
parentdbaef2660ad2a94e432ff8608a257c96095a962b (diff)
imp
bzr revid: fp@openerp.com-20120507200250-1w3b6xwv1c9vrhbs
Diffstat (limited to 'addons/web_graph/controllers')
-rw-r--r--addons/web_graph/controllers/graph.py63
1 files changed, 60 insertions, 3 deletions
diff --git a/addons/web_graph/controllers/graph.py b/addons/web_graph/controllers/graph.py
index aace37a4a26..478941b58e7 100644
--- a/addons/web_graph/controllers/graph.py
+++ b/addons/web_graph/controllers/graph.py
@@ -1,17 +1,74 @@
# -*- coding: utf-8 -*-
try:
+ # embedded
import openerp.addons.web.common.http as openerpweb
+ from openerp.addons.web.controllers.main import View
except ImportError:
+ # standalone
import web.common.http as openerpweb
+ from web.controllers.main import View
-class Widgets(openerpweb.Controller):
+from lxml import etree
+
+class GraphView(View):
_cp_path = '/web_graph/graph'
@openerpweb.jsonrequest
- def data_get(self, req, domain=[], context={}, group_by=[], view_id=False, orientation=False, **kwargs):
+ def data_get(self, req, model=None, domain=[], context={}, group_by=[], view_id=False, orientation=False, **kwargs):
print '---'
print req
print domain
print context
print group_by
- return [{'hello': 3}]
+ obj = req.session.model(model)
+
+ res = obj.fields_view_get(view_id, 'graph')
+ fields = res['fields']
+ toload = filter(lambda x: x not in fields, group_by)
+ if toload:
+ fields.update( obj.fields_get(toload, context) )
+
+ tree = etree.fromstring(res['arch'])
+
+ pos = 0
+ xaxis = group_by or []
+ yaxis = []
+ for field in tree.iter(tag='field'):
+ if (field.tag != 'field') or (not field.get('name')):
+ continue
+ assert field.get('name'), "This <field> tag must have a 'name' attribute."
+ if (not group_by) and ((not pos) or field.get('group')):
+ xaxis.append(field.get('name'))
+ if pos and not field.get('group'):
+ yaxis.append(field.get('name'))
+ pos += 1
+
+ assert len(xaxis), "No field for the X axis!"
+ assert len(yaxis), "No field for the Y axis!"
+ print "X", xaxis, "Y", yaxis
+
+ # Convert a field's data into a displayable string
+ def _convert(field, data):
+ if fields[field]['type']=='many2one':
+ return data and data[1] or ""
+ return data or ""
+
+ result = []
+ for x in xaxis:
+
+ res = obj.read_group(domain, yaxis+[x], [x], context=context)
+ print res
+ result.append( {
+ 'data': map(lambda record: (_convert(x, record[x]), record[yaxis[0]]), res),
+ 'label': fields[x]['string']
+ })
+
+ print result
+ return result
+ [
+ {
+ 'data': 3,
+ 'label': "Axis Name"
+ }
+ ]
+