from django.shortcuts import get_object_or_404, render
from costs.models import Document


def public_document_detail(request, pk=None):
    if pk is None:
        doc = Document.objects.order_by('-date').first()
    else:
        doc = get_object_or_404(Document, pk=pk)

    docs = Document.objects\
                   .filter(type=Document.TYPE_FACT)\
                   .order_by('-date')

    return render(request, 'publicsite/public_document_detail.html', {
        'document': doc,
        'documents': docs,
    })
