Include xml2json_direct in main. Converted node.@attribute to node.attrs = {}
bzr revid: fme@openerp.com-20110303145552-f4cbxu2oi01ykbxl
This commit is contained in:
parent
3925bdae0f
commit
f435d8ca99
|
@ -1,11 +1,49 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import json,os,sys,traceback
|
||||
|
||||
import xml2json_direct
|
||||
import json, os, sys, traceback
|
||||
|
||||
import openerpweb
|
||||
|
||||
from xml.etree import ElementTree
|
||||
|
||||
class Xml2Json:
|
||||
# xml2json-direct
|
||||
# Simple and straightforward XML-to-JSON converter in Python
|
||||
# New BSD Licensed
|
||||
#
|
||||
# URL: http://code.google.com/p/xml2json-direct/
|
||||
@staticmethod
|
||||
def convert_to_json(s):
|
||||
return json.dumps(Xml2Json.convert_to_structure(s), sort_keys=True, indent=4)
|
||||
|
||||
@staticmethod
|
||||
def convert_to_structure(s):
|
||||
root = ElementTree.fromstring(s)
|
||||
return Xml2Json.convert_element(root)
|
||||
|
||||
@staticmethod
|
||||
def convert_element(el, skip_whitespaces=True):
|
||||
res = {}
|
||||
if el.tag[0]=="{":
|
||||
ns, name = el.tag.rsplit("}",1)
|
||||
res["tag"] = name
|
||||
res["namespace"] = ns[1:]
|
||||
else:
|
||||
res["tag"] = el.tag
|
||||
res["attrs"] = {}
|
||||
for k,v in el.items():
|
||||
res["attrs"][k] = v
|
||||
kids = []
|
||||
if el.text and (not skip_whitespaces or el.text.strip() != ''):
|
||||
kids.append(el.text)
|
||||
for kid in el:
|
||||
kids.append(Xml2Json.convert_element(kid))
|
||||
if kid.tail and (not skip_whitespaces or kid.tail.strip() != ''):
|
||||
kids.append(kid.tail)
|
||||
if len(kids):
|
||||
res["children"] = kids
|
||||
return res
|
||||
|
||||
#----------------------------------------------------------
|
||||
# OpenERP Web base Controllers
|
||||
#----------------------------------------------------------
|
||||
|
@ -152,7 +190,7 @@ class FormView(openerpweb.Controller):
|
|||
def load(self,req,model,view_id):
|
||||
m = req.session.model(model)
|
||||
r = m.fields_view_get(view_id,'form')
|
||||
r["arch"]=xml2json_direct.convert_to_structure(r["arch"])
|
||||
r["arch"]=Xml2Json.convert_to_structure(r["arch"])
|
||||
return {'fields_view':r}
|
||||
|
||||
class ListView(openerpweb.Controller):
|
||||
|
@ -161,7 +199,7 @@ class ListView(openerpweb.Controller):
|
|||
def load(self,req,model,view_id):
|
||||
m = req.session.model(model)
|
||||
r = m.fields_view_get(view_id,'tree')
|
||||
r["arch"]=xml2json_direct.convert_to_structure(r["arch"])
|
||||
r["arch"]=Xml2Json.convert_to_structure(r["arch"])
|
||||
return {'fields_view':r}
|
||||
|
||||
class SearchView(openerpweb.Controller):
|
||||
|
@ -170,7 +208,7 @@ class SearchView(openerpweb.Controller):
|
|||
def load(self,req,model,view_id):
|
||||
m = req.session.model(model)
|
||||
r = m.fields_view_get(view_id,'search')
|
||||
r["arch"]=xml2json_direct.convert_to_structure(r["arch"])
|
||||
r["arch"]=Xml2Json.convert_to_structure(r["arch"])
|
||||
return {'fields_view':r}
|
||||
|
||||
class Action(openerpweb.Controller):
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
<table id="todo_use_unique_id" class="jqGrid"></table>
|
||||
</t>
|
||||
<t t-name="FormView">
|
||||
<h3><t t-esc="fields_view.arch['@string']"/></h3>
|
||||
<h3><t t-esc="fields_view.arch.attrs.string"/></h3>
|
||||
<div style="text-align:right;">
|
||||
<input type="button" value="First"/>
|
||||
<input type="button" value="<<"/>
|
||||
|
@ -94,9 +94,9 @@
|
|||
</t>
|
||||
-->
|
||||
<t t-if="node.tag == 'field'">
|
||||
<t t-esc="node['@string']"/>
|
||||
<t t-esc="node['@name']"/>
|
||||
<input type="text" t-att-name="node['@name']"/>
|
||||
<t t-esc="node.attrs.string"/>
|
||||
<t t-esc="node.attrs.name"/>
|
||||
<input type="text" t-att-name="node.attrs.name"/>
|
||||
<br/>
|
||||
</t>
|
||||
<t t-foreach="node.children || []" t-as="node">
|
||||
|
@ -104,7 +104,7 @@
|
|||
</t>
|
||||
</t>
|
||||
<t t-name="SearchView">
|
||||
<h3><t t-esc="fields_view.arch['@string']"/></h3>
|
||||
<h3><t t-esc="fields_view.arch.attrs['string']"/></h3>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<t t-call="SearchView.node">
|
||||
|
@ -141,10 +141,10 @@
|
|||
Also add a TODO about t-code=""
|
||||
|
||||
-->
|
||||
<button type="button" t-att-title="node['@help']">
|
||||
<img t-if="node['@icon']" t-att-src="'/base/static/openerp/img/icons/' + node['@icon'] + '.png'" width="16" height="16"/>
|
||||
<br t-if="node['@icon'] and node['@string']"/>
|
||||
<t t-esc="node['@string']"/>
|
||||
<button type="button" t-att-title="node.attrs.help">
|
||||
<img t-if="node.attrs.icon" t-att-src="'/base/static/openerp/img/icons/' + node.attrs.icon + '.png'" width="16" height="16"/>
|
||||
<br t-if="node.attrs.icon and node.attrs.string"/>
|
||||
<t t-esc="node.attrs.string"/>
|
||||
</button>
|
||||
<t t-if="next_node_type != 'filter'">
|
||||
</td>
|
||||
|
@ -161,13 +161,14 @@
|
|||
<tr>
|
||||
</t>
|
||||
<t t-if="node.tag == 'field'">
|
||||
<t t-set="orm" t-value="fields_view.fields[node.attrs.name] || {}"/>
|
||||
<td>
|
||||
<label style="display: block" t-att-title="node['@help']">
|
||||
<t t-esc="node['@string']"/><t t-esc="node['@name']"/>
|
||||
<span t-if="node['@help']">(?)</span>
|
||||
<label style="display: block" t-att-title="orm.help || node.attrs.help">
|
||||
<t t-esc="orm.string || node.attrs.string || node.attrs.name"/>
|
||||
<span t-if="orm.help || node.attrs.help">(?)</span>
|
||||
</label>
|
||||
<div>
|
||||
<input type="text" t-att-name="node['@name']"/>
|
||||
<input type="text" t-att-name="node.attrs.name"/>
|
||||
</div>
|
||||
</td>
|
||||
</t>
|
||||
|
|
|
@ -559,7 +559,7 @@ openerp.base.ListView = openerp.base.Controller.extend({
|
|||
var self = this;
|
||||
this.fields_view = data.fields_view;
|
||||
//this.log(this.fields_view);
|
||||
this.name = ""+this.fields_view.arch["@string"];
|
||||
this.name = "" + this.fields_view.arch.attrs.string;
|
||||
this.$element.html(QWeb.render("ListView", {"fields_view": this.fields_view}));
|
||||
this.$table = this.$element.find("table");
|
||||
this.cols = [];
|
||||
|
@ -570,9 +570,9 @@ openerp.base.ListView = openerp.base.Controller.extend({
|
|||
for(var i = 0; i < tree.length; i++) {
|
||||
var col = tree[i];
|
||||
if(col.tag == "field") {
|
||||
this.cols.push(col["@name"]);
|
||||
this.colnames.push(col["@name"]);
|
||||
this.colmodel.push({ name: col["@name"], index: col["@name"] });
|
||||
this.cols.push(col.attrs.name);
|
||||
this.colnames.push(col.attrs.name);
|
||||
this.colmodel.push({ name: col.attrs.name, index: col.attrs.name });
|
||||
}
|
||||
}
|
||||
//this.log(this.cols);
|
||||
|
@ -643,7 +643,7 @@ openerp.base.SearchView = openerp.base.Controller.extend({
|
|||
},
|
||||
on_loaded: function(data) {
|
||||
this.fields_view = data.fields_view;
|
||||
//this.log(this.fields_view);
|
||||
this.log(this.fields_view);
|
||||
this.input_ids = {};
|
||||
this.$element.html(QWeb.render("SearchView", {"fields_view": this.fields_view}));
|
||||
this.$element.find("#search").bind('click',this.on_search);
|
||||
|
|
Loading…
Reference in New Issue