<commit_before>from datetime import datetime
from django.core import serializers
from django.core.mail import EmailMultiAlternatives
from django.core.urlresolvers import reverse
from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.template.loader import render_to_string
from django.views.generic import (
    ArchiveIndexView,
    YearArchiveView,
    MonthArchiveView,
    DetailView
)
from tinyblog.forms import EmailSubscriptionForm, EmailSubscriber
from tinyblog.models import Post
from tinyblog.utils import get_from_email, get_site_name


def post(request, year, month, slug):
    post = get_object_or_404(Post, created__year=year, created__month=month,
                             slug=slug)

    if post.created > datetime.now():
        if not request.user.is_staff:
            raise Http404

    return render_to_response('tinyblog/post.html',
                              {'post': post},
                              context_instance=RequestContext(request))


class TinyBlogIndexView(ArchiveIndexView):
    date_field = 'created'

    def get_queryset(self):
        return Post.published_objects.all()


class TinyBlogYearView(YearArchiveView):
    date_field = 'created'
    make_object_list = True

    def get_queryset(self):
        return Post.published_objects.all()


class TinyBlogMonthView(MonthArchiveView):
    date_field = 'created'
    month_format = '%m'

    def get_queryset(self):
        return Post.published_objects.all()


def jsonify(request):
    data = serializers.serialize("json", Post.published_objects.all())
    return HttpResponse(data)


def subscribe(request):
    if request.method == 'GET':
        form = EmailSubscriptionForm()
        return render_to_response('tinyblog/subscribe.html',
                                  {'form': form},
                                  context_instance=RequestContext(request))
    else:
        form = EmailSubscriptionForm(request.POST)

        if form.is_valid():
            model = form.save()
            request.session['tinyblog_thanks_uuid'] = model.uuid_first

            site = get_site_name()

            subject = 'Thanks for subscribing to {0}'.format(site)

            text_template = 'tinyblog/emails/confirm_subscription.txt'
            text_content = render_to_string(text_template,
                                            {'user': model, 'site': site})
<commit_msg>Fix for Django 1.6, which uses a different JSON implementation<commit_after>from datetime import datetime
from django.core import serializers
from django.core.mail import EmailMultiAlternatives
from django.core.urlresolvers import reverse
from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.template.loader import render_to_string
from django.views.generic import (
    ArchiveIndexView,
    YearArchiveView,
    MonthArchiveView,
    DetailView
)
from tinyblog.forms import EmailSubscriptionForm, EmailSubscriber
from tinyblog.models import Post
from tinyblog.utils import get_from_email, get_site_name


def post(request, year, month, slug):
    post = get_object_or_404(Post, created__year=year, created__month=month,
                             slug=slug)

    if post.created > datetime.now():
        if not request.user.is_staff:
            raise Http404

    return render_to_response('tinyblog/post.html',
                              {'post': post},
                              context_instance=RequestContext(request))


class TinyBlogIndexView(ArchiveIndexView):
    date_field = 'created'

    def get_queryset(self):
        return Post.published_objects.all()


class TinyBlogYearView(YearArchiveView):
    date_field = 'created'
    make_object_list = True

    def get_queryset(self):
        return Post.published_objects.all()


class TinyBlogMonthView(MonthArchiveView):
    date_field = 'created'
    month_format = '%m'

    def get_queryset(self):
        return Post.published_objects.all()


def jsonify(request):
    data = serializers.serialize("json", Post.published_objects.all())
    return HttpResponse(data)


def subscribe(request):
    if request.method == 'GET':
        form = EmailSubscriptionForm()
        return render_to_response('tinyblog/subscribe.html',
                                  {'form': form},
                                  context_instance=RequestContext(request))
    else:
        form = EmailSubscriptionForm(request.POST)

        if form.is_valid():
            model = form.save()
            request.session['tinyblog_thanks_uuid'] = str(model.uuid_first)

            site = get_site_name()

            subject = 'Thanks for subscribing to {0}'.format(site)

            text_template = 'tinyblog/emails/confirm_subscription.txt'
            text_content = render_to_string(text_template,
                                            {'user': model, 'site': site})

{'fraction_non_alphanumeric': 0.08163265306122448, 'fraction_numerical': 0.005494505494505495, 'mean_word_length': 2.8409947249434815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6155195', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1327, 'n_words': 311}