def make_sendlog_record(self, **kw): """Create a new sendlog record """ user = get_user() actor = get_user_id() userprops = api.get_user_properties(user) actor_fullname = userprops.get("fullname", actor) email_send_date = DateTime() email_recipients = self.email_recipients email_responsibles = self.email_responsibles email_subject = self.email_subject email_body = self.render_email_template(self.email_body) email_attachments = map(api.get_uid, self.attachments) record = { "actor": actor, "actor_fullname": actor_fullname, "email_send_date": email_send_date, "email_recipients": email_recipients, "email_responsibles": email_responsibles, "email_subject": email_subject, "email_body": email_body, "email_attachments": email_attachments, } # keywords take precedence record.update(kw) return record
def get_object_metadata(obj, **kw): """Get object metadata :param obj: Content object :returns: Dictionary of extracted object metadata """ # inject metadata of volatile data metadata = { "actor": get_user_id(), "roles": get_roles(), "action": "", "review_state": api.get_review_status(obj), "active": api.is_active(obj), "snapshot_created": DateTime().ISO(), "modified": api.get_modification_date(obj).ISO(), "remote_address": "", "user_agent": "", "referer": "", "comments": "", } # Update request data metadata.update(get_request_data()) # allow metadata overrides metadata.update(kw) return metadata
def guard_submit(analysis): """Return whether the transition "submit" can be performed or not """ # Cannot submit without a result if not analysis.getResult(): return False # Cannot submit with interims without value for interim in analysis.getInterimFields(): if not interim.get("value", ""): return False # Cannot submit if attachment not set, but is required if not analysis.getAttachment(): if analysis.getAttachmentOption() == 'r': return False # Check if can submit based on the Analysis Request state if IRequestAnalysis.providedBy(analysis): point_of_capture = analysis.getPointOfCapture() # Cannot submit if the Sample has not been received if point_of_capture == "lab" and not analysis.isSampleReceived(): return False # Cannot submit if the Sample has not been sampled if point_of_capture == "field" and not analysis.isSampleSampled(): return False # Check if the current user can submit if is not assigned if not analysis.bika_setup.getAllowToSubmitNotAssigned(): if not user_has_super_roles(): # Cannot submit if unassigned analyst = analysis.getAnalyst() if not analyst: return False # Cannot submit if assigned analyst is not the current user if analyst != security.get_user_id(): return False # Cannot submit unless all dependencies are submitted or can be submitted for dependency in analysis.getDependencies(): if not is_submitted_or_submittable(dependency): return False return True