<commit_before>import datetime
import logging

from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.db.models import Count
from django.http import Http404
from django.shortcuts import redirect
from django.urls import reverse
from django.views.generic import TemplateView
from django.views.generic.base import RedirectView


from dal import autocomplete

from person.models import Person

from document.models import Agenda
from document.models import AgendaItem
from document.models import BesluitenLijst
from document.models import Document, Kamerstuk
from document.models import Dossier
from document.models import Submitter
from document.models import Voting
from document.models import VoteParty
from document.filters import DossierFilter
from document.filters import VotingFilter
from document import settings


# TODO: remove dependency on website
from website.create import create_or_update_dossier

logger = logging.getLogger(__name__)


class DocumentView(TemplateView):
    template_name = 'document/document.html'

    def get_context_data(self, document_id, **kwargs):
        context = super().get_context_data(**kwargs)
        context['document'] = Document.objects.get(document_id=document_id)
        return context


class KamerstukView(TemplateView):
    template_name = 'document/kamerstuk.html'

    def get_context_data(self, dossier_id, sub_id, **kwargs):
        context = super().get_context_data(**kwargs)
        context['kamerstuk'] = Kamerstuk.objects.get(id_main=dossier_id, id_sub=sub_id)
        return context


class KamerstukRedirectView(RedirectView):
    def get_redirect_url(self, dossier_id, sub_id):
        sub_id = sub_id.lstrip('0')  # remove leading zeros
        return reverse('kamerstuk', args=(dossier_id, sub_id), current_app='document')


class PersonAutocomplete(autocomplete.Select2QuerySetView):
    def get_queryset(self):
        persons = Person.objects.exclude(surname='').order_by('surname')
        person_ids = []
        if self.q:
            for person in persons:
                if self.q.lower() in person.fullname().lower():
                    person_ids.append(person.id)
            return Person.objects.filter(pk__in=person_ids)<commit_msg>return 404 in case the requested document does not exist<commit_after>import datetime
import logging

from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.db.models import Count
from django.http import Http404
from django.shortcuts import redirect
from django.urls import reverse
from django.views.generic import TemplateView
from django.views.generic.base import RedirectView


from dal import autocomplete

from person.models import Person

from document.models import Agenda
from document.models import AgendaItem
from document.models import BesluitenLijst
from document.models import Document, Kamerstuk
from document.models import Dossier
from document.models import Submitter
from document.models import Voting
from document.models import VoteParty
from document.filters import DossierFilter
from document.filters import VotingFilter
from document import settings


# TODO: remove dependency on website
from website.create import create_or_update_dossier

logger = logging.getLogger(__name__)


class DocumentView(TemplateView):
    template_name = 'document/document.html'

    def get_context_data(self, document_id, **kwargs):
        context = super().get_context_data(**kwargs)
        documents = Document.objects.filter(document_id=document_id)
        if not documents:
            raise Http404
        context['document'] = documents[0]
        return context


class KamerstukView(TemplateView):
    template_name = 'document/kamerstuk.html'

    def get_context_data(self, dossier_id, sub_id, **kwargs):
        context = super().get_context_data(**kwargs)
        context['kamerstuk'] = Kamerstuk.objects.get(id_main=dossier_id, id_sub=sub_id)
        return context


class KamerstukRedirectView(RedirectView):
    def get_redirect_url(self, dossier_id, sub_id):
        sub_id = sub_id.lstrip('0')  # remove leading zeros
        return reverse('kamerstuk', args=(dossier_id, sub_id), current_app='document')


class PersonAutocomplete(autocomplete.Select2QuerySetView):
    def get_queryset(self):
        persons = Person.objects.exclude(surname='').order_by('surname')
        person_ids = []
        if self.q:
            for person in persons:
                if self.q.lower() in person.fullname().lower():
                    person_ids.append(person.id)
            return Person.objects.filter(pk__in=person_ids)
{'fraction_non_alphanumeric': 0.07837194197878329, 'fraction_numerical': 0.0036804503139207623, 'mean_word_length': 4.261958997722096, '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': '608893', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1257, 'n_words': 343}