Exemplo n.º 1
0
 def _validate_coordinate(self, widget, text, typedeg):
     if (typedeg == 'lat') and not conv_lat_lon(text, "0", "ISO-D"):
         return ValidationError(_(u"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(_(u"Invalid longitude (syntax: 18\u00b09'") +
                                _('48.21"E, -18.2412 or -18:9:48.21)'))
Exemplo 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'))
Exemplo n.º 3
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_field.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."))
Exemplo n.º 4
0
  def validate(self, field, key, REQUEST):
    try:
      year = field.validate_sub_field('year', REQUEST, key=key)
      month = field.validate_sub_field('month', REQUEST, key=key)
      if field.get_value('hide_day'):
        day = 1
      else:
        day = field.validate_sub_field('day', REQUEST, key=key)

      if field.get_value('date_only'):
        hour = 0
        minute = 0
      elif field.get_value('allow_empty_time'):
          hour = field.validate_sub_field('hour', REQUEST, key=key)
          minute = field.validate_sub_field('minute', REQUEST, key=key)
          if hour == '' and minute == '':
            hour = 0
            minute = 0
          elif hour == '' or minute == '':
            raise ValidationError('not_datetime', field)
      else:
        hour = field.validate_sub_field('hour', REQUEST, key=key)
        minute = field.validate_sub_field('minute', REQUEST, key=key)
    except ValidationError:
      self.raise_error('not_datetime', field)

    # handling of completely empty sub fields
    if ((year == '' and month == '') and
        (field.get_value('hide_day') or day == '') and
        (field.get_value('date_only') or (hour == '' and minute == '')
        or (hour == 0 and minute == 0))):
      if field.get_value('required'):
        self.raise_error('required_not_found', field)
      else:
        # field is not required, return None for no entry
        return None
    # handling of partially empty sub fields; invalid datetime
    if ((year == '' or month == '') or
        (not field.get_value('hide_day') and day == '') or
        (not field.get_value('date_only') and
        (hour == '' or minute == ''))):
      self.raise_error('not_datetime', field)

    if field.get_value('ampm_time_style'):
      ampm = field.validate_sub_field('ampm', REQUEST, key=key)
      if field.get_value('allow_empty_time'):
        if ampm == '':
          ampm = 'am'
      hour = int(hour)
      # handling not am or pm
      # handling hour > 12
      if ((ampm != 'am') and (ampm != 'pm')) or (hour > 12):
        self.raise_error('not_datetime', field)
      if (ampm == 'pm') and (hour == 0):
        self.raise_error('not_datetime', field)
      elif ampm == 'pm' and hour < 12:
        hour += 12

    # handle possible timezone input
    timezone = ''
    if field.get_value('timezone_style'):
      timezone =  field.validate_sub_field('timezone', REQUEST, key=key)

    try:
      # handling of hidden day, which can be first or last day of the month:
      if field.get_value('hidden_day_is_last_day'):
        if int(month) == 12:
          tmp_year = int(year) + 1
          tmp_month = 1
        else:
          tmp_year = int(year)
          tmp_month = int(month) + 1
        tmp_day = DateTime(tmp_year, tmp_month, 1, hour, minute)
        result = tmp_day - 1
      else:
        result = DateTime(int(year),
                          int(month),
                          int(day),
                          hour,
                          minute)
        year = result.year()
        result = DateTime('%s/%s/%s %s:%s %s' % (year,
                            int(month),
                            int(day),
                            hour,
                            minute, timezone))
      # ugh, a host of string based exceptions (not since Zope 2.7)
    except ('DateTimeError', 'Invalid Date Components', 'TimeError',
            DateError, TimeError) :
      self.raise_error('not_datetime', field)
    # pass value through request in order to be restored in case if validation fail
    if getattr(REQUEST, 'form', None):
      REQUEST.form[key] = result
    # check if things are within range
    start_datetime = field.get_value('start_datetime')
    if (start_datetime not in (None, '') and
      result < start_datetime):
      self.raise_error('datetime_out_of_range', field)
    end_datetime = field.get_value('end_datetime')
    if (end_datetime not in (None, '') and
      result >= end_datetime):
      self.raise_error('datetime_out_of_range', field)

    return result
Exemplo n.º 5
0
 def raise_error(self, error_key, field):
     raise ValidationError(error_key, field)