def document(request, abbr, session, bill_id, doc_id):
<EOL>fixed_bill_id = fix_bill_id(bill_id)<EOL>if fixed_bill_id.replace('<STR_LIT:U+0020>', '<STR_LIT>') != bill_id:<EOL><INDENT>return redirect('<STR_LIT>', abbr=abbr, session=session,<EOL>bill_id=fixed_bill_id.replace('<STR_LIT:U+0020>', '<STR_LIT>'), doc_id=doc_id)<EOL><DEDENT>bill = db.bills.find_one({settings.LEVEL_FIELD: abbr, '<STR_LIT>': session,<EOL>'<STR_LIT>': fixed_bill_id})<EOL>if not bill:<EOL><INDENT>raise Http404('<STR_LIT>')<EOL><DEDENT>for version in bill['<STR_LIT>']:<EOL><INDENT>if version['<STR_LIT>'] == doc_id:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise Http404('<STR_LIT>')<EOL><DEDENT>if not settings.ENABLE_DOCUMENT_VIEW.get(abbr, False):<EOL><INDENT>return redirect(version['<STR_LIT:url>'])<EOL><DEDENT>return render(request, templatename('<STR_LIT>'),<EOL>dict(abbr=abbr, session=session, bill=bill, version=version,<EOL>metadata=bill.metadata, nav_active='<STR_LIT>'))<EOL>
Context:
    - abbr
    - session
    - bill
    - version
    - metadata
    - nav_active

Templates:
    - billy/web/public/document.html