def output(self, key, obj): date = fields.get_value(self.date, obj) if self.date else None time = fields.get_value(self.time, obj) if time == __date_time_null_value__: return "" if not date: return self.format_time(time) date_time = date + time return self.format(date_time)
def output(self, key, obj): value = _fields.get_value(key if self.attribute is None else self.attribute, obj) # For all fields, when its value was null (None), return null directly, # instead of return its default value (eg. int type's default value was 0) # Because sometimes the client **needs** to know, was a field of the model empty, to decide its behavior. return None if value is None else self.format(value)
def output(self, key, obj): value = _fields.get_value( key if self.attribute is None else self.attribute, obj) # For all fields, when its value was null (None), return null directly, # instead of return its default value (eg. int type's default value was 0) # Because sometimes the client **needs** to know, was a field of the model empty, to decide its behavior. return None if value is None else self.format(value)
def output(self, key, obj): value = get_value(key if self.attribute is None else self.attribute, obj) if value is None: if self.allow_null: return None elif self.allow_empty: return {} return marshal(value, self.nested)
def output(self, key, obj): if not obj or not obj.HasField(key): value = None else: value = fields.get_value( key if self.attribute is None else self.attribute, obj) if self.allow_null and value is None: return None return fields.marshal(value, self.nested, self.display_null)
def output(self, key, obj): attribute = self.attribute or key if not obj.HasField(attribute): return self.default value = fields.get_value(attribute, obj) if value is None: return self.default return self.format(value)
def output(self, key, obj): value = fields.get_value(key if not self.attribute else self.attribute, obj) if value is not None: try: value = json.loads(value) except TypeError: value = value else: value = self.default return value
def output(self, key, data): value = get_value(key if self.attribute is None else self.attribute, data) if value is None: return self.default.copy() if hasattr(self.default, 'copy') else self.default # we cannot really test for external dict behavior if is_indexable_but_not_string(value) and not isinstance(value, dict): return self.format(value) return [marshal(value, self.container.nested)]
def output(self, key, obj): if hasattr(g, 'disable_geojson') and g.disable_geojson: return None val = fields.get_value( key if self.attribute is None else self.attribute, obj) lines = [] for l in val.lines: lines.append([[c.lon, c.lat] for c in l.coordinates]) response = {"type": "MultiLineString", "coordinates": lines} return response
def output(self, key, obj): envelope_field = {} value = fields.get_value(key if self.attribute else key, obj) if value is not None: for key, items in self.nested.items(): field_obj = fields.marshal(value, items, key) for item_key, field in items.items(): if isinstance(field, fields.List): if hasattr(value, item_key): list_value = getattr(value, item_key) field_obj = {key: field.format(list_value)} else: field_obj = {key: self.default} envelope_field.update(field_obj) return envelope_field else: return self.default
def test_get_value_obj(self): self.assertEquals(3, fields.get_value("hey", Foo()))
def test_get_value_no_value(self): self.assertEquals(None, fields.get_value("foo", {"hey": 3}))
def test_get_value(self): self.assertEquals(3, fields.get_value("hey", {"hey": 3}))
def output(self, key, obj): return self.format(get_value(self.attribute, self.default))
def translate(self, escape_tab): return super().format(get_value(self.attribute, self.default))
def output(self, key, obj): return [ {"rel": "self", "href": api.url_for(UserV3, username=fields.get_value("username", obj))}]
def output(self, key, obj): k = key if self.attribute is None else self.attribute if not obj or not obj.HasField(k): return None else: return fields.get_value(k, obj)