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

from django.shortcuts import render
from django.views import generic
from django.views.decorators.cache import cache_page


def handler500(request):
    """Renders a pretty error page."""
    response = render(request, "500.html", {})
    response.status_code = 500
    return response


class TextTemplateView(generic.TemplateView):

    """A template view that returns a text/plain response."""

    content_type = "text/plain; charset=utf-8"

    def render_to_response(self, context, **kwargs):
        """Dispatches the request."""
        kwargs.setdefault("content_type", self.content_type)
        return super(TextTemplateView, self).render_to_response(context, **kwargs)


class SearchMetaDetailMixin(object):

    """Generates the context for an search meta detail page."""

    def get_context_data(self, **kwargs):
        """Adds in the additional search meta context data."""
        context = super(SearchMetaDetailMixin, self).get_context_data(**kwargs)
        defaults = self.object.get_context_data()
        defaults.update(context)
        return defaults


class PageDetailMixin(SearchMetaDetailMixin):

    """Generates the context for a page detail view."""


class SearchMetaDetailView(SearchMetaDetailMixin, generic.DetailView):

    """A simple entity detail view."""


class PageDetailView(PageDetailMixin, generic.DetailView):

    """A simple page detail view."""


class CacheMixin(object):
    cache_timeout = 60

    def get_cache_timeout(self):
        return self.cache_timeout

    def dispatch(self, *args, **kwargs):
        return cache_page(self.get_cache_timeout())(super(CacheMixin, self).dispatch)(*args, **kwargs)
<commit_msg>Disable full page caching for logged-in users. (#131)<commit_after>"""Views used by the CMS."""

from django.shortcuts import render
from django.views import generic
from django.views.decorators.cache import cache_page


def handler500(request):
    """Renders a pretty error page."""
    response = render(request, "500.html", {})
    response.status_code = 500
    return response


class TextTemplateView(generic.TemplateView):

    """A template view that returns a text/plain response."""

    content_type = "text/plain; charset=utf-8"

    def render_to_response(self, context, **kwargs):
        """Dispatches the request."""
        kwargs.setdefault("content_type", self.content_type)
        return super(TextTemplateView, self).render_to_response(context, **kwargs)


class SearchMetaDetailMixin(object):

    """Generates the context for an search meta detail page."""

    def get_context_data(self, **kwargs):
        """Adds in the additional search meta context data."""
        context = super(SearchMetaDetailMixin, self).get_context_data(**kwargs)
        defaults = self.object.get_context_data()
        defaults.update(context)
        return defaults


class PageDetailMixin(SearchMetaDetailMixin):

    """Generates the context for a page detail view."""


class SearchMetaDetailView(SearchMetaDetailMixin, generic.DetailView):

    """A simple entity detail view."""


class PageDetailView(PageDetailMixin, generic.DetailView):

    """A simple page detail view."""


class CacheMixin(object):
    cache_timeout = 60

    def get_cache_timeout(self):
        return self.cache_timeout

    def dispatch(self, *args, **kwargs):
        if hasattr(self.request, 'user') and self.request.user.is_authenticated():
            return super(CacheMixin, self).dispatch(*args, **kwargs)

        return cache_page(self.get_cache_timeout())(super(CacheMixin, self).dispatch)(*args, **kwargs)

{'fraction_non_alphanumeric': 0.11393103448275863, 'fraction_numerical': 0.0074482758620689656, 'mean_word_length': 4.09985935302391, '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': '6289139', 'n_tokens_mistral': 1040, 'n_tokens_neox': 974, 'n_words': 274}