def evaluate(action, atype, record): ''' Evaluate the action with the record. ''' action = action.copy() if atype in ('print', 'action'): email = {} if 'pyson_email' in action: email = record.expr_eval(action['pyson_email']) if not email: email = {} if 'subject' not in email: email['subject'] = action['name'].replace('_', '') action['email'] = email elif atype == 'relate': encoder = PYSONEncoder() if 'pyson_domain' in action: action['pyson_domain'] = encoder.encode( record.expr_eval(action['pyson_domain'], check_load=False)) if 'pyson_context' in action: action['pyson_context'] = encoder.encode( record.expr_eval(action['pyson_context'], check_load=False)) else: raise NotImplementedError("Action type '%s' is not supported" % atype) return action
def evaluate(action, atype, record): ''' Evaluate the action with the record. ''' action = action.copy() if atype in ('print', 'action'): email = {} if 'pyson_email' in action: email = record.expr_eval(action['pyson_email']) if not email: email = {} if 'subject' not in email: email['subject'] = action['name'].replace('_', '') action['email'] = email elif atype == 'relate': encoder = PYSONEncoder() if 'pyson_domain' in action: action['pyson_domain'] = encoder.encode( record.expr_eval(action['pyson_domain'])) if 'pyson_context' in action: action['pyson_context'] = encoder.encode( record.expr_eval(action['pyson_context'])) else: raise NotImplementedError("Action type '%s' is not supported" % atype) return action
class PYSON(Char): def __init__(self, view, attrs): super(PYSON, self).__init__(view, attrs) self.encoder = PYSONEncoder() self.decoder = PYSONDecoder(noeval=True) self.entry.connect('key-release-event', self.validate_pyson) def get_encoded_value(self): value = self.get_value() if not value: return value try: return self.encoder.encode(eval(value, CONTEXT)) except (ValueError, TypeError, NameError, SyntaxError): return None def set_value(self, record, field): field.set_client(record, self.get_encoded_value()) def get_client_value(self, record, field): value = super(PYSON, self).get_client_value(record, field) if value: value = repr(self.decoder.decode(value)) return value def validate_pyson(self, *args): icon = gtk.STOCK_OK if self.get_encoded_value() is None: icon = gtk.STOCK_CANCEL self.entry.set_icon_from_stock(gtk.ENTRY_ICON_SECONDARY, icon) def _focus_out(self): self.validate_pyson() super(PYSON, self)._focus_out()
class PYSON(Char): def __init__(self, view, attrs): super(PYSON, self).__init__(view, attrs) self.encoder = PYSONEncoder() self.decoder = PYSONDecoder(noeval=True) self.entry.connect('key-release-event', self.validate_pyson) def get_encoded_value(self): value = self.get_value() if not value: return value try: return self.encoder.encode(eval(value, CONTEXT)) except Exception: return None def set_value(self): # avoid modification because different encoding value = self.get_encoded_value() previous = self.field.get_client(self.record) if (previous and value == self.encoder.encode( self.decoder.decode(previous))): value = previous self.field.set_client(self.record, value) def get_client_value(self): value = super(PYSON, self).get_client_value() if value: value = repr(self.decoder.decode(value)) return value def validate_pyson(self, *args): icon = 'tryton-ok' if self.get_encoded_value() is None: icon = 'tryton-error' pixbuf = IconFactory.get_pixbuf(icon, Gtk.IconSize.MENU) self.entry.set_icon_from_pixbuf( Gtk.EntryIconPosition.SECONDARY, pixbuf) def _focus_out(self): self.validate_pyson() super(PYSON, self)._focus_out()
def add(self, model, name, domain): try: id_, = RPCExecute('model', 'ir.ui.view_search', 'create', [{ 'model': model, 'name': name, 'domain': PYSONEncoder().encode(domain), }]) except RPCException: return self.searches.setdefault(model, []).append((id_, name, domain))
def click_and_relate(self, action, value, path): data = {} context = {} act = action.copy() if not(value): message(_('You must select a record to use the relation!')) return False from tryton.gui.window.view_form.screen import Screen screen = Screen(self.screen.group.fields[ path[1].name].attrs['relation']) screen.load([value]) encoder = PYSONEncoder() act['domain'] = encoder.encode(screen.current_record.expr_eval( act.get('domain', []), check_load=False)) act['context'] = encoder.encode(screen.current_record.expr_eval( act.get('context', {}), check_load=False)) data['model'] = self.screen.model_name data['id'] = value data['ids'] = [value] return Action._exec_action(act, data, context)
class PYSON(Char): def __init__(self, view, attrs): super(PYSON, self).__init__(view, attrs) self.encoder = PYSONEncoder() self.decoder = PYSONDecoder(noeval=True) self.entry.connect('key-release-event', self.validate_pyson) def get_encoded_value(self): value = self.get_value() if not value: return value try: return self.encoder.encode(eval(value, CONTEXT)) except Exception: return None def set_value(self, record, field): # avoid modification because different encoding value = self.get_encoded_value() previous = field.get_client(record) if (previous and value == self.encoder.encode( self.decoder.decode(previous))): value = previous field.set_client(record, value) def get_client_value(self, record, field): value = super(PYSON, self).get_client_value(record, field) if value: value = repr(self.decoder.decode(value)) return value def validate_pyson(self, *args): icon = gtk.STOCK_OK if self.get_encoded_value() is None: icon = gtk.STOCK_CANCEL self.entry.set_icon_from_stock(gtk.ENTRY_ICON_SECONDARY, icon) def _focus_out(self): self.validate_pyson() super(PYSON, self)._focus_out()
def __init__(self, view, attrs): super(PYSON, self).__init__(view, attrs) self.encoder = PYSONEncoder() self.decoder = PYSONDecoder(noeval=True) self.entry.connect('key-release-event', self.validate_pyson)