changeset 1364:12ddd8661ad6

basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
author Franz Pletz <fpletz AT franz-pletz DOT org>
date Thu, 17 Aug 2006 08:34:22 +0200
parents 1194f8f91158
children 5bf27a0740aa
files MoinMoin/formatter/text_html.py MoinMoin/macro/AdvancedSearch.py MoinMoin/macro/FullSearch.py
diffstat 3 files changed, 99 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/formatter/text_html.py	Tue Aug 15 22:02:37 2006 +0200
+++ b/MoinMoin/formatter/text_html.py	Thu Aug 17 08:34:22 2006 +0200
@@ -6,7 +6,12 @@
     @license: GNU GPL, see COPYING for details.
 """
 import os.path, re
-from sets import Set # TODO: when we require Python 2.4+ use the builtin 'set' type
+
+try:
+    set
+except:
+    from sets import Set as set
+
 from MoinMoin.formatter import FormatterBase
 from MoinMoin import wikiutil, i18n, config
 from MoinMoin.Page import Page
@@ -16,7 +21,7 @@
 prettyprint = False
 
 # These are the HTML elements that we treat as block elements.
-_blocks = Set(['dd', 'div', 'dl', 'dt', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
+_blocks = set(['dd', 'div', 'dl', 'dt', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
                'hr', 'li', 'ol', 'p', 'pre', 'table', 'tbody', 'td', 'tfoot', 'th',
                'thead', 'tr', 'ul', 'blockquote', ])
 
@@ -26,30 +31,30 @@
 # content, and also IE has a parsing bug with those two elements (only)
 # when they don't have a closing tag even if valid XHTML.
 
-_self_closing_tags = Set(['area', 'base', 'br', 'col', 'frame', 'hr', 'img', 'input',
-                          'isindex', 'link', 'meta', 'param'])
+_self_closing_tags = set(['area', 'base', 'br', 'col', 'frame', 'hr', 'img',
+                          'input', 'isindex', 'link', 'meta', 'param'])
 
 # We only open those tags and let the browser auto-close them:
-_auto_closing_tags = Set(['p'])
+_auto_closing_tags = set(['p'])
 
 # These are the elements which generally should cause an increase in the
 # indention level in the html souce code.
-_indenting_tags = Set(['ol', 'ul', 'dl', 'li', 'dt', 'dd', 'tr', 'td'])
+_indenting_tags = set(['ol', 'ul', 'dl', 'li', 'dt', 'dd', 'tr', 'td'])
 
 # These are the elements that discard any whitespace they contain as
 # immediate child nodes.
-_space_eating_tags = Set(['colgroup', 'dl', 'frameset', 'head', 'map' 'menu',
+_space_eating_tags = set(['colgroup', 'dl', 'frameset', 'head', 'map' 'menu',
                           'ol', 'optgroup', 'select', 'table', 'tbody', 'tfoot',
                           'thead', 'tr', 'ul'])
 
 # These are standard HTML attributes which are typically used without any
 # value; e.g., as boolean flags indicated by their presence.
-_html_attribute_boolflags = Set(['compact', 'disabled', 'ismap', 'nohref',
+_html_attribute_boolflags = set(['compact', 'disabled', 'ismap', 'nohref',
                                  'noresize', 'noshade', 'nowrap', 'readonly',
                                  'selected', 'wrap'])
 
 # These are all the standard HTML attributes that are allowed on any element.
-_common_attributes = Set(['accesskey', 'class', 'dir', 'disabled', 'id', 'lang',
+_common_attributes = set(['accesskey', 'class', 'dir', 'disabled', 'id', 'lang',
                           'style', 'tabindex', 'title'])
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/macro/AdvancedSearch.py	Thu Aug 17 08:34:22 2006 +0200
@@ -0,0 +1,83 @@
+# -*- coding: iso-8859-1 -*-
+'''
+    MoinMoin - AdvancedSearch Macro
+
+    [[AdvancedSearch]]
+        displays advanced search dialog.
+
+    MAYBE:
+    [[AdvancedSearch(Help)]]
+        embed results of an advanced search (use more parameters...)
+'''
+
+from MoinMoin import config, wikiutil, search
+
+Dependencies = ['pages']
+
+def advanced_ui(macro):
+    _ = macro._
+    f = macro.formatter
+
+    search_boxes = ''.join([
+        ''.join([
+            f.table_row(1),
+            f.table_cell(1),
+            f.text('%s:' % _(txt)),
+            f.table_cell(0),
+            f.table_cell(1),
+            f.rawHTML(input_field),
+            f.table_cell(0),
+            f.table_row(0),
+        ]) for txt, input_field in (
+            ('Search for pages containing all the following terms',
+                '<input type="text" name="all_terms" size="30">'),
+            ('Search for pages containing one or more of the following '
+                'terms', '<input type="text" name="or_terms" size="30">'),
+            ('Search for pages not containing the following terms',
+                '<input type="text" name="not_terms" size="30">'),
+            ('Search for pages containing only one of the following terms',
+                '<input type="text" name="xor_terms" size="30">'),
+            # TODO: dropdown-box?
+            ('Search for pages belonging to one of the following categories',
+                '<input type="text" name="categories" size="30">'),
+        )
+    ])
+
+    search_options = ''.join([
+        ''.join([
+            f.table_row(1),
+            f.table_cell(1, colspan=2),
+            f.text(_(txt)),
+            f.table_cell(0),
+            f.table_row(0),
+        ]) for txt in ('Language', 'xxxx')
+    ])
+    
+    html = [
+        u'<form method="get" action="">',
+        u'<div>',
+        u'<input type="hidden" name="action" value="fullsearch">',
+        u'<input type="hidden" name="titlesearch" value="%i">' % 0,
+        f.table(1),
+        search_boxes,
+        search_options,
+        f.table(0),
+        u'<input type="submit" value="%s">' % _('Go get it!'),
+        u'</div>',
+        u'</form>',
+    ]
+
+    return f.rawHTML('\n'.join(html))
+
+
+def execute(macro, needle):
+    request = macro.request
+    _ = request.getText
+
+    # no args given
+    if needle is None:
+        return advanced_ui(macro)
+
+    return macro.formatter.rawHTML('wooza!')
+        
+
--- a/MoinMoin/macro/FullSearch.py	Tue Aug 15 22:02:37 2006 +0200
+++ b/MoinMoin/macro/FullSearch.py	Thu Aug 17 08:34:22 2006 +0200
@@ -23,7 +23,8 @@
     context argument, or make another macro that use context, which may
     be easier to use.
 
-    @copyright: 2000-2004 by Jürgen Hermann <jh@web.de>
+    @copyright: 2000-2004 by Jürgen Hermann <jh@web.de>,
+                2005 MoinMoin:FranzPletz
     @license: GNU GPL, see COPYING for details.
 """