Commits

Thomas Waldmann committed 4899314 Merge

merged

  • Participants
  • Parent commits 5624136, 29301b8

Comments (0)

Files changed (5)

File MoinMoin/apps/frontend/views.py

                             ALL_REVS, LATEST_REVS
 from MoinMoin.util import crypto
 from MoinMoin.util.interwiki import url_for_item
+from MoinMoin.search import SearchForm, ValidSearch
 from MoinMoin.security.textcha import TextCha, TextChaizedForm, TextChaValid
 from MoinMoin.storage.error import NoSuchItemError, NoSuchRevisionError
 from MoinMoin.signalling import item_displayed, item_modified
     return app.send_static_file('logos/favicon.ico')
 
 
-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 = String.using(optional=False, default=u'').with_properties(autofocus=True, placeholder=L_("Search Query"))
-    history = Boolean.using(label=L_('search also in non-current revisions'), optional=True)
-    submit = String.using(default=L_('Search'), optional=True)
-
-    validators = [ValidSearch()]
-
-
 @frontend.route('/+search', methods=['GET', 'POST'])
 def search():
     title_name = _("Search")
                               data_rendered=Markup(item._render_data()),
                               show_revision=show_revision,
                               show_navigation=show_navigation,
-                              search_form=SearchForm.from_defaults(),
                              )
     return Response(content, status)
 

File MoinMoin/items/__init__.py

                                rows_meta=str(ROWS_META), cols=str(COLS),
                                help=self.modify_help,
                                form=form,
+                               search_form=None,
                               )
 
     def _render_data_diff(self, oldrev, newrev):
                                rows_data=str(ROWS_DATA), rows_meta=str(ROWS_META), cols=str(COLS),
                                help=self.modify_help,
                                form=form,
+                               search_form=None,
                               )
 
 item_registry.register(Text._factory, Type('text/*'))
                                rows_meta=str(ROWS_META), cols=str(COLS),
                                help=self.modify_help,
                                form=form,
+                               search_form=None,
                               )
 
     def _render_data(self):
                                help=self.modify_help,
                                drawing_exists=drawing_exists,
                                form=form,
+                               search_form=None,
                               )
 
     def _render_data(self):
                                rows_meta=str(ROWS_META), cols=str(COLS),
                                help=self.modify_help,
                                form=form,
+                               search_form=None,
                               )
 
     def _render_data(self):

File MoinMoin/search/__init__.py

 MoinMoin - MoinMoin search package
 """
 
+from MoinMoin.i18n import L_
+
+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 = String.using(optional=False, default=u'').with_properties(autofocus=True, placeholder=L_("Search Query"))
+    history = Boolean.using(label=L_('search also in non-current revisions'), optional=True)
+    submit = String.using(default=L_('Search'), optional=True)
+
+    validators = [ValidSearch()]
+

File MoinMoin/templates/layout.html

 
 <div id="moin-header">
 {% block header %}
-    {% if search_form %} 
+    {% if search_form %}
     {{ gen.form.open(search_form, id='moin-searchform', method='get', action=url_for('frontend.search')) }}
         <div>
             {{ gen.input(search_form['q'], type='search', id='moin-search-query', size='40') }}
             {{ forms.render_errors(search_form) }}
         </div>
     {{ gen.form.close() }}
-    {% endif %} 
+    {% endif %}
 
     {% if logo %}
     <div id="moin-logo">

File MoinMoin/themes/__init__.py

 from MoinMoin.i18n import _, L_, N_
 from MoinMoin import wikiutil, user
 from MoinMoin.config import USERID, ADDRESS, HOSTNAME
+from MoinMoin.search import SearchForm
 from MoinMoin.util.interwiki import split_interwiki, getInterwikiHome, is_local_wiki, is_known_wiki, url_for_item
 from MoinMoin.util.crypto import cache_key
 from MoinMoin.util.forms import make_generator
                             'get_editor_info': lambda meta: get_editor_info(meta),
                             'utctimestamp': lambda dt: utctimestamp(dt),
                             'gen': make_generator(),
+                            'search_form': SearchForm.from_defaults(),
                             })