def dispatch_request(self, category='', flav=None, *args, **kwargs): """Query whoosh for collection of articles. Sort the articles. Setup up pagination variables in the g variables. Finally render the template, or abort with a 404 if you don't find a template. """ ainfos, total = [], 0 if is_loaded('yawtext.indexer.YawtIndexer'): query = self.query(category, *args, **kwargs) sortfield = current_app.config['YAWT_COLLECTIONS_SORT_FIELD'] ainfos, total = search_page(query=query, sortedby=sortfield, page=g.page, pagelen=g.pagelen, reverse=True) g.total_results = total g.total_pages = int(ceil(float(g.total_results)/g.pagelen)) g.has_prev_page = g.page > 1 g.has_next_page = g.page < g.total_pages g.prev_page = g.page - 1 g.next_page = g.page + 1 articles = [] for ainfo in ainfos: if self.is_load_articles(flav): article = g.site.fetch_article_by_info(ainfo) else: article = Article() article.info = ainfo articles.append(article) try: return render(self.get_template_name(), category, 'index', flav, {'articles': articles}) except TemplatesNotFound: abort(404)
def _article(fullname, tags, content): info = ArticleInfo() info.fullname = fullname info.tags = tags article = Article() article.info = info article.content = content return article
def test_plugin_processes_content_of_markdown_articles(self): with self.app.test_request_context(): self.app.preprocess_request() info = ArticleInfo() info.extension = 'md' article = Article() article.info = info article.content = '*stuff*' article = self.plugin.on_article_fetch(article) self.assertEqual('<p><em>stuff</em></p>', article.content)
def test_plugin_skips_non_markdown_articles(self): with self.app.test_request_context(): self.app.preprocess_request() info = ArticleInfo() info.extension = 'html' article = Article() article.info = info article.content = '*stuff*' article = self.plugin.on_article_fetch(article) self.assertEqual('*stuff*', article.content)
def test_html_summary_attribute_set_correctly(self): with self.app.test_request_context(): self.app.preprocess_request() info = ArticleInfo() info.extension = 'md' article = Article() article.info = info article.content = '<p>stuff</p><p>blah hello</p><p>dude the</p><p>east market</p>' self.app.config['YAWT_EXCERPT_WORDCOUNT'] = 5 article = self.plugin.on_article_fetch(article) self.assertEqual(Markup('<p>stuff</p><p>blah hello</p><p>dude the</p>'), article.info.summary)
def test_text_summary_attribute_set_correctly(self): with self.app.test_request_context(): self.app.preprocess_request() info = ArticleInfo() info.extension = 'md' article = Article() article.info = info article.content = 'stuff blah hello dude the east market' self.app.config['YAWT_EXCERPT_WORDCOUNT'] = 5 article = self.plugin.on_article_fetch(article) self.assertEqual('stuff blah hello dude the [...]', article.info.summary)