Back to index

moin  1.9.0~rc2
Functions | Variables
MoinMoin.macro.AdvancedSearch Namespace Reference

Functions

def getMimetypes
def getCategories
def form_get
def advanced_ui
def execute

Variables

list Dependencies = ['pages']

Function Documentation

Returns the code for the advanced search user interface

@param macro: current macro instance

Definition at line 55 of file AdvancedSearch.py.

00055 
00056 def advanced_ui(macro):
00057     """ Returns the code for the advanced search user interface
00058 
00059     @param macro: current macro instance
00060     """
00061     _ = macro._
00062     f = macro.formatter
00063     request = macro.request
00064 
00065     disabledIfMoinSearch = not request.cfg.xapian_search and \
00066             ' disabled="disabled"' or ''
00067 
00068     search_boxes = ''.join([
00069         f.table_row(1),
00070         f.table_cell(1, attrs={'rowspan': '5', 'class': 'searchfor'}),
00071         f.text(_('Search for items')),
00072         f.table_cell(0),
00073         ''.join([''.join([
00074             f.table_row(1),
00075             f.table_cell(1),
00076             f.text(txt),
00077             f.table_cell(0),
00078             f.table_cell(1),
00079             f.rawHTML(input_field),
00080             f.table_cell(0),
00081             f.table_row(0),
00082         ]) for txt, input_field in (
00083             (_('containing all the following terms'),
00084                 '<input type="text" name="and_terms" size="30" value="%s">'
00085                 % (form_get(request, 'and_terms', escaped=True) or form_get(request, 'value', escaped=True))),
00086             (_('containing one or more of the following terms'),
00087                 '<input type="text" name="or_terms" size="30" value="%s">'
00088                 % form_get(request, 'or_terms', escaped=True)),
00089             (_('not containing the following terms'),
00090                 '<input type="text" name="not_terms" size="30" value="%s">'
00091                 % form_get(request, 'not_terms', escaped=True)),
00092             #('containing only one of the following terms',
00093             #    '<input type="text" name="xor_terms" size="30" value="%s">'
00094             #    % form_get(request, 'xor_terms', escaped=True)),
00095             # TODO: dropdown-box?
00096             (_('last modified since (e.g. 2 weeks before)'),
00097                 '<input type="text" name="mtime" size="30" value="%s">'
00098                 % form_get(request, 'mtime', escaped=True)),
00099         )])
00100     ])
00101 
00102     # category selection
00103     categories = form_get(request, 'categories')
00104     c_select = makeSelection('categories',
00105             [('', _('any category'))] +
00106             [(cat, '%s' % cat) for cat in getCategories(request)],
00107             categories, 3, True)
00108 
00109     # language selection
00110     searchedlang = form_get(request, 'language')
00111     langs = dict([(lang, lmeta['x-language-in-english'])
00112         for lang, lmeta in languages.items()])
00113     userlang = macro.request.lang
00114     lang_select = makeSelection('language',
00115             [('', _('any language')),
00116             (userlang, langs[userlang])] + sorted(langs.items(), key=lambda i: i[1]),
00117             searchedlang, 3, True)
00118 
00119     # mimetype selection
00120     mimetype = form_get(request, 'mimetype')
00121     mt_select = makeSelection('mimetype',
00122             [('', _('any mimetype'))] +
00123             [(type, 'all %s files' % type) for type in getMimetypes()] +
00124             [(m[1], '*%s - %s' % m) for m in sorted(mimetypes.types_map.items())],
00125             mimetype, 3, True)
00126 
00127     # misc search options (checkboxes)
00128     search_options = ''.join([
00129         ''.join([
00130             f.table_row(1),
00131             f.table_cell(1, attrs={'class': 'searchfor'}),
00132             txt[0],
00133             f.table_cell(0),
00134             f.table_cell(1, colspan=2),
00135             unicode(txt[1]),
00136             txt[2],
00137             f.table_cell(0),
00138             f.table_row(0),
00139             ]) for txt in (
00140                 (_('Categories'), unicode(c_select), ''),
00141                 (_('Language'), unicode(lang_select), ''),
00142                 (_('File Type'), unicode(mt_select), ''),
00143                 ('', html.INPUT(type='checkbox', name='titlesearch',
00144                     value='1', checked=form_get(request, 'titlesearch', escaped=True),
00145                     id='titlesearch'),
00146                     '<label for="titlesearch">%s</label>' % _('Search only in titles')),
00147                 ('', html.INPUT(type='checkbox', name='case', value='1',
00148                     checked=form_get(request, 'case', escaped=True),
00149                     id='case'),
00150                     '<label for="case">%s</label>' % _('Case-sensitive search')),
00151                 ('', html.INPUT(type='checkbox', name='excludeunderlay',
00152                     value='1', checked=form_get(request, 'excludeunderlay', escaped=True),
00153                     id='excludeunderlay'),
00154                     '<label for="excludeunderlay">%s</label>' % _('Exclude underlay')),
00155                 ('', html.INPUT(type='checkbox', name='nosystemitems',
00156                     value='1', checked=form_get(request, 'nosystemitems', escaped=True),
00157                     id='nosystempages'),
00158                     '<label for="nosystempages">%s</label>' % _('No system items')),
00159                 ('', html.INPUT(type='checkbox', name='historysearch',
00160                     value='1', checked=form_get(request, 'historysearch', escaped=True),
00161                     disabled=(not request.cfg.xapian_search or
00162                         not request.cfg.xapian_index_history),
00163                     id='historysearch'),
00164                     '<label for="historysearch">%s</label>' % _('Search in all page revisions'))
00165             )
00166     ])
00167 
00168     # the dialogue
00169     return f.rawHTML('\n'.join([
00170         u'<form method="get" action="%s">' % macro.request.href(macro.request.formatter.page.page_name),
00171         u'<div>',
00172         u'<input type="hidden" name="action" value="fullsearch">',
00173         u'<input type="hidden" name="advancedsearch" value="1">',
00174         f.table(1, attrs={'tableclass': 'advancedsearch'}),
00175         search_boxes,
00176         search_options,
00177         f.table_row(1),
00178         f.table_cell(1, attrs={'class': 'submit', 'colspan': '3'}),
00179         u'<input type="submit" value="%s">' % _('Go get it!'),
00180         f.table_cell(0),
00181         f.table_row(0),
00182         f.table(0),
00183         u'</div>',
00184         u'</form>',
00185     ]))
00186 

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.macro.AdvancedSearch.execute (   macro,
  needle 
)

Definition at line 187 of file AdvancedSearch.py.

00187 
00188 def execute(macro, needle):
00189     # for now, just show the advanced ui
00190     return advanced_ui(macro)
00191 

Here is the call graph for this function:

def MoinMoin.macro.AdvancedSearch.form_get (   request,
  name,
  default = '',
  escaped = False 
)
Fetches a form field

@param request: current request
@param name: name of the field
@param default: value if not present (default: '')
@param escaped: if True, escape value so it can be used for html generation (default: False)

Definition at line 41 of file AdvancedSearch.py.

00041 
00042 def form_get(request, name, default='', escaped=False):
00043     """ Fetches a form field
00044 
00045     @param request: current request
00046     @param name: name of the field
00047     @param default: value if not present (default: '')
00048     @param escaped: if True, escape value so it can be used for html generation (default: False)
00049     """
00050     value = request.values.get(name, default)
00051     if escaped:
00052         value = wikiutil.escape(value, quote=True)
00053     return value
00054 

Here is the caller graph for this function:

Definition at line 33 of file AdvancedSearch.py.

00033 
00034 def getCategories(request):
00035     # This will return all pages with "Category" in the title
00036     cat_filter = request.cfg.cache.page_category_regexact.search
00037     pages = request.rootpage.getPageList(filter=cat_filter)
00038     pages.sort()
00039     return pages
00040 

Here is the caller graph for this function:

Definition at line 20 of file AdvancedSearch.py.

00020 
00021 def getMimetypes():
00022     # The types will be listed here, instead of parsing mimetypes.types_map
00023     types = [
00024         'application',
00025         'audio',
00026         'image',
00027         'message',
00028         'text',
00029         'video',
00030         ]
00031     return types
00032 

Here is the caller graph for this function:


Variable Documentation

Definition at line 18 of file AdvancedSearch.py.