<commit_before># -*- coding: utf-8 -*-
import datetime
from itertools import chain
from operator import attrgetter
from django.conf import settings
from django.http import HttpResponse, Http404
from django.shortcuts import render_to_response, get_object_or_404
from django.template import  loader, Context, RequestContext
from django.utils.feedgenerator import rfc3339_date
from fst_web.fs_doc.models import Forfattningssamling, \
     Myndighetsforeskrift, AllmannaRad, Amnesord, AtomEntry, RDFPost


def _response(request, template, context):
    return render_to_response(template,
                              context,
                              context_instance=RequestContext(request))


def index(request):
    """Display start page

    List the latest documents in current document collection.
    Get both 'Myndighetsforeskrift' and 'AllmannaRad'.
    """

    f_list = list(Myndighetsforeskrift.objects.all().order_by(
        "-beslutsdatum")[:10])
    a_list = list(AllmannaRad.objects.all().order_by(
        "-beslutsdatum")[:10])
    latest_documents = sorted(
        chain(f_list, a_list),
        key=attrgetter('beslutsdatum'),
        reverse=True)

    return _response(request, 'index.html', locals())


def fs_dokument_rdf(request, fs_dokument_slug):
    """Display RDF representation of document"""

    rdf_post = get_object_or_404(RDFPost, slug=fs_dokument_slug)
    fs_dokument = rdf_post.content_object
    return HttpResponse(rdf_post.data,
                        mimetype="application/rdf+xml;charset=utf-8")


def fs_dokument(request, fs_dokument_slug):
    """Display document subclassing 'FSDokument' """

    rdf_post= get_object_or_404(RDFPost, slug=fs_dokument_slug)
    fs_dokument = rdf_post.content_object
    if rdf_post.content_type.id == 9:
        return _response(request, 'allmanna_rad.html', dict(doc=fs_dokument))
    elif rdf_post.content_type.id == 10:
        return _response(request, 'foreskrift.html', dict(doc=fs_dokument))
    else:
        pass


def amnesord(request):<commit_msg>Use isinstance on content_object to determine template in document view<commit_after># -*- coding: utf-8 -*-
import datetime
from itertools import chain
from operator import attrgetter
from django.conf import settings
from django.http import HttpResponse, Http404
from django.shortcuts import render_to_response, get_object_or_404
from django.template import  loader, Context, RequestContext
from django.utils.feedgenerator import rfc3339_date
from fst_web.fs_doc.models import Forfattningssamling, \
     Myndighetsforeskrift, AllmannaRad, Amnesord, AtomEntry, RDFPost


def _response(request, template, context):
    return render_to_response(template,
                              context,
                              context_instance=RequestContext(request))


def index(request):
    """Display start page

    List the latest documents in current document collection.
    Get both 'Myndighetsforeskrift' and 'AllmannaRad'.
    """

    f_list = list(Myndighetsforeskrift.objects.all().order_by(
        "-beslutsdatum")[:10])
    a_list = list(AllmannaRad.objects.all().order_by(
        "-beslutsdatum")[:10])
    latest_documents = sorted(
        chain(f_list, a_list),
        key=attrgetter('beslutsdatum'),
        reverse=True)

    return _response(request, 'index.html', locals())


def fs_dokument_rdf(request, fs_dokument_slug):
    """Display RDF representation of document"""

    rdf_post = get_object_or_404(RDFPost, slug=fs_dokument_slug)
    fs_dokument = rdf_post.content_object
    return HttpResponse(rdf_post.data,
                        mimetype="application/rdf+xml;charset=utf-8")


def fs_dokument(request, fs_dokument_slug):
    """Display document subclassing 'FSDokument' """

    rdf_post = get_object_or_404(RDFPost, slug=fs_dokument_slug)
    fs_dokument = rdf_post.content_object
    if isinstance(fs_dokument, AllmannaRad):
        return _response(request, 'allmanna_rad.html', dict(doc=fs_dokument))
    elif isinstance(fs_dokument, Myndighetsforeskrift):
        return _response(request, 'foreskrift.html', dict(doc=fs_dokument))
    else:
        pass


def amnesord(request):
{'fraction_non_alphanumeric': 0.09263258939284857, 'fraction_numerical': 0.011279097672186225, 'mean_word_length': 3.852153667054715, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '81704', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1320, 'n_words': 276}