@@ -35,6 +35,12 @@ def _contract_context(contract, **context):
35
35
return context
36
36
37
37
38
+ def render_markdown_from_template (contract , ** context ):
39
+ template = "sponsors/admin/contracts/sponsorship-agreement.md"
40
+ context = _contract_context (contract , ** context )
41
+ return render_to_string (template , context )
42
+
43
+
38
44
def render_contract_to_pdf_response (request , contract , ** context ):
39
45
response = HttpResponse (
40
46
render_contract_to_pdf_file (contract , ** context ), content_type = "application/pdf"
@@ -45,9 +51,9 @@ def render_contract_to_pdf_response(request, contract, **context):
45
51
def render_contract_to_pdf_file (contract , ** context ):
46
52
with tempfile .NamedTemporaryFile () as docx_file :
47
53
with tempfile .NamedTemporaryFile (suffix = ".pdf" ) as pdf_file :
48
- docx_file . write ( render_contract_to_docx_file ( contract , ** context ) )
49
- pdf = pypandoc .convert_file (
50
- docx_file . name , "pdf" , outputfile = pdf_file .name , format = "docx "
54
+ markdown = render_markdown_from_template ( contract , ** context )
55
+ pdf = pypandoc .convert_text (
56
+ markdown , "pdf" , outputfile = pdf_file .name , format = "md "
51
57
)
52
58
return pdf_file .read ()
53
59
@@ -64,10 +70,8 @@ def render_contract_to_docx_response(request, contract, **context):
64
70
65
71
66
72
def render_contract_to_docx_file (contract , ** context ):
67
- template = "sponsors/admin/contracts/sponsorship-agreement.md"
68
73
reference = "sponsors/admin/contracts/reference.docx"
69
- context = _contract_context (contract , ** context )
70
- markdown = render_to_string (template , context )
74
+ markdown = render_markdown_from_template (contract , ** context )
71
75
with tempfile .NamedTemporaryFile () as docx_file :
72
76
docx = pypandoc .convert_text (
73
77
markdown ,
0 commit comments