changeset 1227:18cb4213fc4d

Always show search box in layout.html
author Sam Toyer <samATqxcvDOTnet>
date Sun, 08 Jan 2012 20:15:24 +1000
parents e3df544da406
children c6ab64b8399a
files MoinMoin/apps/frontend/views.py MoinMoin/search/__init__.py MoinMoin/templates/layout.html MoinMoin/themes/__init__.py
diffstat 4 files changed, 30 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Sun Jan 08 20:55:32 2012 +0100
+++ b/MoinMoin/apps/frontend/views.py	Sun Jan 08 20:15:24 2012 +1000
@@ -55,6 +55,7 @@
                             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
@@ -124,27 +125,6 @@
     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")
@@ -217,7 +197,6 @@
                               data_rendered=Markup(item._render_data()),
                               show_revision=show_revision,
                               show_navigation=show_navigation,
-                              search_form=SearchForm.from_defaults(),
                              )
     return Response(content, status)
 
--- a/MoinMoin/search/__init__.py	Sun Jan 08 20:55:32 2012 +0100
+++ b/MoinMoin/search/__init__.py	Sun Jan 08 20:15:24 2012 +1000
@@ -5,3 +5,30 @@
 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()]
+
+
+
--- a/MoinMoin/templates/layout.html	Sun Jan 08 20:55:32 2012 +0100
+++ b/MoinMoin/templates/layout.html	Sun Jan 08 20:15:24 2012 +1000
@@ -18,7 +18,6 @@
 
 <div id="moin-header">
 {% block header %}
-    {% 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') }}
@@ -26,7 +25,6 @@
             {{ forms.render_errors(search_form) }}
         </div>
     {{ gen.form.close() }}
-    {% endif %} 
 
     {% if logo %}
     <div id="moin-logo">
--- a/MoinMoin/themes/__init__.py	Sun Jan 08 20:55:32 2012 +0100
+++ b/MoinMoin/themes/__init__.py	Sun Jan 08 20:15:24 2012 +1000
@@ -24,6 +24,7 @@
 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
@@ -432,5 +433,6 @@
                             'get_editor_info': lambda meta: get_editor_info(meta),
                             'utctimestamp': lambda dt: utctimestamp(dt),
                             'gen': make_generator(),
+                            'search_form': SearchForm.from_defaults(),
                             })