changeset 1230:4899314f049a

merged
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 09 Jan 2012 11:40:54 +0100
parents 5624136549ab (current diff) 29301b8a2718 (diff)
children 82d28d50ef22
files MoinMoin/items/__init__.py
diffstat 5 files changed, 35 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Mon Jan 09 01:57:49 2012 +0100
+++ b/MoinMoin/apps/frontend/views.py	Mon Jan 09 11:40:54 2012 +0100
@@ -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/items/__init__.py	Mon Jan 09 01:57:49 2012 +0100
+++ b/MoinMoin/items/__init__.py	Mon Jan 09 11:40:54 2012 +0100
@@ -732,6 +732,7 @@
                                rows_meta=str(ROWS_META), cols=str(COLS),
                                help=self.modify_help,
                                form=form,
+                               search_form=None,
                               )
 
     def _render_data_diff(self, oldrev, newrev):
@@ -1210,6 +1211,7 @@
                                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/*'))
@@ -1369,6 +1371,7 @@
                                rows_meta=str(ROWS_META), cols=str(COLS),
                                help=self.modify_help,
                                form=form,
+                               search_form=None,
                               )
 
     def _render_data(self):
@@ -1464,6 +1467,7 @@
                                help=self.modify_help,
                                drawing_exists=drawing_exists,
                                form=form,
+                               search_form=None,
                               )
 
     def _render_data(self):
@@ -1545,6 +1549,7 @@
                                rows_meta=str(ROWS_META), cols=str(COLS),
                                help=self.modify_help,
                                form=form,
+                               search_form=None,
                               )
 
     def _render_data(self):
--- a/MoinMoin/search/__init__.py	Mon Jan 09 01:57:49 2012 +0100
+++ b/MoinMoin/search/__init__.py	Mon Jan 09 11:40:54 2012 +0100
@@ -5,3 +5,28 @@
 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	Mon Jan 09 01:57:49 2012 +0100
+++ b/MoinMoin/templates/layout.html	Mon Jan 09 11:40:54 2012 +0100
@@ -18,7 +18,7 @@
 
 <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') }}
@@ -26,7 +26,7 @@
             {{ forms.render_errors(search_form) }}
         </div>
     {{ gen.form.close() }}
-    {% endif %} 
+    {% endif %}
 
     {% if logo %}
     <div id="moin-logo">
--- a/MoinMoin/themes/__init__.py	Mon Jan 09 01:57:49 2012 +0100
+++ b/MoinMoin/themes/__init__.py	Mon Jan 09 11:40:54 2012 +0100
@@ -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(),
                             })