def get_exported_pdf_file_id(cls, tallySheetId, tallySheetVersionId): tallySheet = TallySheet.get_by_id(tallySheetId=tallySheetId) tallySheetVersion = cls.get_by_id(tallySheetId, tallySheetVersionId) if tallySheetVersion.exportedPdfFileId is None: tally_sheet_version_pdf_content = html_to_pdf(html=str( tallySheet.html(tallySheetVersionId=tallySheetVersionId))) tally_sheet_version_pdf_file = File.create( fileMimeType="application/pdf", fileContentLength=len(tally_sheet_version_pdf_content), fileContentType="application/pdf", fileContent=tally_sheet_version_pdf_content, fileName="%d-%d" % (tallySheetId, tallySheetVersionId)) tallySheetVersion.exportedPdfFileId = tally_sheet_version_pdf_file.fileId db.session.add(tallySheetVersion) db.session.flush() return tallySheetVersion.exportedPdfFileId
def get_exported_letter_pdf_file_id(cls, tallySheetId, tallySheetVersionId, signatures): tallySheet = TallySheet.get_by_id(tallySheetId=tallySheetId) tallySheetVersion = cls.get_by_id(tallySheetId, tallySheetVersionId) # Disable persistence check since the addition of signatures creates different letters. # if tallySheetVersion.exportedLetterPdfFileId is None: tally_sheet_version_letter_pdf_content = html_to_pdf(html=str( tallySheet.html_letter(tallySheetVersionId=tallySheetVersionId, signatures=signatures))) tally_sheet_version_letter_pdf_file = File.create( fileMimeType="application/pdf", fileContentLength=len(tally_sheet_version_letter_pdf_content), fileContentType="application/pdf", fileContent=tally_sheet_version_letter_pdf_content, fileName="%d-%d" % (tallySheetId, tallySheetVersionId)) tallySheetVersion.exportedLetterPdfFileId = tally_sheet_version_letter_pdf_file.fileId db.session.add(tallySheetVersion) db.session.flush() return tallySheetVersion.exportedLetterPdfFileId
def create(fileSource): return File.create(fileSource=fileSource, fileType=FileTypeEnum.Image)