def setFilename(self, value, key=None): """Sets the filename of a field. """ if key is None: field = self.getPrimaryField() else: field = self.getField(key) or getattr(self, key, None) if field and IFileField.isImplementedBy(field): field.setFilename(self, value)
def isBinary(self, key): """Return wether a field contains binary data. """ field = self.getField(key) if IFileField.isImplementedBy(field): value = field.getBaseUnit(self) return value.isBinary() mimetype = self.getContentType(key) if mimetype and shasattr(mimetype, 'binary'): return mimetype.binary elif mimetype and mimetype.find('text') >= 0: return 0 return 1
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.isImplementedBy(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)