<commit_before>"""Views used by the feeds application."""


import datetime

from django import template
from django.http import Http404, HttpResponse
from django.conf import settings
from django.utils.feedgenerator import DefaultFeed

from cms.apps.pages.templatetags.pages import html


def index(request):
    """Generates a page of the latest articles."""
    # Get the model information.
    page = request.page
    content = page.content
    article_model = content.article_model
    # Get the list of articles.
    articles = content.get_latest_articles()
    # Generate the context.
    context = {"articles": articles,
               "date": datetime.datetime.now()}
    # Render the template.
    template_names = ("%s/index.html" % article_model._meta.app_label,
                      "feeds/index.html")
    return page.render_to_response(request, template_names, context)
    

def year_archive(request, year):
    """Generates a page showing the articles in a given year."""
    year = int(year)
    # Get the model information.
    page = request.page
    content = page.content
    article_model = content.article_model
    # Get the list of articles.
    articles = content.get_articles().filter(**{"%s__year" % article_model.date_field_name: year})
    # Generate the context.
    context = {"articles": articles,
               "date": datetime.datetime(year, 1, 1)}
    # Render the template.
    template_names = ("%s/year_archive.html" % article_model._meta.app_label,
                      "feeds/year_archive.html")
    return page.render_to_response(request, template_names, context)


def month_archive(request, year, month):
    """Generates a page showing the articles in a given month."""
    year = int(year)
    month = int(month)
    # Get the model information.
    page = request.page
    content = page.content
    article_model = content.article_model
    # Get the list of articles.
    articles = content.get_articles().filter(**{"%s__year" % article_model.date_field_name: year,
                                                "%s__month" % article_model.date_field_name: month})
    # Generate the context.
    context = {"articles": articles,
               "date": datetime.datetime(year, month, 1)}
    # Render the template.
    template_names = ("%s/month_archive.html" % article_model._meta.app_label,
                      "feeds/month_archive.html")
    return page.render_to_response(request, template_names, context)


def article_detail(request, year, month, article_slug):<commit_msg>Empty month and year archives now throw 404.<commit_after>"""Views used by the feeds application."""


import datetime

from django import template
from django.http import Http404, HttpResponse
from django.conf import settings
from django.utils.feedgenerator import DefaultFeed

from cms.apps.pages.templatetags.pages import html


def index(request):
    """Generates a page of the latest articles."""
    # Get the model information.
    page = request.page
    content = page.content
    article_model = content.article_model
    # Get the list of articles.
    articles = content.get_latest_articles()
    # Generate the context.
    context = {"articles": articles,
               "date": datetime.datetime.now()}
    # Render the template.
    template_names = ("%s/index.html" % article_model._meta.app_label,
                      "feeds/index.html")
    return page.render_to_response(request, template_names, context)
    

def year_archive(request, year):
    """Generates a page showing the articles in a given year."""
    year = int(year)
    # Get the model information.
    page = request.page
    content = page.content
    article_model = content.article_model
    # Get the list of articles.
    articles = content.get_articles().filter(**{"%s__year" % article_model.date_field_name: year})
    if articles.count() == 0:
        raise Http404, "There are no articles to display."
    # Generate the context.
    context = {"articles": articles,
               "date": datetime.datetime(year, 1, 1)}
    # Render the template.
    template_names = ("%s/year_archive.html" % article_model._meta.app_label,
                      "feeds/year_archive.html")
    return page.render_to_response(request, template_names, context)


def month_archive(request, year, month):
    """Generates a page showing the articles in a given month."""
    year = int(year)
    month = int(month)
    # Get the model information.
    page = request.page
    content = page.content
    article_model = content.article_model
    # Get the list of articles.
    articles = content.get_articles().filter(**{"%s__year" % article_model.date_field_name: year,
                                                "%s__month" % article_model.date_field_name: month})
    if articles.count() == 0:
        raise Http404, "There are no articles to display."
    # Generate the context.
    context = {"articles": articles,
               "date": datetime.datetime(year, month, 1)}
    # Render the template.
    template_names = ("%s/month_archive.html" % article_model._meta.app_label,
                      "feeds/month_archive.html")
    return page.render_to_response(request, template_names, context)


def article_detail(request, year, month, article_slug):
{'fraction_non_alphanumeric': 0.102821435334217, 'fraction_numerical': 0.0043552357508047715, 'mean_word_length': 2.9984859954579863, 'pattern_counts': {'":': 12, '<': 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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5367014', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1443, 'n_words': 418}