bzr revid: fp@openerp.com-20120507200250-1w3b6xwv1c9vrhbs
This commit is contained in:
Fabien Pinckaers 2012-05-07 22:02:50 +02:00
parent dbaef2660a
commit 353f8ef8ee
3 changed files with 62 additions and 4 deletions

View File

@ -8,7 +8,7 @@
* Stacked / Not Stacked for areas and bars
* Legends: top, inside (top/left), hidden
* Features: download as PNG or CSV, browse data grid, switch orientation
* Unlimited "Group By" levels, multi level analysis
* Unlimited "Group By" levels (not stacked), two cross level analysis (stacked)
""",
"version": "3.0",
"depends": ['web'],

View File

@ -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"
}
]

View File

@ -152,6 +152,7 @@ instance.web_graph.GraphView = instance.web.View.extend({
data = this.rpc(
'/web_graph/graph/data_get',
{
model: this.dataset.model,
domain: this.domain,
context: this.context,
group_by: this.group_by,