def set(self, instance, value, **kw): """Set the value of the (proxy) field """ proxy_field = self.get_proxy_field(instance) if proxy_field is None: return None # set the field with the proper field manager of the proxy field fieldmanager = IFieldManager(proxy_field) return fieldmanager.set(instance, value, **kw)
def json_data(self, name): """Get a JSON compatible structure for the named attribute """ # fetch the field by name field = api.get_field(self.context, name) # bail out if we have no field if not field: return None fieldmanager = IFieldManager(field) return fieldmanager.json_data(self.context)
def get(self, name): """Get the value of the field by name """ # fetch the field by name field = api.get_field(self.context, name) # bail out if we have no field if not field: return None # call the field adapter and set the value fieldmanager = IFieldManager(field) return fieldmanager.get(self.context)
def set(self, name, value, **kw): """Set the field to the given value. The keyword arguments represent the other field values to integrate constraints to other values. """ # fetch the field by name field = api.get_field(self.context, name) # bail out if we have no field if not field: return False # call the field adapter and set the value fieldmanager = IFieldManager(field) return fieldmanager.set(self.context, value, **kw)
def get_file_info(obj, fieldname, default=None): """Extract file data from a file field :param obj: Content object :type obj: ATContentType/DexterityContentType :param fieldname: Schema name of the field :type fieldname: str/unicode :returns: File data mapping :rtype: dict """ # extract the file field from the object if omitted field = get_field(obj, fieldname) # get the value with the fieldmanager fm = IFieldManager(field) # return None if we have no file data if fm.get_size(obj) == 0: return None out = { "content_type": fm.get_content_type(obj), "filename": fm.get_filename(obj), "download": fm.get_download_url(obj), } # only return file data only if requested (?filedata=yes) if req.get_filedata(False): data = fm.get_data(obj) out["data"] = data.encode("base64") return out
def json_data(self, name): """Get a JSON compatible structure for the named attribute """ # Check the write permission of the context # XXX: This should be done on field level by the field manager adapter if not self.can_write(): raise Unauthorized("You are not allowed to modify this content") # fetch the field by name field = api.get_field(self.context, name) # bail out if we have no field if not field: return None fieldmanager = IFieldManager(field) return fieldmanager.json_data(self.context)
def get(self, name): """Get the value of the field by name """ # Check the read permission of the context # XXX: This should be done on field level by the field manager adapter if not self.can_write(): raise Unauthorized("You are not allowed to modify this content") # fetch the field by name field = api.get_field(self.context, name) # bail out if we have no field if field is None: return None # call the field adapter and set the value fieldmanager = IFieldManager(field) return fieldmanager.get(self.context)
def set(self, name, value, **kw): """Set the field to the given value. The keyword arguments represent the other field values to integrate constraints to other values. """ # Check the write permission of the context # XXX: This should be done on field level by the field manager adapter if not self.can_write(): raise Unauthorized("You are not allowed to modify this content") # fetch the field by name field = api.get_field(self.context, name) # bail out if we have no field if not field: return False # call the field adapter and set the value fieldmanager = IFieldManager(field) return fieldmanager.set(self.context, value, **kw)