@@ -769,15 +769,18 @@ def document_html(request, name, rev=None):
769769 return redirect ('ietf.doc.views_doc.document_html' , name = found .matched_name )
770770
771771 doc = found .documents .get ()
772- if not os .path .exists (doc .get_file_name ()):
773- raise Http404 ("File not found: %s" % doc .get_file_name ())
772+
774773
775774 if found .matched_rev or found .matched_name .startswith ('rfc' ):
776775 rev = found .matched_rev
777776 else :
778777 rev = doc .rev
779778 if rev :
780779 doc = doc .history_set .filter (rev = rev ).first () or doc .fake_history_obj (rev )
780+
781+ if not os .path .exists (doc .get_file_name ()):
782+ raise Http404 ("File not found: %s" % doc .get_file_name ())
783+
781784 if doc .type_id in ['draft' ,]:
782785 doc .supermeta = build_doc_supermeta_block (doc )
783786 doc .meta = build_doc_meta_block (doc , settings .HTMLIZER_URL_PREFIX )
@@ -803,6 +806,36 @@ def document_html(request, name, rev=None):
803806
804807 return render (request , "doc/document_html.html" , {"doc" :doc , "doccolor" :doccolor })
805808
809+ def document_pdfized (request , name , rev = None , ext = None ):
810+
811+ found = fuzzy_find_documents (name , rev )
812+ num_found = found .documents .count ()
813+ if num_found == 0 :
814+ raise Http404 ("Document not found: %s" % name )
815+ if num_found > 1 :
816+ raise Http404 ("Multiple documents matched: %s" % name )
817+
818+ if found .matched_name .startswith ('rfc' ) and name != found .matched_name :
819+ return redirect ('ietf.doc.views_doc.document_pdfized' , name = found .matched_name )
820+
821+ doc = found .documents .get ()
822+
823+ if found .matched_rev or found .matched_name .startswith ('rfc' ):
824+ rev = found .matched_rev
825+ else :
826+ rev = doc .rev
827+ if rev :
828+ doc = doc .history_set .filter (rev = rev ).first () or doc .fake_history_obj (rev )
829+
830+ if not os .path .exists (doc .get_file_name ()):
831+ raise Http404 ("File not found: %s" % doc .get_file_name ())
832+
833+ pdf = doc .pdfized ()
834+ if pdf :
835+ return HttpResponse (pdf ,content_type = 'application/pdf;charset=utf-8' )
836+ else :
837+ raise Http404
838+
806839def check_doc_email_aliases ():
807840 pattern = re .compile (r'^expand-(.*?)(\..*?)?@.*? +(.*)$' )
808841 good_count = 0
0 commit comments