def parse(self, root, fields=None): for node in root.childNodes: if not node.nodeType==node.ELEMENT_NODE: continue attrs = tools.node_attributes(node) field = fields.get(attrs['name']) field.update(attrs) if field['name'] == 'name' or field['name'] == 'ponderation': if field['name'] == 'ponderation': field['type'] = 'url' field['colspan'] = 3 self.head += [field]
def default(self, args=None, **kw): # lang_proxy = rpc.RPCProxy('res.lang') # if(kw.get('lang_code')): # language = kw['lang_code'] # context = rpc.session.context # # context['lang'] = language # lang_id = lang_proxy.search([]) # lang_data = lang_proxy.read(lang_id, [], rpc.session.context) # cherrypy.session['language'] = context['lang'] # cherrypy.session['lang_data'] = lang_data # else: # search_lang = lang_proxy.search([]) # lang_data = lang_proxy.read(search_lang, [], rpc.session.context) # language = 'en_US' # context = rpc.session.context # context['lang'] = language # # if(cherrypy.session.has_key('language')): # cherrypy.session['language'] # cherrypy.session['lang_data'] # else: # cherrypy.session['language'] = context['lang'] # cherrypy.session['lang_data'] = lang_data # selected_items = kw.get('ids', []) selected_items = selected_items and eval(str(selected_items)) if args and not selected_items: pack_proxy = rpc.RPCProxy('evaluation.pack') packs = pack_proxy.search([('name', '=', args)], 0, 0, 0, rpc.session.context) item_ids = pack_proxy.read(packs, ['item_ids'], rpc.session.context) selected_items = item_ids[0].get('item_ids') user_info = cherrypy.session.get('login_info', '') context = rpc.session.context model = 'comparison.factor' proxy = rpc.RPCProxy(model) domain = [('parent_id', '=', False)] ids = proxy.search(domain, 0, 0, 0, context) view = proxy.fields_view_get(False, 'tree', context) fields = proxy.fields_get(False, context) field_parent = view.get("field_parent") or 'child_ids' dom = xml.dom.minidom.parseString(view['arch'].encode('utf-8')) root = dom.childNodes[0] attrs = tools.node_attributes(root) self.head = [] self.parse(root, fields) self.headers = [] add_factor = {} add_factor['name'] = "add_factor" add_factor['type'] = "image" add_factor['string'] = '' add_factor['colspan'] = 2 sh_graph = {} sh_graph['name'] = 'show_graph' sh_graph['type'] = 'image' sh_graph['string'] = '' sh_graph['colspan'] = -1 incr = {} incr['name'] = 'incr' incr['type'] = 'image' incr['string'] = '' incr['colspan'] = -1 decr = {} decr['name'] = 'decr' decr['type'] = 'image' decr['string'] = '' decr['colspan'] = -1 self.headers += [self.head[0]] self.headers += [add_factor] self.headers += [sh_graph] self.headers += [self.head[1]] self.headers += [incr] self.headers += [decr] fields = [] item_model = 'comparison.item' proxy_item = rpc.RPCProxy(item_model) item_ids = proxy_item.search([], 0, 0, 0, context) res = proxy_item.read(item_ids, ['name', 'code', 'load_default']) titles = [] ses_id = [] for r in res: title = {} title['sel'] = False if selected_items: ses_id = selected_items item = {} for s in selected_items: if r['id'] == s: item['id'] = r['id'] item['type'] = 'url' item['string'] = r['name'] item['name'] = r['name'] item['code'] = r['code'] title['sel'] = True title['load'] = r['load_default'] self.headers += [item] elif r['load_default']: item = {} item['id'] = r['id'] item['type'] = 'url' item['string'] = r['name'] item['name'] = r['name'] item['code'] = r['code'] self.headers += [item] ses_id.append(r['id']) cherrypy.session['selected_items'] = ses_id title['name'] = r['name'] title['id'] = r['id'] title['code'] = r['code'] title['load'] = r['load_default'] titles += [title] sel_ids=[] for t in titles: if t['load'] or t['sel']: sel_ids += [t['id']] # cherrypy.response.simple_cookie['selected_items'] = sel_ids for field in self.headers: if field['name'] == 'name' or field['name'] == 'ponderation': fields += [field['name']] fields = jsonify.encode(fields) icon_name = self.headers[0].get('icon') # if kw.has_key('all'): # self.url = '/comparison/data' # self.url_params = dict(model=model, # ids=ids, # fields=ustr(fields), # domain=ustr(domain), ## context=ustr(context), # field_parent=field_parent, # icon_name=icon_name,all = kw.get('all')) # else: self.url = '/comparison/data' self.url_params = dict(model=model, ids=ids, fields=ustr(fields), domain=ustr(domain), context=ustr(context), field_parent=field_parent, icon_name=icon_name) def _jsonify(obj): for k, v in obj.items(): if isinstance(v, dict): obj[k] = _jsonify(v) return jsonify.encode(obj) self.url_params = _jsonify(self.url_params) self.headers = jsonify.encode(self.headers) return dict(headers=self.headers, url_params=self.url_params, url=self.url, titles=titles, selected_items=selected_items)