예제 #1
0
 def toFieldValue(self, value):
     """See interfaces.IDataConverter"""
     if value == u'':
         return self.field.missing_value
     try:
         return Decimal(value)
     except InvalidOperation:
         raise FormatterValidationError(self.errorMessage, value)
 def toFieldValue(self, value):
     """See interfaces.IDataConverter""" 
     if value == u'':
         return self.field.missing_value
     try:
         return self.formatter.parse(value, pattern="M/d/yyyy")
     except DateTimeParseError, err:
         raise FormatterValidationError(err.args[0], value)
예제 #3
0
 def toFieldValue(self, value):
     """See interfaces.IDataConverter"""
     if value == u'':
         return self.field.missing_value
     try:
         value = parse_date(value)
     except (ValueError,):
         raise FormatterValidationError(
             _("The datetime string did not match the pattern yyyy-mm-dd"),
             value)
     try:
         value.strftime("%Y-%m-%d")
     except (ValueError,):
         raise FormatterValidationError(
             _('Year has to be equal or greater than 1900'),
             value)
     return value
예제 #4
0
 def toFieldValue(self, value):
     """See interfaces.IDataConverter"""
     if value == u'':
         return self.field.missing_value
     lines = filter(None, [s.strip() for s in unicode(value).splitlines()])
     if not lines:
         return self.field.missing_value
     field_value = []
     for line in lines:
         if line in field_value:
             raise FormatterValidationError(
                 format_message(_('Duplicate entry "${value}"'),
                                mapping={'value': line}), line)
         if len(line) >= 64:
             raise FormatterValidationError(
                 format_message(_('Value too long "${value}"'),
                                mapping={'value': line}), line)
         field_value.append(line)
     return field_value
예제 #5
0
 def toFieldValue(self, value):
     if value is None:
         return None
     v = value.strip().replace(self.mark(), u'.')
     if not len(v):
         return None
     try:
         v = float(v.replace(self.mark(), '.'))
         return v
     except ValueError:
         raise FormatterValidationError(self.errorMessage, value)
예제 #6
0
def phone_constraint(value):
    if re.match(r"\+\d{7,15}", value) is None:
        raise FormatterValidationError(_("Bad phone format"), value)
    return True