def serialize(self, data): """Returns a dictionary with serialized data from the forms item. The dictionary will include all attributes and relations values of the items. The key in the dictionary is the name of the relation/attribute. In case of relations the value in the dictionary is the "id" value of the related item. If no item is present then return a empty dict. :returns: Dictionary with serialized values of the item. """ serialized = {} for fieldname, value in self._filter_values(data).iteritems(): field = self.fields.get(fieldname) serialized[fieldname] = from_python(field, value) log.debug("Serialized values: %s" % serialized) return serialized
def _get_value(self, value, default, expand): if expand: if not isinstance(value, list): value = [value] ex_values = [] options = self.get_options() for opt in options: for v in value: if hasattr(v, "id"): v = v.id if unicode(v) == unicode(opt[1]): ex_values.append("%s" % opt[0]) return ", ".join(ex_values) else: if value: return from_python(self, value) elif default: return default else: return value
def _get_value(self, value, default, expand): if expand: if not isinstance(value, list): value = [value] ex_values = [] options = self.get_options() for opt in options: for v in value: if hasattr(v, "id"): v = v.id else: v = unicode(v) if unicode(v) == unicode(opt[1]): ex_values.append("%s" % opt[0]) return ", ".join(ex_values) else: if value: return from_python(self, value) elif default: return default else: return value