def deserialize(self, value): if not value: return null try: return self.vocabulary.getTermByToken(value).value except Exception: raise Invalid( self, _('"${val}" is not in vocabulary', mapping={'val':value}))
def deserialize(self, value): if value != 0 and not value: return null try: return self.num(value) except Exception: raise Invalid( self, _('"${val}" is not a number', mapping={'val':value}))
def serialize(self, value): if value is null: return null try: return self.vocabulary.getTerm(value).token except Exception: raise Invalid( self, _('"${val}" is not in vocabulary', mapping={'val':value}))
def deserialize(self, value): if not value: return null try: return [s.strip() for s in value.split()] except Exception: raise Invalid(self, _('"${val}" is not a list', mapping={'val': value}), )
def serialize(self, value): if value is null or not value: return null try: return u'\n'.join(value) except Exception: raise Invalid(self, _('"${val}" is not a list', mapping={'val': value}), )
def serialize(self, value): if value is null: return null try: return str(self.num(value)) except Exception: raise Invalid(self, _('"${val}" is not a number', mapping={'val': value}), )
def serialize(self, value): if value is null: return null try: res = [] for val in value: res.append(self.vocabulary.getTerm(val).token) return res except (LookupError, TypeError): raise Invalid( self, _('"${val}" is not in vocabulary', mapping={'val':value}))
def deserialize(self, value): if not value: return null try: result = iso8601.parse_date(value) result = result.date() except (iso8601.ParseError, TypeError): try: year, month, day = map(int, value.split('-', 2)) result = datetime.date(year, month, day) except Exception, e: raise Invalid( self, _('Invalid date', mapping={'val': value, 'err': e}))
def serialize(self, value): if value is null: return null if isinstance(value, datetime.datetime): value = value.date() if not isinstance(value, datetime.date): raise Invalid(self, _('"${val}" is not a date object', mapping={'val': value})) return value.isoformat()
def serialize(self, value): if value is null or value is None: return null if type(value) is datetime.date: # cant use isinstance; dt subs date value = datetime.datetime.combine(value, datetime.time()) if not isinstance(value, datetime.datetime): raise Invalid( self, _('"${val}" is not a datetime object', mapping={'val':value})) if value.tzinfo is None: value = value.replace(tzinfo=self.default_tzinfo) return value.isoformat()