def get_sp_index(self, user, head): restype = self._get_restype() if restype == 'default': pages = WikiPage.get_index(user) page_group = groupby(pages, lambda p: title_grouper(p.title)) html = self._template('wiki_sp_index.html', {'page_group': page_group}) self.response.headers['Content-Type'] = 'text/html; charset=utf-8' self._set_response_body(html, head) elif restype == 'atom': pages = WikiPage.get_index(None) config = WikiPage.yaml_by_title('.config') host = self.request.host_url url = "%s/sp.index?_type=atom" % host feed = AtomFeed(title="%s: title index" % config['service']['title'], feed_url=url, url="%s/" % host, author=config['admin']['email']) for page in pages: feed.add(title=page.title, content_type="html", author=page.modifier, url='%s%s' % (host, page.absolute_url), updated=page.updated_at) self.response.headers['Content-Type'] = 'text/xml; charset=utf-8' self._set_response_body(feed.to_string(), head) else: self.abort(400, 'Unknown type: %s' % restype)
def get_sp_index(self, user, head): restype = self._get_restype() if restype == "default": pages = WikiPage.get_index(user) page_group = groupby(pages, lambda p: title_grouper(p.title)) html = self._template("wiki_sp_index.html", {"page_group": page_group}) self.response.headers["Content-Type"] = "text/html; charset=utf-8" self._set_response_body(html, head) elif restype == "atom": pages = WikiPage.get_index(None) config = WikiPage.yaml_by_title(".config") host = self.request.host_url url = "%s/sp.index?_type=atom" % host feed = AtomFeed( title="%s: title index" % config["service"]["title"], feed_url=url, url="%s/" % host, author=config["admin"]["email"], ) for page in pages: feed.add( title=page.title, content_type="html", author=page.modifier, url="%s%s" % (host, page.absolute_url), updated=page.updated_at, ) self.response.headers["Content-Type"] = "text/xml; charset=utf-8" self._set_response_body(feed.to_string(), head) else: self.abort(400, "Unknown type: %s" % restype)
def get_sp_changes(self, user, head): restype = self._get_restype() email = user.email() if user is not None else 'None' rendered = None if restype == 'default': if rendered is None: pages = WikiPage.get_changes(user) rendered = self._template('wiki_sp_changes.html', {'pages': pages}) self.response.headers['Content-Type'] = 'text/html; charset=utf-8' self._set_response_body(rendered, head) elif restype == 'atom': if rendered is None: pages = WikiPage.get_changes(None, 3, include_body=True) config = WikiPage.yaml_by_title('.config') host = self.request.host_url url = "%s/sp.changes?_type=atom" % host feed = AtomFeed(title="%s: changes" % config['service']['title'], feed_url=url, url="%s/" % host, author=config['admin']['email']) for page in pages: feed.add(title=page.title, content_type="html", content=page.rendered_body, author=page.modifier, url='%s%s' % (host, page.absolute_url), updated=page.updated_at) rendered = feed.to_string() self.response.headers['Content-Type'] = 'text/xml; charset=utf-8' self._set_response_body(rendered, head) else: self.abort(400, 'Unknown type: %s' % restype)
def _template(self, path, data): t = JINJA.get_template("templates/%s" % path) config = WikiPage.yaml_by_title(".config") data["is_local"] = self.request.host_url.startswith("http://localhost") data["is_mobile"] = self._is_mobile() data["user"] = WikiPageHandler._get_cur_user() data["users"] = users data["cur_url"] = self.request.url data["config"] = config data["app"] = {"version": main.VERSION} return t.render(data)
def _template(self, path, data): t = JINJA.get_template('templates/%s' % path) config = WikiPage.yaml_by_title('.config') data['is_local'] = self.request.host_url.startswith('http://localhost') data['is_mobile'] = self._is_mobile() data['user'] = WikiPageHandler._get_cur_user() data['users'] = users data['cur_url'] = self.request.url data['config'] = config data['app'] = { 'version': main.VERSION, } return t.render(data)
def _render_posts_atom(self, title, pages): host = self.request.host_url config = WikiPage.yaml_by_title(".config") if title is None: feed_title = "%s: posts" % config["service"]["title"] url = "%s/sp.posts?_type=atom" % host else: feed_title = title url = "%s/%s?_type=atom" % (WikiPage.title_to_path(title), host) feed = AtomFeed(title=feed_title, feed_url=url, url="%s/" % host, author=config["admin"]["email"]) for page in pages: feed.add( title=page.title, content_type="html", content=page.rendered_body, author=page.modifier, url="%s%s" % (host, page.absolute_url), updated=page.published_at, ) return feed.to_string()
def get_sp_changes(self, user, head): restype = self._get_restype() email = user.email() if user is not None else "None" rendered = None if restype == "default": if rendered is None: pages = WikiPage.get_changes(user) rendered = self._template("wiki_sp_changes.html", {"pages": pages}) self.response.headers["Content-Type"] = "text/html; charset=utf-8" self._set_response_body(rendered, head) elif restype == "atom": if rendered is None: pages = WikiPage.get_changes(None, 3, include_body=True) config = WikiPage.yaml_by_title(".config") host = self.request.host_url url = "%s/sp.changes?_type=atom" % host feed = AtomFeed( title="%s: changes" % config["service"]["title"], feed_url=url, url="%s/" % host, author=config["admin"]["email"], ) for page in pages: feed.add( title=page.title, content_type="html", content=page.rendered_body, author=page.modifier, url="%s%s" % (host, page.absolute_url), updated=page.updated_at, ) rendered = feed.to_string() self.response.headers["Content-Type"] = "text/xml; charset=utf-8" self._set_response_body(rendered, head) else: self.abort(400, "Unknown type: %s" % restype)
def test_empty_page(self): self.assertEqual(main.DEFAULT_CONFIG, WikiPage.yaml_by_title('Test'))