Ejemplo n.º 1
0
 def _validate_coordinate(self, widget, text, typedeg):
     if (typedeg == 'lat') and not conv_lat_lon(text, "0", "ISO-D"):
         return ValidationError(_("Invalid latitude (syntax: 18\u00b09'") +
                                _('48.21"S, -18.2412 or -18:9:48.21)'))
     elif (typedeg == 'lon') and not conv_lat_lon("0", text, "ISO-D"):
         return ValidationError(_("Invalid longitude (syntax: 18\u00b09'") +
                                _('48.21"E, -18.2412 or -18:9:48.21)'))
Ejemplo n.º 2
0
 def validate(self, widget, data):
     """
     Validate current date in text entry
     """
     # if text could not be parsed it is assumed invalid
     if self.date_obj.get_modifier() == Date.MOD_TEXTONLY:
         return ValidationError(_('Bad Date'))
     elif (self.date_obj.to_calendar(calendar_name=Date.CAL_GREGORIAN) >>
           NextYear()):
         return ValidationError(_('Date more than one year in the future'))
Ejemplo n.º 3
0
 def _validate_coordinate(self, widget, text, typedeg):
     if (typedeg == 'lat') and not conv_lat_lon(text, "0", "ISO-D"):
         return ValidationError(
             # translators: translate the "S" too (and the "or" of course)
             _('Invalid latitude\n(syntax: '
               '18\u00b09\'48.21"S, -18.2412 or -18:9:48.21)'))
     elif (typedeg == 'lon') and not conv_lat_lon("0", text, "ISO-D"):
         return ValidationError(
             # translators: translate the "E" too (and the "or" of course)
             _('Invalid longitude\n(syntax: '
               '18\u00b09\'48.21"E, -18.2412 or -18:9:48.21)'))
Ejemplo n.º 4
0
 def _validate(self, widget, text):
     for level in text.split(','):
         parts = level.split(':')
         if len(parts) < 1:
             return ValidationError('Empty level')
         if len(parts) > 2:
             return ValidationError('Invalid slice')
         for part in parts:
             integer_str = part.replace('p', '')
             if integer_str != '':
                 try:
                     integer = int(integer_str)
                 except ValueError:
                     return ValidationError('Invalid format string')
Ejemplo n.º 5
0
 def _validate_call(self, widget, text):
     """ a callname must be a part of the given name, see if this is the
         case """
     validcall = self.given.obj.get_text().split()
     dummy = copy(validcall)
     for item in dummy:
         validcall += item.split('-')
     if text in validcall:
         return
     return ValidationError(_("Call name must be the given name that "
                                  "is normally used."))
Ejemplo n.º 6
0
    def validate(self, force=False):
        """
        Checks if the data is valid.
        Validates data-type and custom validation.

        :param force: if True, force validation
        :returns: validated data or ValueUnset if it failed
        """

        # If we're not visible or sensitive return a blank value, except
        # when forcing the validation
        if not force and (not self.get_property('visible') or
                          not self.get_property('sensitive')):
            return None

        try:
            text = self.get_text()
            ##_LOG.debug('Read %r for %s' %  (data, self.model_attribute))

            # check if we should draw the mandatory icon
            # this need to be done before any data conversion because we
            # we don't want to end drawing two icons
            if self.mandatory and self.is_empty():
                self.set_blank()
                return None
            else:
                if self._completion:
                    for row in self.get_completion().get_model():
                        if row[COL_TEXT] == text:
                            break
                    else:
                        if text:
                            raise ValidationError()
                else:
                    if not self.is_empty():
                        # this signal calls the custom validation method
                        # of the instance and gets the exception (if any).
                        error = self.emit("validate", text)
                        if error:
                            raise error

            self.set_valid()
            return text
        except ValidationError as e:
            self.set_invalid(str(e))
            return None
Ejemplo n.º 7
0
 def on_validate(widget, text):
     myDate = parser.parse(text)
     if not myDate.is_regular():
         # used on AgeOnDateGramplet
         return ValidationError(_("'%s' is not a valid date value"))
Ejemplo n.º 8
0
 def _validate_iso_code(self, widget, text):
     if text not in ISO_CODES:
         return ValidationError(_("Invalid ISO code"))