def populate_data(self, appstruct): """ Convenience function to fill the data has with the values from the POST'ed form. """ local = EmptyReport() local.serial = appstruct["serial"] local.slugged = slugify(appstruct["serial"]) local.filename = "reports/%s/report.pdf" % local.slugged local.coefficient_0 = appstruct["coefficient_0"] local.coefficient_1 = appstruct["coefficient_1"] local.coefficient_2 = appstruct["coefficient_2"] local.coefficient_3 = appstruct["coefficient_3"] # Images are optional, set to placeholder if not specified if appstruct["top_image_upload"] == colander.null: local.top_image_filename = "resources/image0_defined.jpg" else: local.top_image_filename = "reports/%s/top_image.png" \ % local.slugged if appstruct["bottom_image_upload"] == colander.null: local.bottom_image_filename = "resources/image1_defined.jpg" else: local.bottom_image_filename = "reports/%s/bottom_image.png" \ % local.slugged return local
def generate_calibration_report(self, appstruct, checkout_id): """ Use the generator object from the calibration report module to create a single page pdf. """ report = EmptyReport() report.serial = appstruct["serial"] report.coefficient_0 = appstruct["coefficient_0"] report.coefficient_1 = appstruct["coefficient_1"] report.coefficient_2 = appstruct["coefficient_2"] report.coefficient_3 = appstruct["coefficient_3"] pdf = WasatchSinglePage(report=report, return_blob=True) blob_data = pdf.return_blob() log.info("PDF report blob: %s", len(blob_data)) new_file = File(filename="Calibration_Report.pdf", file_data=blob_data) dbqry = DBSession.query(Checkout) checkout = dbqry.filter(Checkout.id == checkout_id).one() checkout.files.append(new_file) blob_data = pdf.return_thumbnail_blob() self.cache_blob(blob_data, checkout_id, "calibration_report_thumbnail.png") log.info("thumbnail report blob: %s", len(blob_data)) new_file = File(filename="calibration_report_thumbnail.png", file_data=blob_data) dbqry = DBSession.query(Checkout) checkout = dbqry.filter(Checkout.id == checkout_id).one() checkout.files.append(new_file)