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 test_fully_valid_report(self): from calibrationreport.models import EmptyReport from calibrationreport.pdfgenerator import WasatchSinglePage filename = "with_images_check.pdf" self.assertFalse(touch_erase(filename)) img0 = "resources/image0_defined.jpg" img1 = "resources/image1_defined.jpg" report = EmptyReport() report.serial = "DEFINEDSERIAL01234" report.coeff_0 = "1000.1213123*e-06" report.coeff_1 = "1001.1213123*e-06" report.coeff_2 = "1002.1213123*e-06" report.coeff_3 = "1003.1213123*e-06" report.top_image_filename = img0 report.bottom_image_filename = img1 pdf = WasatchSinglePage(filename=filename, report=report) self.assertTrue(file_range(filename, 106494))