<commit_before>from django.contrib.auth.decorators import permission_required
from django.shortcuts import redirect, render, get_object_or_404

from wagtail.wagtailcore.models import Page

from ..models import get_invoiceindex_content_types
from ..forms import SearchForm
from django.utils import timezone
from datetime import timedelta


@permission_required('wagtailadmin.access_admin')  # further permissions are enforced within the view
def choose(request):
    invoiceindex_list = Page.objects.filter(content_type__in=get_invoiceindex_content_types())
    invoiceindex_count = invoiceindex_list.count()
    if invoiceindex_count == 1:
        invoiceindex = invoiceindex_list.first()
        return redirect('wagtailinvoices_index', pk=invoiceindex.pk)

    return render(request, 'wagtailinvoices/choose.html', {
        'has_invoice': invoiceindex_count != 0,
        'invoiceindex_list': ((invoiceindex, invoiceindex.content_type.model_class()._meta.verbose_name)
                           for invoiceindex in invoiceindex_list)
    })


@permission_required('wagtailadmin.access_admin')  # further permissions are enforced within the view
def index(request, pk):
    invoiceindex = get_object_or_404(Page, pk=pk, content_type__in=get_invoiceindex_content_types()).specific
    Invoice = invoiceindex.get_invoice_model()
    invoice_list = Invoice.objects.filter(invoiceindex=invoiceindex)
    #invoice = Invoice.objects.all()
    invoice = get_object_or_404(Invoice, invoiceindex=invoiceindex, pk=pk)
    form = SearchForm()

    return render(request, 'wagtailinvoices/index.html', {
        'invoiceindex': invoiceindex,
        'invoice_list': invoice_list,
        'form': form,
    })

@permission_required('wagtailadmin.access_admin')  # further permissions are enforced within the view
def search(request, pk):
    invoiceindex = get_object_or_404(Page, pk=pk, content_type__in=get_invoiceindex_content_types()).specific
    Invoice = invoiceindex.get_invoice_model()
    invoice_list = Invoice.objects.filter(invoiceindex=invoiceindex)
    form = SearchForm(request.GET or None)
    if form.is_valid():
        query = form.cleaned_data['query']
        invoice_list = invoice_list.search(query)

    else:
        invoice_list = invoice_list.none()

    return render(request, 'wagtailinvoices/search.html', {<commit_msg>Restored invoice index page in chooser.py<commit_after>from django.contrib.auth.decorators import permission_required
from django.shortcuts import redirect, render, get_object_or_404

from wagtail.wagtailcore.models import Page

from ..models import get_invoiceindex_content_types
from ..forms import SearchForm
from django.utils import timezone
from datetime import timedelta


@permission_required('wagtailadmin.access_admin')  # further permissions are enforced within the view
def choose(request):
    invoiceindex_list = Page.objects.filter(content_type__in=get_invoiceindex_content_types())
    invoiceindex_count = invoiceindex_list.count()
    if invoiceindex_count == 1:
        invoiceindex = invoiceindex_list.first()
        return redirect('wagtailinvoices_index', pk=invoiceindex.pk)

    return render(request, 'wagtailinvoices/choose.html', {
        'has_invoice': invoiceindex_count != 0,
        'invoiceindex_list': ((invoiceindex, invoiceindex.content_type.model_class()._meta.verbose_name)
                           for invoiceindex in invoiceindex_list)
    })


@permission_required('wagtailadmin.access_admin')  # further permissions are enforced within the view
def index(request, pk):
    invoiceindex = get_object_or_404(Page, pk=pk, content_type__in=get_invoiceindex_content_types()).specific
    Invoice = invoiceindex.get_invoice_model()
    invoice_list = Invoice.objects.filter(invoiceindex=invoiceindex)
    form = SearchForm()

    return render(request, 'wagtailinvoices/index.html', {
        'invoiceindex': invoiceindex,
        'invoice_list': invoice_list,
        'form': form,
    })

@permission_required('wagtailadmin.access_admin')  # further permissions are enforced within the view
def search(request, pk):
    invoiceindex = get_object_or_404(Page, pk=pk, content_type__in=get_invoiceindex_content_types()).specific
    Invoice = invoiceindex.get_invoice_model()
    invoice_list = Invoice.objects.filter(invoiceindex=invoiceindex)
    form = SearchForm(request.GET or None)
    if form.is_valid():
        query = form.cleaned_data['query']
        invoice_list = invoice_list.search(query)

    else:
        invoice_list = invoice_list.none()

    return render(request, 'wagtailinvoices/search.html', {
{'fraction_non_alphanumeric': 0.09007832898172324, 'fraction_numerical': 0.005439512619669277, 'mean_word_length': 4.739076154806492, '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': '5648629', 'n_tokens_mistral': 1437, 'n_tokens_neox': 1361, 'n_words': 271}