def to_portable_primitive(self, val): if self.subfield: ret = list() if val is None: return ret for item in val: ret.append(self.subfield.to_portable_primitive(item)) #run data through the primitive processor return PRIMITIVE_PROCESSOR.to_primitive(ret) return PRIMITIVE_PROCESSOR.to_primitive(val)
def to_python(self, val, parent=None): if self.subfield: ret = DotPathSet() if val is None: return ret #TODO pass in parent for item in val: if not self.subfield.is_instance(item): try: item = self.subfield.to_python(item) except ObjectDoesNotExist: continue ret.add(item) #run data through the primitive processor return PRIMITIVE_PROCESSOR.to_python(ret) return PRIMITIVE_PROCESSOR.to_python(val)
def __getitem__(self, key): assert isinstance(key, basestring) if key in self._meta.fields: return getattr(self, key) if key in self._primitive_data and key not in self._python_data: from dockit.schema.serializer import PRIMITIVE_PROCESSOR r_val = self._primitive_data[key] p_val = PRIMITIVE_PROCESSOR.to_python(r_val) self._python_data[key] = p_val return self._python_data[key]
def to_portable_primitive(self, val): ret = dict() if val is None: return ret for key, value in val.iteritems(): if hasattr(value, 'to_portable_primitive'): value = type(value).to_portable_primitive(value) if hasattr(key, 'to_portable_primitive'): key = type(key).to_portable_primitive(key) ret[key] = value #TODO run data through the primitive processor ret = PRIMITIVE_PROCESSOR.to_primitive(ret) return ret
def to_python(self, val, parent=None): ret = DotPathDict() if val is None: return ret for key, value in val.iteritems(): if self.value_subfield: if not self.value_subfield.is_instance(value): value = self.value_subfield.to_python(value) if self.key_subfield: if not self.key_subfield.is_instance(key): key = self.key_subfield.to_python(key) ret[key] = value #TODO run data through the primitive processor ret = PRIMITIVE_PROCESSOR.to_python(ret) return ret