示例#1
0
    def get_context_data(self, **kwargs):
        context = super(ArticleList, self).get_context_data(**kwargs)
        context['page'] = 'articles_page'

        self.init_articles()
        context.update(self.get_control_panel_context())

        if context.has_key('own_articles'):
            context['own'] = 'articles'
        elif context.has_key('own_drafts'):
            context['own'] = 'drafts'

        paginator = Paginator(list(self.articles), ARTICLES_LIMIT)

        try:
            page_num = int(self.request.GET.get('page', '1'))
        except ValueError:
            page_num = 1
        try:
            current_page = paginator.page(page_num)
        except (EmptyPage, InvalidPage):
            current_page = paginator.page(paginator.num_pages)

        article_list = list(current_page.object_list)
        for article in article_list:
            article.untranslated_langs = ArticleService.get_untranslated_ids(article)
        context["article_list"] = article_list

        if current_page.has_next():
            preview_page = paginator.page(page_num + 1)
            context['next_page'] = page_num + 1
            context['preview_articles'] = list(preview_page.object_list)

        return context