1.1 --- a/macros/SharedContent.py Tue May 14 01:37:22 2013 +0200
1.2 +++ b/macros/SharedContent.py Tue May 14 17:16:56 2013 +0200
1.3 @@ -10,7 +10,7 @@
1.4 from MoinMoin.Page import Page
1.5 from MoinRemoteSupport import *
1.6 from MoinSupport import parseMacroArguments
1.7 -from MoinShare import getUpdatesFromPage, Update
1.8 +from MoinShare import getUpdateSources, getUpdatesFromPage, Update
1.9 from email.utils import parsedate
1.10 import xml.dom.pulldom
1.11
1.12 @@ -197,16 +197,13 @@
1.13 fmt = macro.formatter
1.14 _ = request.getText
1.15
1.16 - feed_urls = []
1.17 - pagenames = []
1.18 + source_pages = []
1.19 show_content = None
1.20 max_entries = None
1.21
1.22 for arg, value in parseMacroArguments(args):
1.23 - if arg == "url":
1.24 - feed_urls.append(value)
1.25 - elif arg == "page":
1.26 - pagenames.append(value)
1.27 + if arg == "sources":
1.28 + source_pages.append(value)
1.29 elif arg == "show":
1.30 show_content = value.lower()
1.31 elif arg == "limit":
1.32 @@ -215,44 +212,67 @@
1.33 except ValueError:
1.34 return fmt.text(_("SharedContent: limit must be set to the maximum number of entries to be shown"))
1.35
1.36 - if not feed_urls and not pagenames:
1.37 - return fmt.text(_("SharedContent: at least one feed URL or page must be specified"))
1.38 + if not source_pages:
1.39 + return fmt.text(_("SharedContent: at least one sources page must be specified"))
1.40 +
1.41 + sources = {}
1.42 +
1.43 + for source_page in source_pages:
1.44 + sources.update(getUpdateSources(source_page, request))
1.45 +
1.46 + if not sources:
1.47 + return fmt.text(_("SharedContent: at least one update source must be specified"))
1.48
1.49 show_content = show_content or False
1.50 max_entries = max_entries or MAX_ENTRIES
1.51
1.52 - # Retrieve updates from feeds, classifying them as missing or bad and
1.53 - # excluding them if appropriate.
1.54 + # Retrieve updates, classifying them as missing or bad and excluding them if
1.55 + # appropriate.
1.56
1.57 updates = []
1.58 feeds = []
1.59 + unspecified = []
1.60 missing = []
1.61 bad_content = []
1.62
1.63 - for feed_url in feed_urls:
1.64 + for source_name, source_parameters in sources.items():
1.65 + location = source_parameters.get("location")
1.66 + if not location:
1.67 + unspecified.append(source_name)
1.68 + continue
1.69 +
1.70 + show_feed_content = source_parameters.get("show", show_content)
1.71 try:
1.72 - feed_info, feed_updates = getUpdates(request, feed_url, max_entries, show_content)
1.73 - updates += feed_updates
1.74 - feeds.append((feed_url, feed_info))
1.75 - except FeedMissingError:
1.76 - missing.append(feed_url)
1.77 - except FeedContentTypeError:
1.78 - bad_content.append(feed_url)
1.79 + max_entries_for_feed = int(source_parameters["limit"])
1.80 + except (KeyError, ValueError):
1.81 + max_entries_for_feed = None
1.82
1.83 - # Retrieve updates from pages.
1.84 + # Retrieve updates from feeds.
1.85
1.86 - for pagename in pagenames:
1.87 - page = Page(request, pagename)
1.88 - updates += getUpdatesFromPage(page, request)
1.89 + if source_parameters.get("type") == "url":
1.90 + try:
1.91 + feed_info, feed_updates = getUpdates(request, location, max_entries_for_feed, show_feed_content)
1.92 + updates += feed_updates
1.93 + feeds.append((location, feed_info))
1.94 + except FeedMissingError:
1.95 + missing.append(location)
1.96 + except FeedContentTypeError:
1.97 + bad_content.append(location)
1.98
1.99 - # Build feed-equivalent information for the update source.
1.100 + # Retrieve updates from pages.
1.101
1.102 - feeds.append((
1.103 - page.url(request), (
1.104 - "internal", _("Updates from page %s") % pagename,
1.105 - page.url(request, {"action" : "SharedUpdates", "doit" : "1"})
1.106 - )
1.107 - ))
1.108 + elif source_parameters.get("type") == "page":
1.109 + page = Page(request, location)
1.110 + updates += getUpdatesFromPage(page, request)
1.111 +
1.112 + # Build feed-equivalent information for the update source.
1.113 +
1.114 + feeds.append((
1.115 + page.url(request, {"action" : "SharedUpdates", "doit" : "1"}), (
1.116 + "internal", _("Updates from page %s") % location,
1.117 + page.url(request)
1.118 + )
1.119 + ))
1.120
1.121 # Prepare the output.
1.122