def create(self, params): view_id = (params.view_ids or False) and params.view_ids[0] domain = params.domain context = params.context res_id = params.ids model = params.model if view_id: view_base = rpc.session.execute('object', 'execute', 'ir.ui.view', 'read', [view_id], ['model', 'type'], context)[0] model = view_base['model'] view = cache.fields_view_get(model, view_id, view_base['type'], context) else: view = cache.fields_view_get(model, False, 'tree', context) tree = tree_view.ViewTree(view, model, res_id, domain=domain, context=context, action="/tree/action") if tree.toolbar: for tool in tree.toolbar: if tool.get('icon'): tool['icon'] = icons.get_icon(tool['icon']) else: tool['icon'] = False return dict(tree=tree, model=model)
def generate_url_for_picture(model, name, id, value): url = '' if isinstance(value, (tuple, list)) and len(value)==2: type, data = value else: type, data = None, value if data: if type == 'stock': stock, size = data url = icons.get_icon(stock) else: key = "%s,%s:%s@%s" % (model, id or 0, name, time.time()) hashkey = str(hash(key)) fname = get_temp_file(hash=hashkey) tmp = open(fname, "w") try: tmp.write(base64.decodestring(data)) finally: tmp.close() url = tools.url("/image/get_picture", hash=hashkey) else: url = tools.url("/static/images/blank.gif") return url
def __init__(self, **attrs): icon = attrs.get('name') attrs['name'] = attrs.get('name', 'Image').replace("-","_") super(Image, self).__init__(**attrs) self.filename = attrs.get('filename', '') if getattr(self,'size', ''): self.img_size = True else: self.img_size = False if 'widget' in attrs: self.stock = False self.field = self.name.split('/')[-1] if self.id: self.src = tools.url('/image/get_image', model=self.model, id=self.id, field=self.field) else: self.src = attrs.get('value') self.height = attrs.get('img_height', attrs.get('height', 160)) self.width = attrs.get('img_width', attrs.get('width', 200)) self.validator = validators.Binary() else: self.src = icons.get_icon(icon) if self.readonly: self.editable = False
def __init__(self, **attrs): icon = attrs.get('name') attrs['name'] = attrs.get('name', 'Image').replace("-", "_") super(Image, self).__init__(**attrs) self.filename = attrs.get('filename', '') if getattr(self, 'size', ''): self.img_size = True else: self.img_size = False if 'widget' in attrs: self.stock = False self.field = self.name.split('/')[-1] if self.id: self.src = tools.url('/image/get_image', model=self.model, id=self.id, field=self.field) else: self.src = attrs.get('value') self.height = attrs.get('img_height', attrs.get('height', 160)) self.width = attrs.get('img_width', attrs.get('width', 200)) self.validator = validators.Binary() else: self.src = icons.get_icon(icon) if self.readonly: self.editable = False
def generate_url_for_picture(model, name, id, value): url = '' if isinstance(value, (tuple, list)) and len(value) == 2: type, data = value else: type, data = None, value if data: if type == 'stock': stock, size = data url = icons.get_icon(stock) else: key = "%s,%s:%s@%s" % (model, id or 0, name, time.time()) hashkey = str(hash(key)) fname = get_temp_file(hash=hashkey) tmp = open(fname, "w") try: tmp.write(base64.decodestring(data)) finally: tmp.close() url = tools.url("/image/get_picture", hash=hashkey) else: url = tools.url("/static/images/blank.gif") return url
def __init__(self, **attrs): super(Button, self).__init__(**attrs) # remove mnemonic self.string = re.sub('_(?!_)', '', self.string or '') self.btype = attrs.get('special', attrs.get('type', 'workflow')) self.context = attrs.get("context") or {} self.nolabel = True if self.icon: self.icon = icons.get_icon(self.icon)
def __init__(self, **attrs): super(Button, self).__init__(**attrs) self.states = attrs.get('states') if self.states: self.states = self.states.split(',') self.btype = attrs.get('special', attrs.get('type', 'workflow')) self.icon = attrs.get('icon') if self.icon: self.icon = icons.get_icon(self.icon) self.context = attrs.get('context', {}) self.help = self.help or self.string self.confirm = attrs.get('confirm') or '' self.readonly = False self.width = attrs.get('width', 16)
def execute(self, params): action = params.name model = params.model state = params.state datas = params.datas form = None buttons = [] if model: action = model.replace('wizard.', '', 1) else: model = 'wizard.' + action params.name = action params.model = model params.view_mode = [] if 'form' not in datas: datas['form'] = {} wiz_id = params.wiz_id or rpc.session.execute('wizard', 'create', action) while state != 'end': ctx = rpc.session.context.copy() ctx.update(datas.get('context' or {}) or {}) res = rpc.session.execute('wizard', 'execute', wiz_id, datas, state, ctx) if 'datas' in res: datas['form'].update(res['datas']) else: res['datas'] = {} if res['type']=='form': fields = res['fields'] form_values = {} for f in fields: if 'value' in fields[f]: form_values[f] = fields[f]['value'] if f in datas['form'] and fields[f]['type'] == "one2many": datas['form'][f] = [(1, d, {}) for d in datas['form'][f]] form_values.update(datas['form']) datas['form'] = form_values res['datas'].update(datas['form']) params.is_wizard = True params.view_mode = ['form'] params.view_type = 'form' params.views = {'form': res} # keep track of datas and some other required information params.hidden_fields = [tw.form.Hidden(name='_terp_datas', default=ustr(datas)), tw.form.Hidden(name='_terp_state2', default=state), tw.form.Hidden(name='_terp_wiz_id', default=wiz_id)] form = tw.form_view.ViewForm(params, name="view_form", action="/wizard/action") buttons = [] for x in res.get('state', []): x = list(x) x[1] = re.sub('_(?!_)', '', x[1]) # remove mnemonic if len(x) >= 3: x[2] = icons.get_icon(x[2]) buttons.append(tuple(x)) params.state = state target = getattr(cherrypy.request, '_terp_view_target', None) return dict(form=form, buttons=buttons, show_header_footer=target!='new') elif res['type']=='action': from openerp.controllers import actions act_res = actions.execute(res['action'], **datas) if act_res: return act_res state = res['state'] elif res['type']=='print': from openerp.controllers import actions datas['report_id'] = res.get('report_id', False) if res.get('get_id_from_action', False): backup_ids = datas['ids'] datas['ids'] = datas['form']['ids'] return actions.execute_report(res['report'], **datas) elif res['type']=='state': state = res['state'] raise redirect('/wizard/end')
def data(self, ids, model, fields, field_parent=None, icon_name=None, domain=[], context={}, sort_by=None, sort_order="asc"): ids = ids or [] if isinstance(ids, basestring): ids = [int(id) for id in ids.split(',')] 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) fields_info = cache.fields_get(model, fields, ctx) result = proxy.read(ids, fields, ctx) if sort_by: result.sort(lambda a,b: self.sort_callback(a, b, sort_by, sort_order, type=fields_info[sort_by]['type'])) # formate the data for field in fields: if fields_info[field]['type'] in ('integer'): for x in result: if x[field]: x[field] = '%s'%(x[field]) if fields_info[field]['type'] in ('float'): for x in result: if x[field]: x[field] = '%.02f'%(round(x[field], 2)) if fields_info[field]['type'] in ('date',): for x in result: if x[field]: date = time.strptime(x[field], DT_FORMAT) x[field] = time.strftime('%x', date) if fields_info[field]['type'] in ('datetime',): for x in result: if x[field]: date = time.strptime(x[field], DHM_FORMAT) x[field] = time.strftime('%x %H:%M:%S', date) if fields_info[field]['type'] in ('one2one', 'many2one'): for x in result: if x[field]: x[field] = x[field][1] if fields_info[field]['type'] in ('selection'): for x in result: if x[field]: x[field] = dict(fields_info[field]['selection']).get(x[field], '') records = [] for item in result: # empty string instead of bool and None for k, v in item.items(): if v==None or (v==False and type(v)==bool): item[k] = '' record = {} record['id'] = item.pop('id') record['action'] = url('/tree/open', model=model, id=record['id']) record['target'] = None record['icon'] = None if icon_name and item.get(icon_name): icon = item.pop(icon_name) record['icon'] = icons.get_icon(icon) if icon == 'STOCK_OPEN': record['action'] = None record['target'] = None record['children'] = [] if field_parent and field_parent in item: record['children'] = item.pop(field_parent) or None record['items'] = item records += [record] return dict(records=records)
def execute(self, params): action = params.name model = params.model state = params.state datas = params.datas form = None buttons = [] if model: action = model.replace('wizard.', '', 1) else: model = 'wizard.' + action params.name = action params.model = model params.view_mode = [] if 'form' not in datas: datas['form'] = {} wiz_id = params.wiz_id or rpc.session.execute('wizard', 'create', action) while state != 'end': ctx = rpc.session.context.copy() ctx.update(datas.get('context' or {}) or {}) res = rpc.session.execute('wizard', 'execute', wiz_id, datas, state, ctx) if 'datas' in res: datas['form'].update(res['datas']) else: res['datas'] = {} if res['type'] == 'form': fields = res['fields'] form_values = {} for f in fields: if 'value' in fields[f]: form_values[f] = fields[f]['value'] if f in datas['form'] and fields[f]['type'] == "one2many": datas['form'][f] = [(1, d, {}) for d in datas['form'][f]] form_values.update(datas['form']) datas['form'] = form_values res['datas'].update(datas['form']) params.is_wizard = True params.view_mode = ['form'] params.view_type = 'form' params.views = {'form': res} # keep track of datas and some other required information params.hidden_fields = [ tw.form.Hidden(name='_terp_datas', default=ustr(datas)), tw.form.Hidden(name='_terp_state2', default=state), tw.form.Hidden(name='_terp_wiz_id', default=wiz_id) ] form = tw.form_view.ViewForm(params, name="view_form", action="/wizard/action") buttons = [] for x in res.get('state', []): x = list(x) x[1] = re.sub('_(?!_)', '', x[1]) # remove mnemonic if len(x) >= 3: x[2] = icons.get_icon(x[2]) buttons.append(tuple(x)) params.state = state target = getattr(cherrypy.request, '_terp_view_target', None) return dict(form=form, buttons=buttons, show_header_footer=target != 'new') elif res['type'] == 'action': from openerp.controllers import actions act_res = actions.execute(res['action'], **datas) if act_res: return act_res state = res['state'] elif res['type'] == 'print': from openerp.controllers import actions datas['report_id'] = res.get('report_id', False) if res.get('get_id_from_action', False): backup_ids = datas['ids'] datas['ids'] = datas['form']['ids'] return actions.execute_report(res['report'], **datas) elif res['type'] == 'state': state = res['state'] raise redirect('/wizard/end')
def data(self, ids, model, fields, field_parent=None, icon_name=None, domain=[], context={}, sort_by=None, sort_order="asc"): ids = ids or [] if isinstance(ids, basestring): ids = [int(id) for id in ids.split(',')] 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) fields_info = cache.fields_get(model, fields, ctx) result = proxy.read(ids, fields, ctx) if sort_by: result.sort(lambda a,b: self.sort_callback(a, b, sort_by, sort_order, type=fields_info[sort_by]['type'])) # formate the data for field in fields: if fields_info[field]['type'] in ('integer'): for x in result: if x[field]: x[field] = '%s'%(x[field]) if fields_info[field]['type'] in ('float'): for x in result: if x[field]: x[field] = '%.02f'%(round(x[field], 2)) if fields_info[field]['type'] in ('date',): for x in result: if x[field]: date = time.strptime(x[field], DT_FORMAT) x[field] = time.strftime('%x', date) if fields_info[field]['type'] in ('datetime',): for x in result: if x[field]: date = time.strptime(x[field], DHM_FORMAT) x[field] = time.strftime('%x %H:%M:%S', date) if fields_info[field]['type'] in ('one2one', 'many2one'): for x in result: if x[field]: x[field] = x[field][1] if fields_info[field]['type'] in ('selection'): for x in result: if x[field]: x[field] = dict(fields_info[field]['selection']).get(x[field], '') records = [] for item in result: # empty string instead of bool and None for k, v in item.items(): if v==None or (v==False and type(v)==bool): item[k] = '' record = {} record['id'] = item.pop('id') record['action'] = url('/tree/open', model=model, id=record['id'], context=ctx) record['target'] = None record['icon'] = None if icon_name and item.get(icon_name): icon = item.pop(icon_name) record['icon'] = icons.get_icon(icon) if icon == 'STOCK_OPEN': record['action'] = None record['target'] = None record['children'] = [] if field_parent and field_parent in item: record['children'] = item.pop(field_parent) or None record['items'] = item records += [record] return dict(records=records)