# HG changeset patch # User Paul Boddie # Date 1368711289 -7200 # Node ID 885085e0371597d2a9af3fc32d1880d2674f4953 # Parent 41468208408e943089bcc0b7ca79fadbe3784b95 Added the display of messages from page message stores. Harmonised the handling and presentation of datetimes. diff -r 41468208408e -r 885085e03715 MoinShare.py --- a/MoinShare.py Tue May 14 23:14:39 2013 +0200 +++ b/MoinShare.py Thu May 16 15:34:49 2013 +0200 @@ -7,9 +7,10 @@ """ from ContentTypeSupport import getContentPreferences -from DateSupport import getCurrentTime +from DateSupport import getCurrentTime, getDateTimeFromRFC2822 from MoinSupport import * from MoinMoin import wikiutil +from email.parser import Parser import re try: @@ -85,9 +86,9 @@ latest_timestamp = metadata.get("last-modified") if latest_timestamp: - return latest_timestamp.as_ISO8601_datetime_string() + return latest_timestamp else: - return getCurrentTime().as_ISO8601_datetime_string() + return getCurrentTime() def getUpdateSources(request, sources_page): @@ -118,6 +119,10 @@ self.fragment = None self.preferred = None + # Message-related attributes. + + self.parts = None + def __cmp__(self, other): if self.updated is None and other.updated is not None: return 1 @@ -148,11 +153,11 @@ for n, (format, attributes, body) in enumerate(getFragments(page.get_raw_body())): + update = Update() + # Produce a fragment identifier. # NOTE: Choose a more robust identifier where none is explicitly given. - update = Update() - update.fragment = attributes.get("fragment", str(n)) update.title = attributes.get("summary", "Update #%d" % n) @@ -189,6 +194,44 @@ return updates +# Update retrieval from message stores. + +def getUpdatesFromStore(page, request): + + """ + Get updates from the message store associated with the given 'page' using + the 'request'. A list of update objects is returned. + """ + + updates = [] + + metadata = getMetadata(page) + updated = getUpdatedTime(metadata) + + store = ItemStore(page, "messages", "message-locks") + + for n, message_text in enumerate(iter(store)): + + update = Update() + message = Parser().parse(StringIO(message_text)) + + # Produce a fragment identifier. + + update.fragment = update.updated = getDateTimeFromRFC2822(message.get("date")) + update.title = message.get("subject", "Update #%d" % n) + + # Determine whether the message has several representations. + + if not message.is_multipart(): + update.content = message.get_payload() + update.content_type = message.get_content_type() + else: + update.parts = message.get_payload() + + updates.append(update) + + return updates + # Source management. def getUpdateSources(pagename, request): diff -r 41468208408e -r 885085e03715 actions/SharedUpdates.py --- a/actions/SharedUpdates.py Tue May 14 23:14:39 2013 +0200 +++ b/actions/SharedUpdates.py Thu May 16 15:34:49 2013 +0200 @@ -103,7 +103,7 @@ "title" : escape(path_info[1:]), "link" : escape(link), "href" : escattr(link), - "updated" : escape(updated), + "updated" : escape(updated.as_ISO8601_datetime_string()), } # Start the output. @@ -136,7 +136,7 @@ "fragment_link" : escape(fragment_link), "download_links" : "\r\n".join(download_links), "content" : update.content and ('%s' % escape(update.content)) or "", - "updated" : escape(update.updated), + "updated" : escape(update.updated.as_ISO8601_datetime_string()), } # Write the entry output. diff -r 41468208408e -r 885085e03715 macros/SharedContent.py --- a/macros/SharedContent.py Tue May 14 23:14:39 2013 +0200 +++ b/macros/SharedContent.py Thu May 16 15:34:49 2013 +0200 @@ -10,7 +10,7 @@ from MoinMoin.Page import Page from MoinRemoteSupport import * from MoinSupport import parseMacroArguments, getParsersForContentType, formatText -from MoinShare import getUpdateSources, getUpdatesFromPage, Update +from MoinShare import getUpdateSources, getUpdatesFromPage, getUpdatesFromStore, Update from email.utils import parsedate import xml.dom.pulldom @@ -289,6 +289,21 @@ ) )) + # Retrieve updates from message stores. + + elif source_parameters.get("type") == "store": + page = Page(request, location) + updates += getUpdatesFromStore(page, request) + + # Build feed-equivalent information for the update source. + + feeds.append(( + page.url(request, {"action" : "SharedUpdates", "store" : "1", "doit" : "1"}), ( + "internal", _("Updates from message store on page %s") % location, + page.url(request) + ) + )) + # Prepare the output. output = []