def data(self, model, ids=[], fields=[], field_parent=None, icon_name=None, domain=[], context={}, sort_by=None, sort_order="asc", factor_id=None, ponderation=None, parent_id=None, parent_name=None, ftype='',all = None): ids = ids or [] if isinstance(ids, basestring): ids = [int(id) for id in ids.split(',')] res = None user_info = cherrypy.session.get('login_info', '') if parent_id: if not user_info: return dict(error="You are not logged in...") user_proxy = rpc.RPCProxy('comparison.user') user_id = user_proxy.search([('name', '=', user_info)]) new_fact_proxy = rpc.RPCProxy(model) try: res = new_fact_proxy.create({'name': factor_id, 'parent_id': parent_id, 'user_id': user_id[0], 'ponderation': ponderation, 'type': ftype}) ids = [res] except Exception, e: return dict(error=str(e))
def item_voting(self, **kw): user_info = cherrypy.session.get('login_info', '') id = kw.get('id') item = kw.get('header') iproxy = rpc.RPCProxy('comparison.item') item_id = iproxy.search([('name', '=', item)], 0, 0, 0, rpc.session.context)[0] fmodel = "comparison.factor" proxy = rpc.RPCProxy(fmodel) fres = proxy.read([id], [], rpc.session.context) factor_id = fres[0]['name'] child_ids = fres[0]['child_ids'] child = [] for ch in child_ids: chid = {} chd = proxy.read([ch], [], rpc.session.context) chid['name'] = chd[0]['name'] chid['id'] = ch chid['type'] = chd[0]['type'] if chid['type'] == 'criterion': child += [chid] vproxy = rpc.RPCProxy('comparison.vote.values') val = vproxy.search([], 0, 0, 0, rpc.session.context) value_name = vproxy.read(val, ['name'], rpc.session.context) if not user_info: return dict(item_id=item_id, item=item, child=child, factor_id=factor_id, value_name=value_name, id=id, error="You are not logged in...") else: return dict(item_id=item_id, item=item, child=child, factor_id=factor_id, value_name=value_name, id=id, error="")
def index(self): proxy = rpc.RPCProxy('comparison.item') url_re = re.compile('(http\:\/\/[^\s]+)|(file\:\/\/[^\s]+)|(ftp\:\/\/[^\s]+)|(https\:\/\/[^\s]+)', re.MULTILINE) ids = proxy.search([], 0, 0, 0, rpc.session.context) res = proxy.read(ids, ['name', 'note', 'code'], rpc.session.context) full_dir = os.path.realpath("erpcomparator/static/images/Screenshots") lst_folder = os.listdir(full_dir) lst_folder.sort() for note in res: files = [] file_names = [] if note['note']: notes = str(note['note']) note['note'] = re.sub(r'<','less than',notes) or re.sub(r'>', 'greater than', notes) def substitue_url(a): url = a.group(0) return "<a href='%s'>%s</a>" % (url, url) note['note'] = url_re.sub(substitue_url, note['note']) note['note'] = note['note'].replace('\n',' <br/>') note['note'] = note['note'].replace('&','&') for d in lst_folder: key = d.split("_")[0] if key == note['code']: files.append(d) lst = d.split('_')[1].split('.')[0] file_names.append(lst) note['code'] = {note['code']: [files, file_names]} return dict(res=res)
def check_data(self): criterions = None feedbacks = None model = 'comparison.factor' proxy = rpc.RPCProxy(model) criterions = proxy.search([]) criterions = len(criterions) vproxy = rpc.RPCProxy('comparison.vote') feedbacks = vproxy.search([]) feedbacks = len(feedbacks) user_info = cherrypy.session.get('login_info', None) return criterions, feedbacks, user_info
def update_item_voting(self, **kw): user_info = cherrypy.session.get('login_info', '') if not user_info: return dict(error="You are not logged in...") vals = kw.get('_terp_values', '') vals = vals.split('!') vals = [v.split('|') for v in vals] vals = [(x.split(','), y.split(','), z.split(','), w.split(',')) for x, y, z, w in vals] vals = [dict(v) for v in vals] list = [] user_proxy = rpc.RPCProxy('comparison.user') user_id = user_proxy.search([('name', '=', user_info)]) for v in vals: items = {} if v.get('score_id') != '0' and user_id: items['score_id'] = v.get('score_id') items['factor_id'] = v.get('id') items['item_id'] = v.get('item_id') items['note'] = str(v.get('note')) items['user_id'] = user_id[0] list += [items] vproxy = rpc.RPCProxy('comparison.vote.values') vid = vproxy.search([], 0, 0, 0, rpc.session.context) value_name = vproxy.read(vid, ['name'], rpc.session.context) smodel = "comparison.vote" sproxy = rpc.RPCProxy(smodel) res = None try: res = sproxy.vote_create_async(list) except Exception, e: return dict(error=str(e))
def voting(self, **kw): id = kw.get('id') pond_val = kw.get('pond_val') value = None user_info = cherrypy.session.get('login_info', '') if not user_info: return dict(value=value, error="You are not logged in...") model = "comparison.factor" proxy = rpc.RPCProxy(model) res = proxy.read([id], ['name', 'ponderation'], rpc.session.context) name = res[0]['name'] pond = res[0]['ponderation'] smodel = "comparison.ponderation.suggestion" sproxy = rpc.RPCProxy(smodel) if pond_val == 'incr': if pond > 0.0: pond = pond + 0.1 effect = 'positive' else: if pond > 0.0: pond = pond - 0.1 effect = 'negative' user_proxy = rpc.RPCProxy('comparison.user') user_id = user_proxy.search([('name', '=', user_info)]) user_id = user_id[0] try: value = sproxy.create({'factor_id': id, 'user_id': user_id, 'ponderation': pond, 'effect':effect}) except Exception, e: return dict(value=value, error=str(e))
def add_factor(self, **kw): user_info = cherrypy.session.get('login_info', '') id = kw.get('id') error = '' p_name = 'No Parent' child_type = 'view' model = "comparison.factor" proxy = rpc.RPCProxy(model) res = proxy.read([id], ['name', 'parent_id', 'child_ids'], rpc.session.context) parent = res[0].get('name') p_id = id count = range(0, 21) count = [c/float(10) for c in count] if not user_info: return dict(error="You are not logged in...", count=count, parent_id=p_id, parent_name=parent) else: return dict(error=error, count=count, parent_id=p_id, parent_name=parent)
def radar(self, **kw): item_ids = kw.get('ids') item_ids = item_ids and eval(str(item_ids)) ctx = rpc.session.context.copy() ctx.update(ctx or {}) parent_name = kw.get('factor_name') parent_name = parent_name.replace('@', '&') proxy_factor = rpc.RPCProxy('comparison.factor') child_name = [] child_ids = [] if parent_name == 'Summary': list = proxy_factor.search([('parent_id', '=', False)], 0, 0, 0, ctx) ch_ids = proxy_factor.read(list, [], ctx) for ch in ch_ids: cname = {} cname['name'] = ch['name'][:18] child_ids += [ch['id']] child_name += [cname] else: if '/' in parent_name: parent_name = parent_name.rsplit('/')[1] parent_list = proxy_factor.search([('name', '=', parent_name)], 0, 0, 0, ctx) child_ids = proxy_factor.read(parent_list, ['child_ids'], ctx) child_ids = child_ids[0].get('child_ids') child_list = proxy_factor.read(child_ids, ['name'], ctx) for ch in child_list: cname = {} cname['name'] = ch['name'][:18] child_name += [cname] elem = [] elements = {} elements["elements"] = [] #Required elements["title"] = {} #Optional elements["radar_axis"] = {} #Required elements["tooltip"] = { "mouse": 2, "stroke": 1, "colour": "#000000", "background": "#ffffff" } #Depend On Choice elements["bg_colour"] = "#ffffff" #Optional ChartColors = [ '#c4a000', '#ce5c00', '#8f5902', '#4e9a06', '#204a87', '#5c3566', '#a40000', '#babdb6', '#2e3436' ] proxy_item = rpc.RPCProxy('comparison.item') item_name = proxy_item.read(item_ids, ['name']) proxy_res = rpc.RPCProxy('comparison.factor.result') rids = proxy_res.search([('factor_id', 'in', child_ids)], 0, 0, 0, ctx) factor_res = proxy_res.read(rids, [], ctx) value = [] lables = [i['name'] for i in child_name] for item in item_name: val = [0] * len(lables) for factor in factor_res: if factor.get('item_id')[1] == item['name']: val[lables.index(factor.get('factor_id')[1] [:18])] = factor.get('result') / 10.0 value += [val] for n, j in enumerate(item_name): if n % 2 == 0: elem.append({ 'type': 'line_hollow', "values": value[n], "halo_size": 2, "width": 1, "dot-size": 2, "colour": ChartColors[n], "text": str(j['name']), "font-size": 12, "loop": True }) else: elem.append({ "type": "line_dot", "values": value[n], "halo_size": 2, "width": 1, "dot-size": 2, "colour": ChartColors[n], "text": str(j['name']), "font-size": 12, "loop": True }) elements["elements"] = elem elements["title"] = { "text": parent_name, "style": "{font-size: 15px; color: #50284A; text-align: left; font-weight: bold;}" } elements["radar_axis"] = { "max": 10, "colour": "#DAD5E0", "grid-colour": "#DAD5E0", "labels": { "labels": [], "colour": "#9F819F" }, "spoke-labels": { "labels": [ch['name'] for ch in child_name], "colour": "#5c3566" } } # elements["tooltip"] = {"mouse": 1} elements["bgcolor"] = "#ffffff" return elements
def index(self, **kw): ctx = rpc.session.context.copy() ctx.update(ctx or {}) proxy_factor = rpc.RPCProxy('comparison.factor') view_factor_id = kw.get('view_id', []) parent_name = kw.get('parent_name') sel_factor_id = [] if parent_name: parent_name = parent_name.replace('@', '&') sel_factor_id = proxy_factor.search([('name', '=', parent_name)], 0, 0, 0, ctx) proxy_item = rpc.RPCProxy('comparison.item') item_ids = proxy_item.search([], 0, 0, 0, ctx) res = proxy_item.read(item_ids, ['name'], ctx) titles = [] factors = [] summary = {} parent_child = [] selected_items = [] if cherrypy.session.has_key('selected_items'): selected_items = cherrypy.session['selected_items'] selected_items = selected_items and eval(str(selected_items)) for r in res: title = {} title['sel'] = False if selected_items: for s in selected_items: if r['id'] == s: title['sel'] = True title['name'] = r['name'] title['id'] = r['id'] titles += [title] # if view_factor_id: # view_factors = proxy_factor.search([('id', '=', [view_factor_id])]) # else: factors = proxy_factor.search([('parent_id', '=', False)], 0, 0, 0, ctx) parents = proxy_factor.read(factors, ['id', 'name'], ctx) for pch in parents: fact = proxy_factor.search([('id', '=', [pch['id']])], 0, 0, 0, ctx) parent_child += proxy_factor.read(fact, ['child_ids'], ctx) all_child = [] for ch in parent_child: pname = proxy_factor.read(ch['id'], ['name'], ctx) if ch.get('child_ids'): for c in ch['child_ids']: child = {} level2 = proxy_factor.read(c, ['name'], ctx) child['name'] = pname.get('name') + '/' + level2.get( 'name') child['id'] = level2.get('id') all_child += [child] view_name = None if view_factor_id: view = {} view_id = proxy_factor.read([view_factor_id], ['name'], ctx) view_name = view_id[0].get('name') view['id'] = view_id[0].get('id') view['name'] = view_name all_child += [view] return dict(titles=titles, parents=parents, view_name=view_name, all_child=all_child, selected_items=selected_items)
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)
except Exception, e: return dict(error=str(e)) if isinstance(fields, basestring): fields = eval(fields) if isinstance(domain, basestring): domain = eval(domain) if isinstance(context, basestring): context = eval(context) if field_parent and field_parent not in fields: fields.append(field_parent) proxy = rpc.RPCProxy(model) ctx = context or {} ctx.update(rpc.session.context.copy()) if icon_name: fields.append(icon_name) if not fields: fields = ['name', 'ponderation', 'child_ids'] fact_proxy = rpc.RPCProxy('comparison.factor') fields_info = proxy.fields_get(fields, ctx) result = proxy.read(ids, fields, ctx) prx = rpc.RPCProxy('comparison.factor.result') rids = prx.search([('factor_id', 'in', ids)], 0, 0, 0, ctx) factor_res = prx.read(rids, [], ctx)