# HG changeset patch # User Paul Boddie # Date 1555358846 -7200 # Node ID 9c0eca408f20b3f2b2a32ea0474708e6ceff0233 # Parent 886cd734be0c6aea9bade527859f86e3a2407718 Added MIME type filtering. diff -r 886cd734be0c -r 9c0eca408f20 moinformat/macros/attachlist.py --- a/moinformat/macros/attachlist.py Mon Apr 15 22:07:03 2019 +0200 +++ b/moinformat/macros/attachlist.py Mon Apr 15 22:07:26 2019 +0200 @@ -19,6 +19,7 @@ this program. If not, see . """ +from mimetypes import guess_type from moinformat.macros.common import Macro from moinformat.tree.moin import Link, LinkLabel, List, ListItem, Text from moinformat.utils.links import LinkTarget @@ -43,10 +44,21 @@ # Access the input context to get the attachment details. input = self.metadata.get_input() - filenames = pagename and input.get_attachments(pagename) or [] # Select attachments by type. - # NOTE: To do. + + all_filenames = pagename and input.get_attachments(pagename) or [] + + if mimetype: + filenames = [] + + for filename in all_filenames: + type, encoding = guess_type(filename) + + if type == mimetype: + filenames.append(filename) + else: + filenames = all_filenames # Prepare a list of links.