Пример #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
Пример #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
Пример #3
0
    def _buildConfigPage(self, parm_map):
        # Start with an empty config form then add the sections.
        html = self._getHTMLClone()
        # "Save and Shutdown" is confusing here - it means "Save database"
        # but that's not clear.
        html.shutdownTableCell = "&nbsp;"
        html.mainContent = self.html.configForm.clone()
        html.mainContent.configFormContent = ""
        html.mainContent.optionsPathname = optionsPathname
        configTable = None
        section = None

        # Loop though the sections.
        for sect, opt in parm_map:
            # We need a string to use as the html key that we can change to
            # and from the sect, opt pair.  We like irony, so we use '_' as
            # the delimiter <wink>.
            if opt is None:
                if configTable is not None and section is not None:
                    # Finish off the box for this section and add it
                    # to the form.
                    section.boxContent = configTable
                    html.configFormContent += section
                # Start the yellow-headed box for this section.
                section = self.html.headedBox.clone()
                # Get a clone of the config table and a clone of each
                # example row, then blank out the example rows to make way
                # for the real ones.
                configTable = self.html.configTable.clone()
                configTextRow1 = configTable.configTextRow1.clone()
                configTextRow2 = configTable.configTextRow2.clone()
                configCbRow1 = configTable.configCbRow1.clone()
                configRow2 = configTable.configRow2.clone()
                blankRow = configTable.blankRow.clone()
                del configTable.configTextRow1
                del configTable.configTextRow2
                del configTable.configCbRow1
                del configTable.configRow2
                del configTable.blankRow
                del configTable.folderRow
                section.heading = sect
                del section.iconCell
                continue
            html_key = sect + '_' + opt

            # Populate the rows with the details and add them to the table.
            if type(options.valid_input(sect, opt)) in types.StringTypes:
                # we provide a text input
                newConfigRow1 = configTextRow1.clone()
                newConfigRow1.label = options.display_name(sect, opt)
                newConfigRow1.input.name = html_key
                newConfigRow1.input.value = options.unconvert(sect, opt)
            else:
                # we provide checkboxes/radio buttons
                newConfigRow1 = configCbRow1.clone()
                newConfigRow1.label = options.display_name(sect, opt)
                blankOption = newConfigRow1.input.clone()
                firstOpt = True
                i = 0
                for val in options.valid_input(sect, opt):
                    newOption = blankOption.clone()
                    if options.multiple_values_allowed(sect, opt):
                        if val in options[sect, opt]:
                            newOption.input_box.checked = "checked"
                        newOption.input_box.type = "checkbox"
                        newOption.input_box.name = html_key + '-' + str(i)
                        i += 1
                    else:
                        if val == options[sect, opt]:
                            newOption.input_box.checked = "checked"
                        newOption.input_box.type = "radio"
                        newOption.input_box.name = html_key
                    # Tim thinks that Yes/No makes more sense than True/False
                    if options.is_boolean(sect, opt):
                        if val == False:
                            val = "No"
                        elif val == True:
                            val = "Yes"
                    newOption.val_label = str(val)
                    newOption.input_box.value = str(val)
                    if firstOpt:
                        newConfigRow1.input = newOption
                        firstOpt = False
                    else:
                        newConfigRow1.input += newOption
            # Insert the help text in a cell
            newConfigRow1.helpCell = '<strong>' + \
                                     options.display_name(sect, opt) + \
                                     ':</strong> ' + \
                                     cgi.escape(options.doc(sect, opt))

            newConfigRow2 = configRow2.clone()
            currentValue = options[sect, opt]

            if type(currentValue) in types.StringTypes:
                currentValue = currentValue.replace(',', ', ')
                newConfigRow2 = configTextRow2.clone()
            else:
                currentValue = options.unconvert(sect, opt)
                newConfigRow2 = configRow2.clone()

            # Tim thinks that Yes/No makes more sense than True/False
            if options.is_boolean(sect, opt):
                if currentValue == "False":
                    currentValue = "No"
                elif currentValue == "True":
                    currentValue = "Yes"
            # XXX Something needs to be done here, otherwise really
            # XXX long options squeeze the help text too far to the
            # XXX right.  Browsers can't wrap the text (even if
            # XXX no-wrap is False) unless there is whitespace to
            # XXX wrap on - comma's don't count.  This works, but
            # XXX it's a bit ugly.  Ideas?
            # currentValue = str(currentValue).replace(',', '<br />')
            newConfigRow2.currentValue = currentValue
            configTable += newConfigRow1 + newConfigRow2 + blankRow

        # Finish off the box for this section and add it to the form.
        if section is not None:
            section.boxContent = configTable
            html.configFormContent += section
        return html
Пример #4
0
 def _buildConfigPageBody(self, html, parm_map):
     configTable = None
     section = None
     for sect, opt in parm_map:
         if opt is None:
             if configTable is not None and section is not None:
                 section.boxContent = configTable
                 html.configFormContent += section
             section = self.html.headedBox.clone()
             configTable = self.html.configTable.clone()
             configTextRow1 = configTable.configTextRow1.clone()
             configTextRow2 = configTable.configTextRow2.clone()
             configCbRow1 = configTable.configCbRow1.clone()
             configRow2 = configTable.configRow2.clone()
             blankRow = configTable.blankRow.clone()
             del configTable.configTextRow1
             del configTable.configTextRow2
             del configTable.configCbRow1
             del configTable.configRow2
             del configTable.blankRow
             del configTable.folderRow
             section.heading = sect
             del section.iconCell
             continue
         html_key = sect + '_' + opt
         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)
         if isinstance(valid_input, types.StringTypes):
             newConfigRow1 = configTextRow1.clone()
             newConfigRow1.label = options.display_name(sect, opt)
             newConfigRow1.input.name = html_key
             newConfigRow1.input.value = options.unconvert(sect, opt)
         else:
             newConfigRow1 = configCbRow1.clone()
             newConfigRow1.label = options.display_name(sect, opt)
             blankOption = newConfigRow1.input.clone()
             firstOpt = True
             i = 0
             for val in valid_input:
                 newOption = blankOption.clone()
                 if options.multiple_values_allowed(sect, opt):
                     if val in options[sect, opt]:
                         newOption.input_box.checked = "checked"
                     newOption.input_box.type = "checkbox"
                     newOption.input_box.name = html_key + '-' + str(i)
                     i += 1
                 else:
                     if val == options[sect, opt]:
                         newOption.input_box.checked = "checked"
                     newOption.input_box.type = "radio"
                     newOption.input_box.name = html_key
                 if options.is_boolean(sect, opt):
                     if val is True:
                         val = "Yes"
                     elif val is False:
                         val = "No"
                 newOption.val_label = str(val)
                 newOption.input_box.value = str(val)
                 if firstOpt:
                     newConfigRow1.input = newOption
                     firstOpt = False
                 else:
                     newConfigRow1.input += newOption
         newConfigRow1.helpCell = '<strong>' + \
                                  options.display_name(sect, opt) + \
                                  ':</strong> ' + \
                                  cgi.escape(options.doc(sect, opt))
         newConfigRow2 = configRow2.clone()
         currentValue = options[sect, opt]
         if type(currentValue) in types.StringTypes:
             currentValue = currentValue.replace(',', ', ')
             newConfigRow2 = configTextRow2.clone()
         else:
             currentValue = options.unconvert(sect, opt)
             newConfigRow2 = configRow2.clone()
         if options.is_boolean(sect, opt):
             if currentValue == "False":
                 currentValue = _("No")
             elif currentValue == "True":
                 currentValue = _("Yes")
         newConfigRow2.currentValue = currentValue
         configTable += newConfigRow1 + newConfigRow2 + blankRow
     if section is not None:
         section.boxContent = configTable
         html.configFormContent += section
     return html