Esempio n. 1
0
    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)
Esempio n. 2
0
    def dispatch_request(self, category=None, year=None, month=None, day=None,
                         slug=None, flav=None):
        datefield = current_app.config['YAWT_ARCHIVE_DATEFIELD']
        ainfos, _ = search_page(_query(category, year, month, day),
                                datefield,
                                g.page, g.pagelen,
                                True)
        article = None
        for info in ainfos:
            if info.slug == slug:
                article = g.site.fetch_article(info.fullname)

        return render(self.get_template_name(), category, slug,
                      flav, {'article': article, 'is_permalink': True})
Esempio n. 3
0
    def test_search_page_returns_page_results_and_total(self):
        ix = _create_index()
        writer = ix.writer()
        article = _article('cooking/indian/madras',
                           [u'spicy', u'curry'],
                           'this is an awesome article')
        doc = _field_values(article)
        writer.add_document(**doc)

        article = _article('reading/scifi/clarke',
                           [u'monolith', u'alien'],
                           'this is a crappy article')
        doc = _field_values(article)
        writer.add_document(**doc)
        writer.commit()

        articles, total = search_page('', None, page=1, pagelen=1)
        self.assertEquals(1, len(articles))
        self.assertEquals(2, total)