1.1 --- a/macros/ShowMessages.py Fri May 17 20:46:36 2013 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,106 +0,0 @@
1.4 -# -*- coding: iso-8859-1 -*-
1.5 -"""
1.6 - MoinMoin - ShowMessages Macro
1.7 -
1.8 - @copyright: 2012, 2013 by Paul Boddie <paul@boddie.org.uk>
1.9 - @license: GNU GPL (v2 or later), see COPYING.txt for details.
1.10 -"""
1.11 -
1.12 -from MoinSupport import \
1.13 - ItemStore, get_form, parseMacroArguments, getParsersForContentType, formatText
1.14 -from email.parser import Parser
1.15 -
1.16 -try:
1.17 - from cStringIO import StringIO
1.18 -except ImportError:
1.19 - from StringIO import StringIO
1.20 -
1.21 -Dependencies = ['pages']
1.22 -
1.23 -# Macro functions.
1.24 -
1.25 -def execute(macro, args):
1.26 -
1.27 - """
1.28 - Execute the 'macro' with the given 'args' to produce a list of messages from
1.29 - a message store associated with the current page.
1.30 - """
1.31 -
1.32 - request = macro.request
1.33 - fmt = macro.formatter
1.34 - page = fmt.page
1.35 - _ = request.getText
1.36 -
1.37 - # Interpret the arguments.
1.38 -
1.39 - parsed_args = dict(parseMacroArguments(args))
1.40 - fragment = parsed_args.get("fragment")
1.41 -
1.42 - # Obtain any request parameters corresponding to the field.
1.43 - # NOTE: Get selection of representations for display.
1.44 -
1.45 - form = get_form(request)
1.46 -
1.47 - # Show the messages.
1.48 - # NOTE: Support additional access control.
1.49 -
1.50 - store = ItemStore(page, "messages", "message-locks")
1.51 -
1.52 - output = []
1.53 - output.append(fmt.div(on=1, css_class="showmessages-messages"))
1.54 -
1.55 - for message_text in iter(store).reversed():
1.56 - message = Parser().parse(StringIO(message_text))
1.57 -
1.58 - # Determine whether the message has several representations.
1.59 -
1.60 - if not message.is_multipart():
1.61 - parts = [message]
1.62 - else:
1.63 - parts = message.get_payload()
1.64 -
1.65 - # Show the parts.
1.66 -
1.67 - output.append(fmt.div(on=1, css_class="showmessages-message"))
1.68 - first = True
1.69 -
1.70 - for part in parts:
1.71 -
1.72 - # Set the appearance of the part.
1.73 -
1.74 - extra_flags = first and " showmessages-shown-part" or ""
1.75 - css_class = "showmessages-message-part%s" % extra_flags
1.76 -
1.77 - output.append(fmt.div(on=1, css_class=css_class))
1.78 -
1.79 - # Find a parser for the content type.
1.80 -
1.81 - mimetype = part.get_content_type()
1.82 - parsers = getParsersForContentType(request.cfg, mimetype)
1.83 -
1.84 - if parsers:
1.85 - for parser_cls in parsers:
1.86 -
1.87 - # NOTE: Could check for output_mimetypes and use formatForOutputType.
1.88 - # Emit the parsed content.
1.89 -
1.90 - output.append(formatText(part.get_payload(), request, fmt, parser_cls=parser_cls))
1.91 - break
1.92 - else:
1.93 - output.append(fmt.text(_("Update cannot be shown for content of type %s.") % mimetype))
1.94 -
1.95 - # End message part.
1.96 -
1.97 - output.append(fmt.div(on=0))
1.98 - first = False
1.99 -
1.100 - # End message.
1.101 -
1.102 - output.append(fmt.div(on=0))
1.103 -
1.104 - # End message list.
1.105 -
1.106 - output.append(fmt.div(on=0))
1.107 - return u"".join(output)
1.108 -
1.109 -# vim: tabstop=4 expandtab shiftwidth=4