changeset 1653:5b15b6e010cf

AttachList can list files of given mimetype now (ported from 1.5)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 31 Oct 2006 22:11:29 +0100
parents 4e027adb9f25
children 2a1f570ea6d4
files MoinMoin/action/AttachFile.py MoinMoin/macro/AttachList.py
diffstat 2 files changed, 18 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/AttachFile.py	Tue Oct 31 22:06:16 2006 +0100
+++ b/MoinMoin/action/AttachFile.py	Tue Oct 31 22:11:29 2006 +0100
@@ -251,13 +251,16 @@
     return (None, None)
 
 
-def _build_filelist(request, pagename, showheader, readonly):
+def _build_filelist(request, pagename, showheader, readonly, mime_type='*'):
     _ = request.getText
 
     # access directory
     attach_dir = getAttachDir(request, pagename)
     files = _get_files(request, pagename)
 
+    if mime_type != '*':
+        files = [fname for fname in files if mime_type == mimetypes.guess_type(fname)[0]]
+
     str = ""
     if files:
         if showheader:
--- a/MoinMoin/macro/AttachList.py	Tue Oct 31 22:06:16 2006 +0100
+++ b/MoinMoin/macro/AttachList.py	Tue Oct 31 22:11:29 2006 +0100
@@ -1,20 +1,29 @@
 """
     MoinMoin - AttachList Macro
 
-    A macro to produce a list of attached pages
+    A macro to produce a list of attached files
 
-    Usage: [[AttachList]]
+    Usage: [[AttachList([pagename,mime_type])]]
+
+    If pagename isn't set, the current pagename is used.
+    If mime_type isn't given, all files are listed.
 
     @copyright: 2004 Jacob Cohen, Nigel Metheringham
+    @copyright: 2006 Reimar Bauer
     @license: GNU GPL, see COPYING for details.
 """
 
 from MoinMoin.action.AttachFile import _build_filelist
 
 def execute(macro, args):
+    # defaults if we don't get anything better
     pagename = macro.formatter.page.page_name
+    mime_type = '*'
     if args:
-        pagename = args
-    result = _build_filelist(macro.request, pagename, 0, 1)
-    return result
+        args = args.split(',')
+        if args[0].strip():
+            pagename = args[0].strip()
+        if len(args) > 1 and args[1].strip():
+            mime_type = args[1].strip()
+    return _build_filelist(macro.request, pagename, 0, 1, mime_type=mime_type)