RFCartography/rfcartography/details.py
2023-01-03 14:42:54 +01:00

44 lines
1.9 KiB
Python

from flask import Blueprint, render_template, current_app, abort
from rfcartography.index_parser import Document, NotIssued, DocType, Month
details: Blueprint = Blueprint('details', __name__)
@details.route('/RFC<int:num>', methods=['GET'])
def show_rfc(num: int) -> tuple[str, int]:
"""handle requests for the details page for RFCs"""
rfc: Document = current_app.cartographer.get_document(DocType.RFC, num)
if rfc is None:
abort(404)
elif isinstance(rfc, NotIssued):
content: dict = {'title': rfc.docID(),
'content': [('Not Issued', 'This RFC number was retained as a place holder, but never issued.')]}
return render_template('generic.html', **content), 200
else:
url: str = "http://" + current_app.config['SERVER_NAME']
if url[-1] != '/':
url = url + '/'
if rfc.pub_date is not None:
date: str = f"{Month(rfc.pub_date.month).name} {rfc.pub_date.year}"
else:
date: str = ""
context: dict = {'rfc': rfc,
'url': url,
'date': date}
return render_template('rfc.html', **context), 200
@details.route('/STD<int:num>', methods=['GET'], defaults={'doctype': DocType.STD})
@details.route('/BCP<int:num>', methods=['GET'], defaults={'doctype': DocType.BCP})
@details.route('/FYI<int:num>', methods=['GET'], defaults={'doctype': DocType.FYI})
def show_details(num: int, doctype: DocType) -> tuple[str, int]:
"""handle requests for the details page for STDs, BCPs and FYIs"""
doc: Document = current_app.cartographer.get_document(doctype, num)
if doc is None:
abort(404)
url: str = "http://" + current_app.config['SERVER_NAME']
if url[-1] != '/':
url = url + '/'
context: dict = {'doc': doc,
'url': url}
return render_template('details.html', **context), 200