def get_client_uid(self): instance = self.context.aq_parent while not IPloneSiteRoot.providedBy(instance): if IClient.providedBy(instance): return instance.UID() if IBatch.providedBy(instance): client = instance.getClient() if client: return client.UID()
def isVisible(self, field, mode="view", default="visible"): if mode == "add": container = self.context.aq_parent # Do not display the doctor field if the Sample is being created # inside a Batch and the latter has a Doctor assigned. In such # case, the batch assigned to the Batch will be used: # See: adapters.addsample.DoctorDefaultFieldValue if IBatch.providedBy(container): doctor = container.getField("Doctor").get(container) if doctor: return "hidden" return default
def __call__(self, context, mode, field, default): state = default if default else 'hidden' fieldName = field.getName() if fieldName != 'Client': return state parent = self.context.aq_parent if IBatch.providedBy(parent): if parent.getClient(): return 'hidden' if IClient.providedBy(parent): return 'hidden' return state
def isVisible(self, field, mode="view", default="visible"): if IBatch.providedBy(self.context.aq_parent): return "hidden" if mode == "edit": client = api.get_current_client() if client: # If current user is a client contact and the batch this Sample # is assigned to does not have a client assigned (e.g., the # batch was assigned by lab personnel), hide this field batch = self.context.getBatch() if batch and batch.getClient() != client: return "invisible" return default
def isVisible(self, field, mode="view", default="visible"): if mode == "edit": return "invisible" elif mode == "add": container = self.context.aq_parent # Do not display the Patient field if the Sample is being created # inside a Batch and the latter has a Patient assigned. In such # case, the patient assigned to the Batch will be used: # See: adapters.addsample.PatientDefaultFieldValue if IBatch.providedBy(container): patient = container.getField("Patient").get(container) if patient: return "hidden" return default
def isVisible(self, field, mode="view", default="visible"): if mode == "add": parent = self.context.aq_parent if IClient.providedBy(parent): # Note we return "hidden" here instead of "invisible": we want # the field to be auto-filled and processed on submit return "hidden" if IBatch.providedBy(parent) and parent.getClient(): # The Batch has a Client assigned already! # Note we can have Batches without a client assigned return "hidden" elif mode == "edit": # This is already managed by wf permission, but is **never** a good # idea to allow the user to change the Client from an AR (basically # because otherwise, we'd need to move the object from one client # folder to another!). return "invisible" return default
def handle_after_submit(context, request, state): """Handles actions provided in extra_buttons slot from edit forms """ status_id = "created" if request.get("form.button.new_sample"): # Redirect to Sample Add from Patient next_url = api.get_url(context) if IPatient.providedBy(context): uid = context.UID() client = context.getPrimaryReferrer() folder = client or api.get_portal().analysisrequests folder_url = api.get_url(folder) ar_count = get_default_num_samples() next_url = "{}/ar_add?Patient={}&ar_count={}".format( folder_url, uid, ar_count) # Redirect to Sample Add form from Batch elif IBatch.providedBy(context): ar_count = get_default_num_samples() next_url = "{}/ar_add?ar_count={}".format(next_url, ar_count) state.setNextAction('redirect_to:string:{}'.format(next_url)) elif request.get("form.button.new_batch"): # Redirect to New Batch from Patient next_url = api.get_url(context) if IPatient.providedBy(context): # Create temporary Batch inside Patient context (the case will be # moved in client's folder later thanks to objectmodified event) next_url = "{}/createObject?type_name=Batch".format(next_url) #tmp_path = "portal_factory/Batch/{}".format(tmpID()) #tmp_obj = context.restrictedTraverse(tmp_path) #batch_url = api.get_url(tmp_obj) #next_url = "{}/edit".format(batch_url) state.setNextAction('redirect_to:string:{}'.format(next_url)) elif IPatient.providedBy(context): # Redirect to Patient's samples view next_url = "{}/analysisrequests".format(api.get_url(context)) state.setNextAction('redirect_to:string:{}'.format(next_url)) else: status_id = "success" return status_id
def isVisible(self, field, mode="view", default="visible"): if IBatch.providedBy(self.context.aq_parent): return "hidden" return default
def __call__(self, context): if IBatch.providedBy(context): return context # Try with batch explicitly defined in request return self.get_object_from_request_field("Batch")