<commit_before>"""Views used by the CMS news app."""

from django.views import generic
from django.views.generic.list import BaseListView
from django.shortcuts import get_object_or_404
from django.utils.feedgenerator import DefaultFeed
from django.http import HttpResponse

from cms.views import PageDetailMixin
from cms.apps.news.models import Article, Category
from cms.html import process as process_html


class ArticleListMixin(object):
    
    """Base class for every view that handles articles."""
    
    model = Article
    
    make_object_list = True
    
    date_field = "date"
    
    allow_future = True  # The publication manager will take care of this.
    
    allow_empty = True
    
    context_object_name = "article_list"
    
    def get_paginate_by(self, queryset):
        """Returns the number of articles to show per page."""
        return self.request.pages.current.content.per_page
    
    def get_context_data(self, **kwargs):
        """Returns the context data for the view."""
        context = super(ArticleListMixin, self).get_context_data(**kwargs)
        category_list = Category.objects.filter(
            article__news_feed__page = self.request.pages.current,
        ).distinct()
        context["category_list"] = category_list
        return context
    
    def get_queryset(self):
        """Returns the article queryset."""
        return super(ArticleListMixin, self).get_queryset().prefetch_related(
            "categories",
            "authors",
        ).select_related("image").filter(
            news_feed__page = self.request.pages.current,
        ).order_by("-date")


class ArticleArchiveView(ArticleListMixin, generic.ArchiveIndexView):
    
    pass<commit_msg>404 errors thrown on article list pages that aren't the main listing when there are no articles.<commit_after>"""Views used by the CMS news app."""

from django.views import generic
from django.views.generic.list import BaseListView
from django.shortcuts import get_object_or_404
from django.utils.feedgenerator import DefaultFeed
from django.http import HttpResponse

from cms.views import PageDetailMixin
from cms.apps.news.models import Article, Category
from cms.html import process as process_html


class ArticleListMixin(object):
    
    """Base class for every view that handles articles."""
    
    model = Article
    
    make_object_list = True
    
    date_field = "date"
    
    allow_future = True  # The publication manager will take care of this.
    
    context_object_name = "article_list"
    
    def get_paginate_by(self, queryset):
        """Returns the number of articles to show per page."""
        return self.request.pages.current.content.per_page
    
    def get_context_data(self, **kwargs):
        """Returns the context data for the view."""
        context = super(ArticleListMixin, self).get_context_data(**kwargs)
        category_list = Category.objects.filter(
            article__news_feed__page = self.request.pages.current,
        ).distinct()
        context["category_list"] = category_list
        return context
    
    def get_queryset(self):
        """Returns the article queryset."""
        return super(ArticleListMixin, self).get_queryset().prefetch_related(
            "categories",
            "authors",
        ).select_related("image").filter(
            news_feed__page = self.request.pages.current,
        ).order_by("-date")


class ArticleArchiveView(ArticleListMixin, generic.ArchiveIndexView):
    
    allow_empty = True
{'fraction_non_alphanumeric': 0.08624113475177304, 'fraction_numerical': 0.002553191489361702, 'mean_word_length': 3.071593533487298, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2330556', 'n_tokens_mistral': 964, 'n_tokens_neox': 940, 'n_words': 268}