Beispiel #1
0
    def verifyInput(self, parms, pmap):
        '''Check that the given input is valid.'''
        # Most of the work here is done by the options class, but
        # we may have a few extra checks that are beyond its capabilities
        errmsg = ''

        # mumbo-jumbo to deal with the checkboxes
        # XXX This will break with more than 9 checkboxes
        # XXX A better solution is needed than this
        for name, value in parms.items():
            if name[-2:-1] == '-':
                if parms.has_key(name[:-2]):
                    parms[name[:-2]] += (value,)
                else:
                    parms[name[:-2]] = (value,)
                del parms[name]

        for sect, opt in pmap:
            if opt is None:
                nice_section_name = sect
                continue
            html_key = sect + '_' + opt
            if not parms.has_key(html_key):
                # This is a set of checkboxes where none are selected
                value = ()
                entered_value = "None"
            else:
                value = parms[html_key]
                entered_value = value
                # Tim thinks that Yes/No makes more sense than True/False
                if options.is_boolean(sect, opt):
                    if value == "No":
                        value = False
                    elif value == "Yes":
                        value = True
                if options.multiple_values_allowed(sect, opt) and \
                   value == "":
                        value = ()
                value = options.convert(sect, opt, value)
            if not options.is_valid(sect, opt, value):
                errmsg += '<li>\'%s\' is not a value valid for [%s] %s' % \
                          (entered_value, nice_section_name,
                           options.display_name(sect, opt))
                if type(options.valid_input(sect, opt)) == type((0,1)):
                    errmsg += '. Valid values are: '
                    for valid in options.valid_input(sect, opt):
                        errmsg += str(valid) + ','
                    errmsg = errmsg[:-1] # cut last ','
                errmsg += '</li>'
            parms[html_key] = value

        return errmsg
Beispiel #2
0
 def verifyInput(self, parms, pmap):
     '''Check that the given input is valid.'''
     errmsg = ''
     for name, value in parms.items():
         if name[-2:-1] == '-':
             if parms.has_key(name[:-2]):
                 parms[name[:-2]] += (value,)
             else:
                 parms[name[:-2]] = (value,)
             del parms[name]
     for sect, opt in pmap:
         if opt is None:
             nice_section_name = sect
             continue
         if sect == "Headers" and opt in ("notate_to", "notate_subject"):
             valid_input = (options["Headers", "header_ham_string"],
                            options["Headers", "header_spam_string"],
                            options["Headers", "header_unsure_string"])
         else:
             valid_input = options.valid_input(sect, opt)
         html_key = sect + '_' + opt
         if not parms.has_key(html_key):
             value = ()
             entered_value = "None"
         else:
             value = parms[html_key]
             entered_value = value
             if options.is_boolean(sect, opt):
                 if value == _("No"):
                     value = False
                 elif value == _("Yes"):
                     value = True
             if options.multiple_values_allowed(sect, opt) and \
                value == "":
                 value = ()
             value = options.convert(sect, opt, value)
         if not options.is_valid(sect, opt, value):
             errmsg += _('<li>\'%s\' is not a value valid for [%s] %s') % \
                       (entered_value, nice_section_name,
                        options.display_name(sect, opt))
             if isinstance(valid_input, types.TupleType):
                 errmsg += _('. Valid values are: ')
                 for valid in valid_input:
                     errmsg += str(valid) + ','
                 errmsg = errmsg[:-1] # cut last ','
             errmsg += '</li>'
         parms[html_key] = value
     return errmsg