def clear_binary_data(self, **kw): params, data = TinyDict.split(kw) proxy = rpc.RPCProxy(params.model) ctx = tools.context_with_concurrency_info(params.context, params.concurrency_info) if params.fname: proxy.write([params.id], { params.field: False, params.fname: False }, ctx) else: proxy.write([params.id], {params.field: False}, ctx) args = { 'model': params.model, 'id': params.id, 'ids': ustr(params.ids), 'view_ids': ustr(params.view_ids), 'view_mode': ustr(params.view_mode), 'domain': ustr(params.domain), 'context': ustr(params.context), 'offset': params.offset, 'limit': params.limit, 'count': params.count, 'search_domain': ustr(params.search_domain) } raise redirect(self.path + '/edit', **args)
def save(self, **kw): params, data = TinyDict.split(kw) error = None error_field = None id = params.id or 0 id = (id > 0) and id or 0 ids = params.ids or [] model = params.parent.model if model != params.model and not params.parent.id: error = _("Parent record doesn't exists...") if error: return dict(error=error) try: proxy = rpc.RPCProxy(model) frm = TinyForm(**kw).to_python() data = {} ctx = tools.context_with_concurrency_info(params.parent.context, params.concurrency_info) source = params.source if source and source != '_terp_list': data = frm.chain_get(source) if '__id' in data: data.pop('__id') if 'id' in data: data.pop('id') fld = source.split('/')[-1] data = {fld: [(id and 1, id, data.copy())]} proxy.write([params.parent.id], data, ctx) all_ids = proxy.read([params.parent.id], [fld])[0][fld] new_ids = [i for i in all_ids if i not in ids] ids = all_ids if new_ids: id = new_ids[0] else: data = frm.copy() if 'id' in data: data.pop('id') if id > 0: proxy.write([id], data, ctx) else: id = proxy.create(data, params.parent.context or {}) ids = [id] + ids except TinyFormError, e: error_field = e.field error = ustr(e)
def save(self, **kw): params, data = TinyDict.split(kw) error = None error_field = None id = params.id or 0 id = (id > 0) and id or 0 ids = params.ids or [] model = params.parent.model if model != params.model and not params.parent.id: error = _("Parent record doesn't exists...") if error: return dict(error=error) try: proxy = rpc.RPCProxy(model) frm = TinyForm(**kw).to_python() data = {} ctx = tools.context_with_concurrency_info(params.parent.context, params.concurrency_info) source = params.source if source and source != '_terp_list': data = frm.chain_get(source) if '__id' in data: data.pop('__id') if 'id' in data: data.pop('id') fld = source.split('/')[-1] data = {fld : [(id and 1, id, data.copy())]} proxy.write([params.parent.id], data, ctx) all_ids = proxy.read([params.parent.id], [fld])[0][fld] new_ids = [i for i in all_ids if i not in ids] ids = all_ids if new_ids: id = new_ids[0] else: data = frm.copy() if 'id' in data: data.pop('id') if id > 0: proxy.write([id], data, ctx) else: id = proxy.create(data, params.parent.context or {}) ids = [id] + ids except TinyFormError, e: error_field = e.field error = ustr(e)
def remove(self, **kw): params, data = TinyDict.split(kw) error = None proxy = rpc.RPCProxy(params.model) if params.ids: try: ctx = tools.context_with_concurrency_info(params.context, params.concurrency_info) if isinstance(params.ids, list): res = proxy.unlink(params.ids, ctx) else: res = proxy.unlink([params.ids], ctx) except Exception, e: error = ustr(e)
def delete(self, **kw): params, data = TinyDict.split(kw) error = None ctx = rpc.session.context.copy() ctx.update(params.context or {}) ctx = tools.context_with_concurrency_info(ctx, params.concurrency_info) proxy = rpc.RPCProxy(params.model) try: proxy.unlink([params.id], ctx) except Exception, e: error = ustr(e)
def remove(self, **kw): params, data = TinyDict.split(kw) error = None proxy = rpc.RPCProxy(params.model) if params.ids: try: ctx = tools.context_with_concurrency_info(params.context, params.concurrency_info) if isinstance(params.ids, list): res = proxy.unlink(params.ids, ctx) else: res = proxy.unlink([params.ids], ctx) if params.model == 'res.request': ids, ids2 = rpc.RPCProxy(params.model).request_get() cherrypy.session['terp_requests'] = (ids, ids2) return dict(msg = _('%s request(s)') % len(ids)) except Exception, e: error = ustr(e)
def save(self, terp_save_only=False, **kw): params, data = TinyDict.split(kw) # remember the current page (tab) of notebooks cherrypy.session['remember_notebooks'] = True # bypass save, for button action in non-editable view if not (params.button and not params.editable and params.id): proxy = rpc.RPCProxy(params.model) if not params.id: id = proxy.create(data, params.context) params.ids = (params.ids or []) + [int(id)] params.id = int(id) params.count += 1 else: ctx = tools.context_with_concurrency_info( params.context, params.concurrency_info) id = proxy.write([params.id], data, ctx) current = params.chain_get(params.source or '') button = (params.button or False) and True params.load_counter = 1 if current and current.id and not button: params.load_counter = 2 # perform button action if params.button: res = self.button_action(params) if res: return res if current: current.id = None if not params.id: params.id = int(id) elif not button: params.editable = False if not current and not button: params.load_counter = 2 return self.create(params)
def save(self, **kw): params, data = TinyDict.split(kw) data = {} ds = tc.utils.parse_datetime(params.starts) de = tc.utils.parse_datetime(params.ends) data[params.fields['date_start']['name']] = format.parse_datetime( ds.timetuple()) if 'date_stop' in params.fields: data[params.fields['date_stop']['name']] = format.parse_datetime( de.timetuple()) elif 'date_delay' in params.fields: # convert the end time in hours day_length = params.fields['day_length'] tds = time.mktime(ds.timetuple()) tde = time.mktime(de.timetuple()) n = (tde - tds) / (60 * 60) if n > day_length: d = math.floor(n / 24) h = n % 24 n = d * day_length + h data[params.fields['date_delay']['name']] = n ctx = rpc.session.context.copy() ctx.update(params.context or {}) ctx = tools.context_with_concurrency_info(ctx, params.concurrency_info) error = None info = {} proxy = rpc.RPCProxy(params.model) try: res = proxy.write([params.id], data, ctx) info = proxy.read([params.id], ['__last_update'])[0]['__last_update'] info = {'%s,%s' % (params.model, params.id): info} except Exception, e: error = ustr(e)
def save(self, terp_save_only=False, **kw): params, data = TinyDict.split(kw) params.editable = True proxy = rpc.RPCProxy(params.parent_model) pprefix = '.'.join(params.o2m.split('/')[:-1]) if pprefix: data = eval(pprefix, TinyDict(**data)).make_dict() ctx = tools.context_with_concurrency_info(rpc.session.context, params.concurrency_info) ctx.update(params.parent_context or {}) ctx.update(params.o2m_context or {}) id = proxy.write([params.parent_id], data, ctx) prefix = params.o2m current = params.chain_get(prefix) params.load_counter = 1 if current and current.id and not params.button: params.load_counter = 2 ids = current.ids fld = params.o2m.split('/')[-1] all_ids = proxy.read([params.parent_id], [fld])[0][fld] new_ids = [i for i in all_ids if i not in ids] current.ids = all_ids if new_ids and params.source: current.id = new_ids[-1] params.o2m_id = current.id # perform button action if params.button: current.button = params.button current.parent_params = params cherrypy.request._terp_view_target = 'new' res = self.button_action(current) if res: return res return self.create(params)
def save(self, terp_save_only=False, **kw): params, data = TinyDict.split(kw) # remember the current page (tab) of notebooks cherrypy.session['remember_notebooks'] = True # bypass save, for button action in non-editable view if not (params.button and not params.editable and params.id): proxy = rpc.RPCProxy(params.model) if not params.id: id = proxy.create(data, params.context) params.ids = (params.ids or []) + [int(id)] params.id = int(id) params.count += 1 else: ctx = tools.context_with_concurrency_info(params.context, params.concurrency_info) id = proxy.write([params.id], data, ctx) current = params.chain_get(params.source or '') button = (params.button or False) and True params.load_counter = 1 if current and current.id and not button: params.load_counter = 2 # perform button action if params.button: res = self.button_action(params) if res: return res if current: current.id = None if not params.id: params.id = int(id) elif not button: params.editable = False if not current and not button: params.load_counter = 2 return self.create(params)
def remove(self, **kw): params, data = TinyDict.split(kw) error = None proxy = rpc.RPCProxy(params.model) if params.ids: try: ctx = tools.context_with_concurrency_info( params.context, params.concurrency_info) if isinstance(params.ids, list): res = proxy.unlink(params.ids, ctx) else: res = proxy.unlink([params.ids], ctx) if params.model == 'res.request': ids, ids2 = rpc.RPCProxy(params.model).request_get() cherrypy.session['terp_requests'] = (ids, ids2) return dict(msg=_('%s request(s)') % len(ids)) except Exception, e: error = ustr(e)
def save(self, **kw): params, data = TinyDict.split(kw) data = {} ds = tc.utils.parse_datetime(params.starts) de = tc.utils.parse_datetime(params.ends) data[params.fields['date_start']['name']] = format.parse_datetime(ds.timetuple()) if 'date_stop' in params.fields: data[params.fields['date_stop']['name']] = format.parse_datetime(de.timetuple()) elif 'date_delay' in params.fields: # convert the end time in hours day_length = params.fields['day_length'] tds = time.mktime(ds.timetuple()) tde = time.mktime(de.timetuple()) n = (tde - tds) / (60 * 60) if n > day_length: d = math.floor(n / 24) h = n % 24 n = d * day_length + h data[params.fields['date_delay']['name']] = n ctx = rpc.session.context.copy() ctx.update(params.context or {}) ctx = tools.context_with_concurrency_info(ctx, params.concurrency_info) error = None info = {} proxy = rpc.RPCProxy(params.model) try: res = proxy.write([params.id], data, ctx) info = proxy.read([params.id], ['__last_update'])[0]['__last_update'] info = {'%s,%s'%(params.model, params.id): info} except Exception, e: error = ustr(e)
def delete(self, **kw): params, data = TinyDict.split(kw) current = params.chain_get(params.source or '') or params proxy = rpc.RPCProxy(current.model) idx = -1 if current.id: ctx = tools.context_with_concurrency_info(current.context, params.concurrency_info) res = proxy.unlink([current.id], ctx) idx = current.ids.index(current.id) current.ids.remove(current.id) params.count = 0 # invalidate count if idx == len(current.ids): idx = -1 current.id = (current.ids or None) and current.ids[idx] self.reset_notebooks() args = { 'model': params.model, 'id': params.id, 'ids': ustr(params.ids), 'view_ids': ustr(params.view_ids), 'view_mode': ustr(params.view_mode), 'domain': ustr(params.domain), 'context': ustr(params.context), 'offset': params.offset, 'limit': params.limit, 'count': params.count, 'search_domain': ustr(params.search_domain) } if not params.id: raise redirect(self.path + '/edit', **args) raise redirect(self.path + '/view', **args)
def delete(self, **kw): params, data = TinyDict.split(kw) current = params.chain_get(params.source or '') or params proxy = rpc.RPCProxy(current.model) idx = -1 if current.id: ctx = tools.context_with_concurrency_info(current.context, params.concurrency_info) res = proxy.unlink([current.id], ctx) idx = current.ids.index(current.id) current.ids.remove(current.id) params.count = 0 # invalidate count if idx == len(current.ids): idx = -1 current.id = (current.ids or None) and current.ids[idx] self.reset_notebooks() args = {'model': params.model, 'id': params.id, 'ids': ustr(params.ids), 'view_ids': ustr(params.view_ids), 'view_mode': ustr(params.view_mode), 'domain': ustr(params.domain), 'context': ustr(params.context), 'offset': params.offset, 'limit': params.limit, 'count': params.count, 'search_domain': ustr(params.search_domain)} if not params.id: raise redirect(self.path + '/edit', **args) raise redirect(self.path + '/view', **args)
def clear_binary_data(self, **kw): params, data = TinyDict.split(kw) proxy = rpc.RPCProxy(params.model) ctx = tools.context_with_concurrency_info(params.context, params.concurrency_info) if params.fname: proxy.write([params.id], {params.field: False, params.fname: False}, ctx) else: proxy.write([params.id], {params.field: False}, ctx) args = {'model': params.model, 'id': params.id, 'ids': ustr(params.ids), 'view_ids': ustr(params.view_ids), 'view_mode': ustr(params.view_mode), 'domain': ustr(params.domain), 'context': ustr(params.context), 'offset': params.offset, 'limit': params.limit, 'count': params.count, 'search_domain': ustr(params.search_domain)} raise redirect(self.path + '/edit', **args)
def save(self, terp_save_only=False, **kw): """Controller method to save/button actions... @param tg_errors: TG special arg, used durring validation @param kw: keyword arguments @return: form view """ params, data = TinyDict.split(kw) # remember the current page (tab) of notebooks cherrypy.session['remember_notebooks'] = True # bypass save, for button action in non-editable view if not (params.button and not params.editable and params.id): proxy = rpc.RPCProxy(params.model) if not params.id: ctx = params.context or {} ctx.update(rpc.session.context.copy()) id = proxy.create(data, ctx) params.ids = (params.ids or []) + [int(id)] params.id = int(id) params.count += 1 else: ctx = tools.context_with_concurrency_info( params.context, params.concurrency_info) id = proxy.write([params.id], data, ctx) button = params.button # perform button action if params.button: res = self.button_action(params) if res: return res current = params.chain_get(params.source or '') if current: current.id = None if not params.id: params.id = int(id) elif not button: params.editable = False if terp_save_only: return dict(params=params, data=data) def get_params(p, f): pp = p.chain_get(f) px = rpc.RPCProxy(p.model) _ids = pp.ids _all = px.read([p.id], [f])[0][f] _new = [i for i in _all if i not in _ids] pp.ids = _all if _new: pp.id = _new[0] return pp if params.source and len(params.source.split("/")) > 1: path = params.source.split("/") p = params for f in path: p = get_params(p, f) return self.create(params) args = { 'model': params.model, 'id': params.id, 'ids': ustr(params.ids), 'view_ids': ustr(params.view_ids), 'view_mode': ustr(params.view_mode), 'domain': ustr(params.domain), 'context': ustr(params.context), 'offset': params.offset, 'limit': params.limit, 'count': params.count, 'search_domain': ustr(params.search_domain) } if not int(cherrypy.request.params.get('_terp_header_footer', 1)): args['target'] = 'new' if params.editable or params.source or params.return_edit: raise redirect(self.path + '/edit', source=params.source, **args) raise redirect(self.path + '/view', **args)
def save(self, terp_save_only=False, **kw): """Controller method to save/button actions... @param tg_errors: TG special arg, used durring validation @param kw: keyword arguments @return: form view """ params, data = TinyDict.split(kw) # remember the current page (tab) of notebooks cherrypy.session['remember_notebooks'] = True # bypass save, for button action in non-editable view if not (params.button and not params.editable and params.id): proxy = rpc.RPCProxy(params.model) if not params.id: ctx = params.context or {} ctx.update(rpc.session.context.copy()) id = proxy.create(data, ctx) params.ids = (params.ids or []) + [int(id)] params.id = int(id) params.count += 1 else: ctx = tools.context_with_concurrency_info(params.context, params.concurrency_info) id = proxy.write([params.id], data, ctx) button = params.button # perform button action if params.button: res = self.button_action(params) if res: return res current = params.chain_get(params.source or '') if current: current.id = None if not params.id: params.id = int(id) elif not button: params.editable = True if terp_save_only: return dict(params=params, data=data) def get_params(p, f): pp = p.chain_get(f) px = rpc.RPCProxy(p.model) _ids = pp.ids _all = px.read([p.id], [f])[0][f] _new = [i for i in _all if i not in _ids] pp.ids = _all if _new: pp.id = _new[0] return pp if params.source and len(params.source.split("/")) > 1: path = params.source.split("/") p = params for f in path: p = get_params(p, f) return self.create(params) args = {'model': params.model, 'id': params.id, 'ids': ustr(params.ids), 'view_ids': ustr(params.view_ids), 'view_mode': ustr(params.view_mode), 'domain': ustr(params.domain), 'context': ustr(params.context), 'offset': params.offset, 'limit': params.limit, 'count': params.count, 'search_domain': ustr(params.search_domain)} if not int(cherrypy.request.params.get('_terp_header_footer', 1)): args['target'] = 'new' if params.editable or params.source or params.return_edit: raise redirect(self.path + '/edit', source=params.source, **args) raise redirect(self.path + '/view', **args)