view MoinMoin/search/__init__.py @ 1988:490c13d072f2

remove Submit widget The Submit widget was a mistake. The buttons carry no user input, and making it part of the form screws up POST form handling. Instead of being a widget, the submit button has its label kept in the class member submit_label of the Form, and is rendered by a new macro forms.render_submit.
author Cheer Xiao <xiaqqaix@gmail.com>
date Tue, 12 Feb 2013 10:28:18 +0800
parents 384555088cab
children 2003e3685733
line wrap: on
line source
# Copyright: 2011 MoinMoin:MichaelMayorov
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
MoinMoin - MoinMoin search package
"""

from MoinMoin.i18n import L_
from MoinMoin.forms import Search, InlineCheckbox

from flatland import Form, String, Boolean
from flatland.validation import Validator


class ValidSearch(Validator):
    """Validator for a valid search form
    """
    too_short_query_msg = L_('Search query too short.')

    def validate(self, element, state):
        if element['q'].value is None:
            # no query, nothing to search for
            return False
        if len(element['q'].value) < 2:
            return self.note_error(element, state, 'too_short_query_msg')
        return True


class SearchForm(Form):
    q = Search
    history = InlineCheckbox.using(label=L_('search all revisions'))
    submit_label = L_('Search')

    validators = [ValidSearch()]