1.1 --- a/MoinShare.py Tue May 14 00:53:38 2013 +0200
1.2 +++ b/MoinShare.py Tue May 14 01:37:22 2013 +0200
1.3 @@ -100,14 +100,39 @@
1.4
1.5 return getWikiDict(sources_page, request)
1.6
1.7 -def getUpdateFragmentsFromPage(page, request):
1.8 +# Entry/update classes.
1.9 +
1.10 +class Update:
1.11 +
1.12 + "A feed update entry."
1.13 +
1.14 + def __init__(self):
1.15 + self.title = None
1.16 + self.link = None
1.17 + self.content = None
1.18 + self.content_type = None
1.19 + self.updated = None
1.20 +
1.21 + # Page-related attributes.
1.22 +
1.23 + self.fragment = None
1.24 + self.preferred = None
1.25 +
1.26 + def __cmp__(self, other):
1.27 + if self.updated is None and other.updated is not None:
1.28 + return 1
1.29 + elif self.updated is not None and other.updated is None:
1.30 + return -1
1.31 + else:
1.32 + return cmp(self.updated, other.updated)
1.33 +
1.34 +# Update retrieval from pages.
1.35 +
1.36 +def getUpdatesFromPage(page, request):
1.37
1.38 """
1.39 - Get update fragments from the given 'page' using the 'request'. A list of
1.40 - update descriptions is returned, each being a tuple of the form...
1.41 -
1.42 - (fragment identifer, summary text, preferred mimetypes, textual content,
1.43 - updated datetime)
1.44 + Get updates from the given 'page' using the 'request'. A list of update
1.45 + objects is returned.
1.46 """
1.47
1.48 updates = []
1.49 @@ -126,34 +151,41 @@
1.50 # Produce a fragment identifier.
1.51 # NOTE: Choose a more robust identifier where none is explicitly given.
1.52
1.53 - fragment = attributes.get("fragment", str(n))
1.54 - summary = attributes.get("summary", "Update #%d" % n)
1.55 + update = Update()
1.56 +
1.57 + update.fragment = attributes.get("fragment", str(n))
1.58 + update.title = attributes.get("summary", "Update #%d" % n)
1.59
1.60 # Get the preferred content types available for the fragment.
1.61
1.62 - preferred = getPreferredOutputTypes(request, getOutputTypes(request, format))
1.63 + update.preferred = getPreferredOutputTypes(request, getOutputTypes(request, format))
1.64
1.65 # Try and obtain some suitable content for the entry.
1.66 # NOTE: Could potentially get a summary for the fragment.
1.67
1.68 - content = None
1.69 + update.content = None
1.70
1.71 - if "text/html" in preferred:
1.72 + if "text/html" in update.preferred:
1.73 parser_cls = getParserClass(request, format)
1.74 parser = parser_cls(body, request)
1.75
1.76 if format == "html":
1.77 - content = body
1.78 + update.content = body
1.79 elif hasattr(parser, "formatForOutputType"):
1.80 s = StringIO()
1.81 parser.formatForOutputType("text/html", write=s.write)
1.82 - content = s.getvalue()
1.83 + update.content = s.getvalue()
1.84 else:
1.85 fmt = request.html_formatter
1.86 fmt.setPage(page)
1.87 - content = formatText(body, request, fmt, parser_cls)
1.88 + update.content = formatText(body, request, fmt, parser_cls)
1.89 +
1.90 + update.content_type = "html"
1.91
1.92 - updates.append((fragment, summary, preferred, content, updated))
1.93 + update.link = page.url(request)
1.94 + update.updated = updated
1.95 +
1.96 + updates.append(update)
1.97
1.98 return updates
1.99