def get_index(self, user, head): restype = get_restype(self.request) if restype == 'default': pages = WikiPage.get_index(user) page_group = groupby(pages, lambda p: title_grouper(p.title)) html = template(self.request, 'wiki_sp_index.html', {'page_group': page_group}) self.response.headers['Content-Type'] = 'text/html; charset=utf-8' set_response_body(self.response, html, head) elif restype == 'atom': pages = WikiPage.get_index(None) config = WikiPage.get_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' set_response_body(self.response, feed.to_string(), head) else: self.abort(400, 'Unknown type: %s' % restype)
def get_changes(self, user, head): restype = get_restype(self.request) rendered = None if restype == 'default': if rendered is None: pages = WikiPage.get_changes(user) rendered = template(self.request, 'wiki_sp_changes.html', {'pages': pages}) self.response.headers['Content-Type'] = 'text/html; charset=utf-8' set_response_body(self.response, rendered, head) elif restype == 'atom': if rendered is None: pages = WikiPage.get_changes(None, 3, include_body=True) config = WikiPage.get_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' set_response_body(self.response, rendered, head) else: self.abort(400, 'Unknown type: %s' % restype)
def template(req, path, data): config = WikiPage.get_config() t = loader.get_template('wiki/%s' % path) c = RequestContext(req, data) c['config'] = config c['is_local'] = req.META.get('HTTP_HOST', '').startswith('localhost') c['app'] = {'version': wiki_settings.VERSION} return t.render(c)
def test_empty_config_page(self): config_page = WikiPage.get_by_title('.config') config_page.update_content('', 1, user=self.get_cur_user()) config = WikiPage.get_config() perm = config['service']['default_permissions'] self.assertEqual(perm['read'], ['all']) self.assertEqual(perm['write'], ['login'])
def test_empty_config_page(self): config_page = WikiPage.get_by_title(u'.config') config_page.update_content('', 1) config = WikiPage.get_config() perm = config['service']['default_permissions'] self.assertEqual(perm['read'], ['all']) self.assertEqual(perm['write'], ['login'])
def template(req, path, data): config = WikiPage.get_config() user = get_cur_user() data['is_local'] = req.host_url.startswith('http://localhost') data['is_mobile'] = is_mobile(req) data['user'] = user data['preferences'] = UserPreferences.get_by_user(user) if user is not None else None data['users'] = users data['cur_url'] = req.url data['config'] = config data['app'] = {'version': main.VERSION} return JINJA.get_template('templates/%s' % path).render(data)
def template(req, path, data): config = WikiPage.get_config() user = get_cur_user() data['is_local'] = req.host_url.startswith('http://localhost') data['is_mobile'] = is_mobile(req) data['user'] = user data['preferences'] = UserPreferences.get_by_user( user) if user is not None else None data['users'] = users data['cur_url'] = req.url data['config'] = config data['app'] = {'version': main.VERSION} return JINJA.get_template('templates/%s' % path).render(data)
def render_atom(req, title, path, pages, include_content=False, use_published_date=False): config = WikiPage.get_config() host = req.get_host() title = '%s: %s' % (config['service']['title'], title) url = "%s/%s?_type=atom" % (host, path) feed = AtomFeed(title=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 if include_content else ""), author=page.modifier, url='%s%s' % (host, page.absolute_url), updated=(page.published_at if use_published_date else page.updated_at)) return feed.to_string()
def test_invalid_config_page(self): self.config_page.update_content(u''' admin: email: [email protected] service: default_permissions_with_typo: read: [whatthe write: [what] ''', 1, user=self.get_cur_user()) config = WikiPage.get_config() self.assertEqual( {'read': ['all'], 'write': ['login']}, config['service']['default_permissions'] )
def test_invalid_config_page(self): self.config_page.update_content(u''' admin: email: [email protected] service: default_permissions_with_typo: read: [whatthe write: [what] ''', 1, user=self.get_cur_user()) config = WikiPage.get_config() self.assertEqual({ 'read': ['all'], 'write': ['login'] }, config['service']['default_permissions'])
def render_posts_atom(req, title, pages): host = req.host_url config = WikiPage.get_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 render_atom(req, title, path, pages, include_content=False, use_published_date=False): config = WikiPage.get_config() host = req.host_url title = '%s: %s' % (config['service']['title'], title) url = "%s/%s?_type=atom" % (host, path) feed = AtomFeed(title=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 if include_content else ""), author=page.modifier, url='%s%s' % (host, page.absolute_url), updated=(page.published_at if use_published_date else page.updated_at)) return feed.to_string()
def test_updates_partial_configurations(self): config = WikiPage.get_config() self.assertEqual(config['service']['title'], '')
def test_update_by_dot_config_page(self): config = WikiPage.get_config() self.assertEqual(config['admin']['email'], '*****@*****.**')
def test_empty_page(self): self.assertEqual(main.DEFAULT_CONFIG, WikiPage.get_config())
def has_supported_language(hashbangs): config = WikiPage.get_config() return any(x in config['highlight']['supported_languages'] for x in hashbangs)
def test_update_by_dot_config_page(self): config = WikiPage.get_config() self.assertEqual('*****@*****.**', config['admin']['email'])
def test_updates_partial_configurations(self): config = WikiPage.get_config() self.assertEqual('', config['service']['title'])
def has_supported_language(hashbangs): langs = WikiPage.get_config()['highlight']['supported_languages'] return any(lang in langs for lang in hashbangs)