I am currently trying to print financial reports with my web app - this needs to happen by the click of a button. When I click the button, however, the app only prints 1 document (the first one) I don't understand what this could be as there are 2 different returns for each if statement that re-direct to 2 different .HTML pages
This is what I have tried at the moment:
import tempfile
def printReports(request , reports_pk):
pkForm = get_object_or_404(SettingsClass , pk=reports_pk)
complexName = pkForm.Complex
if pkForm.Trial_balance_Year_To_Date == True:
### Printing Trial Balance PDF
response = HttpResponse(content_type= 'application/pdf')
response['Content-Disposition']= 'attachment; filename=TrialBalance' + \
str(datetime.now()) + '.pdf'
response['Content-Transfer-Encoding'] = 'binary'
content = {"x_AlltrbYTD":x_AlltrbYTD , 'xCreditTotal':xCreditTotal , 'xDebitTotal':xDebitTotal , 'complexName':complexName , 'openingBalances': openingBalances ,'printZero':printZero , 'printDesc':printDesc , 'printAcc':printAcc}
html_string=render_to_string('main/reports/trialBalanceYear.html' , content)
html=HTML(string=html_string)
result=html.write_pdf()
with tempfile.NamedTemporaryFile(delete=True) as output:
output.write(result)
output.flush()
output.seek(0)
response.write(output.read())
return response
if pkForm.Trial_balance_Monthly == True:
### Printing Trial Balance PDF
response = HttpResponse(content_type= 'application/pdf')
response['Content-Disposition']= 'attachment; filename=TrialBalanceMonthly' + \
str(datetime.now()) + '.pdf'
response['Content-Transfer-Encoding'] = 'binary'
content = {"xtrbMonth":xtrbMonth , 'xCreditTotalM':xCreditTotalM , 'xDebitTotalM':xDebitTotalM , 'complexName':complexName , 'printZeroM':printZeroM}
html_string=render_to_string('main/reports/trialBalanceMonthly.html' , content)
html=HTML(string=html_string)
result=html.write_pdf()
with tempfile.NamedTemporaryFile(delete=True) as output:
output.write(result)
output.flush()
output.seek(0)
response.write(output.read())
else:
printTrialBalanceMonth = False
The program only prints what the first if-statement shows and doesn't print the second .pdf document. Does anyone know what might be causing this?
from Generating Multiple Documents (Python TempFile Module)
No comments:
Post a Comment