def revisions_feed(request=None, pagename=None, feedtype="atom"): if pagename is None: pagename ='Home' page = get_page(request.site._id, pagename) if not page: raise NotFound all_revisions = [page] + page.revisions() if feedtype == "atom": feed = AtomFeed( title="%s: Latest revisions of %s" % (request.site.cname, page.title), subtitle=request.site.subtitle, updated = page.updated, feed_url = request.url ) for rev in all_revisions: title = '' _url="%s%s" % (request.host_url, url_for("revision_page", pagename=pagename, nb_revision=rev.nb_revision )) for change in rev.changes: if change['type'] != "unmod": title = "\n".join(change['changed']['lines']) title = do_truncate(do_striptags(title), 60) title = title and title or "Edited." feed.add(title, convert_markdown(rev.content), updated=rev.updated, url=_url, id=_url, author=rev.title.replace(' ', '_') ) return feed.get_response() else: json = { 'title': "%s: Latest revisions of %s" % (request.site.cname, page.title), 'subtitle': request.site.subtitle, 'updated':datetime_tojson(page.updated), 'feed_url': request.url, 'revisions': [] } for rev in all_revisions: title = '' for change in rev.changes: if change['type'] != "unmod": title = "\n".join(change['changed']['lines']) title = do_truncate(do_striptags(title), 60) title = title and title or "Edited." url = "%s%s" % (request.host_url, url_for("revision_page", cname=request.site.cname, pagename=pagename, nb_revision=rev.nb_revision )) json['revisions'].append({ 'title': title, 'content': rev.content, 'url': url, 'updated':datetime_tojson(rev.updated), 'id':rev.nb_revision }) return send_json(json)
def site_changes(request, feedtype=None): pages = all_pages(request.site._id) changes = get_changes(request.site._id) if feedtype == "atom": feed = AtomFeed( title="%s: Latest changes" % request.site.title and request.site.title or request.site.cname, subtitle=request.site.subtitle, updated = changes[0].updated, feed_url = request.url ) for rev in changes: _url = "%s%s" % (request.host_url, url_for("show_page", pagename=rev.title.replace(' ', '_'))) feed.add(rev.title, convert_markdown(rev.content), updated=rev.updated, url=_url, id=_url, author=rev.title.replace(' ', '_') ) return feed.get_response() elif feedtype == 'json': json = { 'title': "%s: Latest changes" % request.site.title and request.site.title or request.site.cname, 'subtitle': request.site.subtitle, 'updated':datetime_tojson(changes[0].updated), 'feed_url': request.url, 'pages': [] } for rev in changes: url = "%s%s" % (request.host_url, url_for("show_page", pagename=rev.title.replace(' ', '_'))) json['pages'].append({ 'title': rev.title, 'content': rev.content, 'url': url, 'updated':datetime_tojson(rev.updated), 'id':rev.title.replace(' ', '_') }) return send_json(json) elif feedtype == 'rdf': site_title = request.site.title and request.site.title or request.site.cname site_url = request.host_url if not local.site_url: site_url += local.site_url sioc = SiocWiki(site_url, site_title, datetime_tojson(request.site.created)) for rev in changes: _url = "%s%s" % (request.host_url, url_for("show_page", pagename=rev.title.replace(' ', '_'))) sioc.add_page(rev.content, rev.title, _url, datetime_tojson(rev.updated)) return send_sioc(sioc.to_str()) return render_response('site/changes.html', changes=changes, pages=pages)