changeset 5948:378bfb1d0eec

AttachList: introduced search_term parameter (optional) for listing attachments by a regular expression
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Fri, 08 Mar 2013 08:39:57 +0100
parents e64b119587f8
children 4bdcbead1516
files MoinMoin/action/AttachFile.py MoinMoin/macro/AttachList.py
diffstat 2 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/AttachFile.py	Thu Mar 07 02:06:56 2013 +0100
+++ b/MoinMoin/action/AttachFile.py	Fri Mar 08 08:39:57 2013 +0100
@@ -22,7 +22,7 @@
                 2001-2004 by Juergen Hermann <jh@web.de>,
                 2005 MoinMoin:AlexanderSchremmer,
                 2005 DiegoOngaro at ETSZONE (diego@etszone.com),
-                2005-2007 MoinMoin:ReimarBauer,
+                2005-2013 MoinMoin:ReimarBauer,
                 2007-2008 MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
 """
@@ -310,7 +310,7 @@
     return (pagename, None, None)
 
 
-def _build_filelist(request, pagename, showheader, readonly, mime_type='*'):
+def _build_filelist(request, pagename, showheader, readonly, mime_type='*', filterfn=None):
     _ = request.getText
     fmt = request.html_formatter
 
@@ -320,6 +320,8 @@
 
     if mime_type != '*':
         files = [fname for fname in files if mime_type == mimetypes.guess_type(fname)[0]]
+    if filterfn is not None:
+        files = [fname for fname in files if filterfn(fname)]
 
     html = []
     if files:
--- a/MoinMoin/macro/AttachList.py	Thu Mar 07 02:06:56 2013 +0100
+++ b/MoinMoin/macro/AttachList.py	Fri Mar 08 08:39:57 2013 +0100
@@ -9,16 +9,19 @@
     If mime_type isn't given, all files are listed.
 
     @copyright: 2004 Jacob Cohen, Nigel Metheringham,
-                2006 MoinMoin:ReimarBauer
+                2006-2013 MoinMoin:ReimarBauer
     @license: GNU GPL, see COPYING for details.
 """
 
+import re
+
 from MoinMoin.action.AttachFile import _build_filelist
 
-def macro_AttachList(macro, pagename=None, mime_type=u'*'):
+def macro_AttachList(macro, pagename=None, mime_type=u'*', search_term=u'.+'):
     # defaults if we don't get anything better
     if not pagename:
         pagename = macro.formatter.page.page_name
+    filterfn = re.compile(search_term, re.U).search
+    return _build_filelist(macro.request, pagename, 0, 1, mime_type=mime_type, filterfn=filterfn)
 
-    return _build_filelist(macro.request, pagename, 0, 1, mime_type=mime_type)