def pre_install(portal_setup): """Runs before the first import step of the *default* profile This handler is registered as a *pre_handler* in the generic setup profile :param portal_setup: SetupTool """ logger.info("{} pre-install handler [BEGIN]".format(PRODUCT_NAME.upper())) context = portal_setup._getImportContext(PROFILE_ID) portal = context.getSite() # noqa # # Only install senaite.lims once! # qi = portal.portal_quickinstaller # if not qi.isProductInstalled("senaite.lims"): # portal_setup.runAllImportStepsFromProfile("profile-senaite.lims:default") logger.info("{} pre-install handler [DONE]".format(PRODUCT_NAME.upper()))
def post_install(portal_setup): """Runs after the last import step of the *default* profile This handler is registered as a *post_handler* in the generic setup profile :param portal_setup: SetupTool """ logger.info("{} post-install handler [BEGIN]".format(PRODUCT_NAME.upper())) context = portal_setup._getImportContext(PROFILE_ID) portal = context.getSite() # noqa # update bika_setup_catalog pc = getToolByName(portal, 'bika_setup_catalog') if 'getSupplier' not in pc.indexes(): logger.info( "{} post-install handler: add getSupplier to portal catalog". format(PRODUCT_NAME.upper())) pc.addIndex('getSupplier', 'FieldIndex') pc.addColumn('getSupplier') pc.manage_reindexIndex('getSupplier') logger.info("{} post-install handler [DONE]".format(PRODUCT_NAME.upper()))
def __init__(self, collection, request): logger.info("MultiReportView::__init__:collection={}" .format(collection)) super(MultiReportView, self).__init__(collection, request) self.collection = collection self.request = request
def ajax_save_reports(self): """Render all reports as PDFs and store them as AR Reports """ # Data sent via async ajax call as JSON data from the frontend data = self.get_json() # This is the html after it was rendered by the client browser and # eventually extended by JavaScript, e.g. Barcodes or Graphs added etc. # NOTE: It might also contain multiple reports! html = data.get("html") # get the triggered action (Save|Email) action = data.get("action", "save") # get the selected template template = data.get("template") # get the selected paperformat paperformat = data.get("format") # get the selected orientation orientation = data.get("orientation", "portrait") # Generate the print CSS with the set format/orientation css = self.get_print_css(paperformat=paperformat, orientation=orientation) logger.info(u"Print CSS: {}".format(css)) # get the publisher instance publisher = self.publisher # add the generated CSS to the publisher publisher.add_inline_css(css) # split the html per report # NOTE: each report is an instance of <bs4.Tag> html_reports = publisher.parse_reports(html) # generate a PDF for each HTML report pdf_reports = map(publisher.write_pdf, html_reports) # extract the UIDs of each HTML report # NOTE: UIDs are injected in `.analysisrequest.reportview.render` report_uids = map(lambda report: report.get("uids", "").split(","), html_reports) # generate a CSV for each report_uids samples = [] for sample in data['items']: sample = getAdapter(sample, ISuperModel) samples.append(sample) csv_reports = [] is_multi_template = self.is_multi_template(template) if is_multi_template: csv_report = self.create_csv_reports(samples) csv_reports = [csv_report for i in range(len(pdf_reports))] else: for sample_csv in samples: csv_report = self.create_csv_report(sample_csv) csv_reports.append(csv_report) # prepare some metadata metadata = { "template": template, "paperformat": paperformat, "orientation": orientation, "timestamp": DateTime().ISO8601(), } # Create PDFs and HTML # get the storage multi-adapter to save the generated PDFs storage = getMultiAdapter((self.context, self.request), IPdfReportStorage) report_groups = [] for pdf, html, csv_text, uids in zip(pdf_reports, html_reports, csv_reports, report_uids): # ensure we have valid UIDs here uids = filter(api.is_uid, uids) # convert the bs4.Tag back to pure HTML html = publisher.to_html(html) # BBB: inject contained UIDs into metadata metadata["contained_requests"] = uids # store the report(s) objs = storage.store(pdf, html, uids, metadata=metadata, csv_text=csv_text) # append the generated reports to the list report_groups.append(objs) # Fixed LIMS-3288 - send one email with multiple attache report_groups = [[a[0] for a in report_groups]] # NOTE: The reports might be stored in multiple places (clients), # which makes it difficult to redirect to a single exit URL # based on the action the users clicked (save/email) exit_urls = map( lambda reports: self.get_exit_url_for(reports, action=action), report_groups) if not exit_urls: return api.get_url(self.context) return exit_urls[0]