def _migrateSetValue(self, name, value, old_schema=None, **kw): """Try to set an object value using a variety of methods.""" schema = self.Schema() # Migrate pre-AT 1.3 schemas. schema = fixSchema(schema) field = schema.get(name, None) # Try using the field's mutator if field: mutator = field.getMutator(self) if mutator is not None: try: args = [value,] mapply(mutator, *args, **kw) return except (ConflictError, KeyboardInterrupt): raise except: log_exc() else: # Try setting an existing attribute if shasattr(self, name): setattr(self, name, value) return raise ValueError, 'name = %s, value = %s' % (name, value)
def _migrateSetValue(self, name, value, old_schema=None, **kw): """Try to set an object value using a variety of methods.""" schema = self.Schema() # Migrate pre-AT 1.3 schemas. schema = fixSchema(schema) field = schema.get(name, None) # Try using the field's mutator if field: mutator = field.getMutator(self) if mutator is not None: try: args = [value] mapply(mutator, *args, **kw) return except (ConflictError, KeyboardInterrupt): raise except: log_exc() else: # Try setting an existing attribute if shasattr(self, name): setattr(self, name, value) return raise ValueError, 'name = %s, value = %s' % (name, value)
def _migrateGetValue(self, name, new_schema=None): """Try to get a value from an object using a variety of methods.""" schema = self.Schema() # Migrate pre-AT 1.3 schemas. schema = fixSchema(schema) # First see if the new field name is managed by the current schema field = schema.get(getattr(new_schema.get(name,None),'old_field_name',name), None) if field: # At very first try to use the BaseUnit itself try: if IFileField.providedBy(field): return field.getBaseUnit(self) except (ConflictError, KeyboardInterrupt): raise except: pass # First try the edit accessor try: editAccessor = field.getEditAccessor(self) if editAccessor: return editAccessor() except (ConflictError, KeyboardInterrupt): raise except: pass # No luck -- now try the accessor try: accessor = field.getAccessor(self) if accessor: return accessor() except (ConflictError, KeyboardInterrupt): raise except: pass # No luck use standard method to get the value return field.get(self) # Still no luck -- try to get the value directly # this part should be remove because for some fields this will fail # if you get the value directly for example for FixPointField # stored value is (0,0) but the input value is a string. # at this time FixPointField fails if he got a tuple as input value # Because of this line value = value.replace(',','.') try: return self[field.getName()] except (ConflictError, KeyboardInterrupt): raise except: pass # Nope -- see if the new accessor method is present # in the current object. if new_schema: new_field = new_schema.get(name) # Try the new edit accessor try: editAccessor = new_field.getEditAccessor(self) if editAccessor: return editAccessor() except (ConflictError, KeyboardInterrupt): raise except: pass # Nope -- now try the accessor try: accessor = new_field.getAccessor(self) if accessor: return accessor() except (ConflictError, KeyboardInterrupt): raise except: pass # Still no luck -- try to get the value directly using the new name try: return self[new_field.getName()] except (ConflictError, KeyboardInterrupt): raise except: pass # Nope -- now see if the current object has an attribute # with the same name # as the new field if shasattr(self, name): return getattr(self, name) raise ValueError, 'name = %s' % (name)
def _migrateGetValue(self, name, new_schema=None): """Try to get a value from an object using a variety of methods.""" schema = self.Schema() # Migrate pre-AT 1.3 schemas. schema = fixSchema(schema) # First see if the new field name is managed by the current schema field = schema.get(getattr(new_schema.get( name, None), 'old_field_name', name), None) if field: # At very first try to use the BaseUnit itself try: if IFileField.providedBy(field): return field.getBaseUnit(self) except (ConflictError, KeyboardInterrupt): raise except: pass # First try the edit accessor try: editAccessor = field.getEditAccessor(self) if editAccessor: return editAccessor() except (ConflictError, KeyboardInterrupt): raise except: pass # No luck -- now try the accessor try: accessor = field.getAccessor(self) if accessor: return accessor() except (ConflictError, KeyboardInterrupt): raise except: pass # No luck use standard method to get the value return field.get(self) # Still no luck -- try to get the value directly # this part should be remove because for some fields this will fail # if you get the value directly for example for FixPointField # stored value is (0,0) but the input value is a string. # at this time FixPointField fails if he got a tuple as input value # Because of this line value = value.replace(',','.') try: return self[field.getName()] except (ConflictError, KeyboardInterrupt): raise except: pass # Nope -- see if the new accessor method is present # in the current object. if new_schema: new_field = new_schema.get(name) # Try the new edit accessor try: editAccessor = new_field.getEditAccessor(self) if editAccessor: return editAccessor() except (ConflictError, KeyboardInterrupt): raise except: pass # Nope -- now try the accessor try: accessor = new_field.getAccessor(self) if accessor: return accessor() except (ConflictError, KeyboardInterrupt): raise except: pass # Still no luck -- try to get the value directly using the new name try: return self[new_field.getName()] except (ConflictError, KeyboardInterrupt): raise except: pass # Nope -- now see if the current object has an attribute # with the same name # as the new field if shasattr(self, name): return getattr(self, name) raise ValueError, 'name = %s' % (name)