コード例 #1
0
 def format(self, value):
     """Format the value"""
     try:
         new_value = self.parse(value)
         if not new_value:
             return value
         if self.dt_format == 'iso8601':
             return new_value.isoformat()
         else:
             return fields.DateTime.format(self, value)
     except (AttributeError, ValueError) as e:
         raise fields.MarshallingError(e)
     except arrow.parser.ParserError:
         return _(str(value))
コード例 #2
0
 def format(self, value):
     dvalue = Decimal(value)
     if not dvalue.is_normal() and dvalue != Decimal():
         raise fields.MarshallingError("Invalid Fixed precision number.")
     return dvalue.quantize(self.precision, rounding=ROUND_HALF_EVEN)
コード例 #3
0
 def format(self, value):
     """Format the value"""
     try:
         return fields.String.format(self, '{0:07d}'.format(int(value)))
     except ValueError as e:
         raise fields.MarshallingError(e)