# HG changeset patch # User Paul Boddie # Date 1368488242 -7200 # Node ID 8c25dd04bf78e9627a7e11d78ca1614f29096917 # Parent 4967a73df0a59a840ea378548dfef7f1f5bc487f Added support for the retrieval of internal page-based updates to the macro. Made the retrieval of page updates use the Update class so that both feed-based and page-based updates can be obtained and used by the macro, also changing the action to manipulate Update instances provided by the renamed getUpdatesFromPage function. diff -r 4967a73df0a5 -r 8c25dd04bf78 MoinShare.py --- a/MoinShare.py Tue May 14 00:53:38 2013 +0200 +++ b/MoinShare.py Tue May 14 01:37:22 2013 +0200 @@ -100,14 +100,39 @@ return getWikiDict(sources_page, request) -def getUpdateFragmentsFromPage(page, request): +# Entry/update classes. + +class Update: + + "A feed update entry." + + def __init__(self): + self.title = None + self.link = None + self.content = None + self.content_type = None + self.updated = None + + # Page-related attributes. + + self.fragment = None + self.preferred = None + + def __cmp__(self, other): + if self.updated is None and other.updated is not None: + return 1 + elif self.updated is not None and other.updated is None: + return -1 + else: + return cmp(self.updated, other.updated) + +# Update retrieval from pages. + +def getUpdatesFromPage(page, request): """ - Get update fragments from the given 'page' using the 'request'. A list of - update descriptions is returned, each being a tuple of the form... - - (fragment identifer, summary text, preferred mimetypes, textual content, - updated datetime) + Get updates from the given 'page' using the 'request'. A list of update + objects is returned. """ updates = [] @@ -126,34 +151,41 @@ # Produce a fragment identifier. # NOTE: Choose a more robust identifier where none is explicitly given. - fragment = attributes.get("fragment", str(n)) - summary = attributes.get("summary", "Update #%d" % n) + update = Update() + + update.fragment = attributes.get("fragment", str(n)) + update.title = attributes.get("summary", "Update #%d" % n) # Get the preferred content types available for the fragment. - preferred = getPreferredOutputTypes(request, getOutputTypes(request, format)) + update.preferred = getPreferredOutputTypes(request, getOutputTypes(request, format)) # Try and obtain some suitable content for the entry. # NOTE: Could potentially get a summary for the fragment. - content = None + update.content = None - if "text/html" in preferred: + if "text/html" in update.preferred: parser_cls = getParserClass(request, format) parser = parser_cls(body, request) if format == "html": - content = body + update.content = body elif hasattr(parser, "formatForOutputType"): s = StringIO() parser.formatForOutputType("text/html", write=s.write) - content = s.getvalue() + update.content = s.getvalue() else: fmt = request.html_formatter fmt.setPage(page) - content = formatText(body, request, fmt, parser_cls) + update.content = formatText(body, request, fmt, parser_cls) + + update.content_type = "html" - updates.append((fragment, summary, preferred, content, updated)) + update.link = page.url(request) + update.updated = updated + + updates.append(update) return updates diff -r 4967a73df0a5 -r 8c25dd04bf78 actions/SharedUpdates.py --- a/actions/SharedUpdates.py Tue May 14 00:53:38 2013 +0200 +++ b/actions/SharedUpdates.py Tue May 14 01:37:22 2013 +0200 @@ -9,7 +9,7 @@ from MoinMoin.action import ActionBase from MoinMoin.Page import Page from MoinMoin import wikiutil -from MoinShare import getUpdatedTime, getUpdateFragmentsFromPage +from MoinShare import getUpdatedTime, getUpdatesFromPage from MoinSupport import escattr, get_form, getMetadata, getPathInfo, \ writeHeaders, ActionSupport @@ -117,27 +117,26 @@ %(updated)s\r ''' % d) - for fragment, summary, preferred, content, updated in \ - getUpdateFragmentsFromPage(page, request): + for update in getUpdatesFromPage(page, request): # Get the URL that yields only the fragment. - fragment_link = "%s?action=SharedUpdate&fragment=%s" % (link, fragment) + fragment_link = "%s?action=SharedUpdate&fragment=%s" % (update.link, update.fragment) download_links = [] - for mimetype in preferred: + for mimetype in update.preferred: specific_link = "%s&type=%s&doit=1" % (fragment_link, mimetype) download_links.append('' % ( escattr(mimetype), escattr(specific_link))) d = { - "title" : escape(summary), + "title" : escape(update.title), "fragment_link" : escape(fragment_link), "download_links" : "\r\n".join(download_links), - "content" : content and ('%s' % escape(content)) or "", - "updated" : escape(updated), + "content" : update.content and ('%s' % escape(update.content)) or "", + "updated" : escape(update.updated), } # Write the entry output. diff -r 4967a73df0a5 -r 8c25dd04bf78 macros/SharedContent.py --- a/macros/SharedContent.py Tue May 14 00:53:38 2013 +0200 +++ b/macros/SharedContent.py Tue May 14 01:37:22 2013 +0200 @@ -10,6 +10,7 @@ from MoinMoin.Page import Page from MoinRemoteSupport import * from MoinSupport import parseMacroArguments +from MoinShare import getUpdatesFromPage, Update from email.utils import parsedate import xml.dom.pulldom @@ -55,27 +56,6 @@ class FeedContentTypeError(FeedError): pass -# Entry/update classes. - -class Update: - - "A feed update entry." - - def __init__(self): - self.title = None - self.link = None - self.content = None - self.content_type = None - self.updated = None - - def __cmp__(self, other): - if self.updated is None and other.updated is not None: - return 1 - elif self.updated is not None and other.updated is None: - return -1 - else: - return cmp(self.updated, other.updated) - # Feed retrieval. def getUpdates(request, feed_url, max_entries, show_content): @@ -218,12 +198,15 @@ _ = request.getText feed_urls = [] + pagenames = [] show_content = None max_entries = None for arg, value in parseMacroArguments(args): if arg == "url": feed_urls.append(value) + elif arg == "page": + pagenames.append(value) elif arg == "show": show_content = value.lower() elif arg == "limit": @@ -232,8 +215,8 @@ except ValueError: return fmt.text(_("SharedContent: limit must be set to the maximum number of entries to be shown")) - if not feed_urls: - return fmt.text(_("SharedContent: a feed URL must be specified")) + if not feed_urls and not pagenames: + return fmt.text(_("SharedContent: at least one feed URL or page must be specified")) show_content = show_content or False max_entries = max_entries or MAX_ENTRIES @@ -256,6 +239,23 @@ except FeedContentTypeError: bad_content.append(feed_url) + # Retrieve updates from pages. + + for pagename in pagenames: + page = Page(request, pagename) + updates += getUpdatesFromPage(page, request) + + # Build feed-equivalent information for the update source. + + feeds.append(( + page.url(request), ( + "internal", _("Updates from page %s") % pagename, + page.url(request, {"action" : "SharedUpdates", "doit" : "1"}) + ) + )) + + # Prepare the output. + output = [] append = output.append