def getClientInChargeAtSamplingTime(self): """ Returns info from the Client contact who is in charge at sampling time """ pc = getToolByName(api.portal.get(), 'portal_catalog') contentFilter = { 'portal_type': 'Contact', 'id': self.client_contact_in_charge_at_sampling_time } cnt = pc(contentFilter) cntdict = {'uid': '', 'id': '', 'fullname': '', 'url': ''} if len(cnt) == 1: cnt = cnt[0].getObject() cntdict = { 'uid': cnt.id, 'id': cnt.UID(), 'fullname': cnt.getFullname(), 'url': cnt.absolute_url(), } else: from bika.lims import logger error = "Error when looking for contact with id '%s'. " logger.exception(error, self.client_contact_in_charge_at_sampling_time) return cntdict
def is_UIDReferenceField(portal_type, fieldname): uc = get_tool('uid_catalog') brains = uc(portal_type=portal_type) if not brains: return False field = brains[0].getObject().getField(fieldname) if not field: logger.exception("Field not found: %s/%s" % (portal_type, fieldname)) return None if field.type == 'uidreference': return True
def get_service_by_keyword(self, keyword, default=None): """Get a service by keyword """ logger.info("Get service by keyword={}".format(keyword)) bsc = api.get_tool("bika_setup_catalog") results = bsc(portal_type='AnalysisService', getKeyword=keyword) if not results: logger.exception("No Analysis Service found for Keyword '{}'. " "Related: LIMS-1614".format(keyword)) return default elif len(results) > 1: logger.exception( "More than one Analysis Service found for Keyword '{}'. ". format(keyword)) return default else: return api.get_object(results[0])
def get_service_by_keyword(self, keyword, default=None): """Get a service by keyword """ logger.info("Get service by keyword={}".format(keyword)) bsc = api.get_tool("bika_setup_catalog") results = bsc(portal_type='AnalysisService', getKeyword=keyword) if not results: logger.exception("No Analysis Service found for Keyword '{}'. " "Related: LIMS-1614".format(keyword)) return default elif len(results) > 1: logger.exception("More than one Analysis Service found for Keyword '{}'. " .format(keyword)) return default else: return api.get_object(results[0])
def getResultsRange(self): """Return the AR Specs sorted by Service UID, so that the JS can work easily with the values. """ bsc = self.bika_setup_catalog rr_dict_by_service_uid = {} rr = self.context.getResultsRange() for r in rr: keyword = r['keyword'] try: service_uid = bsc(portal_type='AnalysisService', getKeyword=keyword)[0].UID rr_dict_by_service_uid[service_uid] = r except IndexError: from bika.lims import logger error = "No Analysis Service found for Keyword '%s'. " \ "Related: LIMS-1614" logger.exception(error, keyword) return json.dumps(rr_dict_by_service_uid)
def getResultsRange(self): """Return the AR Specs sorted by Service UID, so that the JS can work easily with the values. """ bsc = self.bika_setup_catalog rr_dict_by_service_uid = {} rr = self.context.getResultsRange() for r in rr: keyword = r['keyword'] try: service_uid = bsc(portal_type='AnalysisService', getKeyword=keyword)[0].UID rr_dict_by_service_uid[service_uid] = r except IndexError: from bika.lims import logger error = "No Analysis Service found for Keyword '%s'. "\ "Related: LIMS-1614" logger.exception(error, keyword) return json.dumps(rr_dict_by_service_uid)
def touidref(src, dst, src_relation, src_portal_type, fieldname): """Convert an archetypes reference in src/src_relation to a UIDReference in dst/fieldname. """ field = dst.getField(fieldname) refs = src.getRefs(relationship=src_relation) if len(refs) == 1: value = get_uid(refs[0]) elif len(refs) > 1: value = filter(lambda x: x, [get_uid(ref) for ref in refs]) else: value = field.get(src) if not value: value = '' if not field: raise RuntimeError('Cannot find field %s/%s' % (fieldname, src)) if field.required and not value: logger.exception('Required %s field %s/%s has no value' % (src.portal_type, src, fieldname)) field.set(src, value)
def getClientContact(self): """ Returns info from the Client contact who coordinates with the lab """ pc = getToolByName(api.portal.get(), 'portal_catalog') contentFilter = {'portal_type': 'Contact', 'id': self.client_contact} cnt = pc(contentFilter) cntdict = {'uid': '', 'id': '', 'fullname': '', 'url': ''} if len(cnt) == 1: cnt = cnt[0].getObject() cntdict = { 'uid': cnt.id, 'id': cnt.UID(), 'fullname': cnt.getFullname(), 'url': cnt.absolute_url(), } else: from bika.lims import logger error = "Error when looking for contact with id '%s'. " logger.exception(error, self.client_contact) return cntdict
def getSRTemplateInfo(self): """ Returns a dict with the SRTemplate infomration {'uid':'xxxx','id':'xxxx','title':'xxx','url':'xxx'} """ pc = getToolByName(api.portal.get(), 'portal_catalog') contentFilter = {'portal_type': 'SRTemplate', 'UID': self.sr_template} srt = pc(contentFilter) srtdict = {'uid': '', 'id': '', 'title': '', 'url': ''} if len(srt) == 1: template = srt[0].getObject() srtdict = { 'uid': template.id, 'id': template.UID(), 'title': template.title, 'url': template.absolute_url(), } else: from bika.lims import logger error = "Error when looking for sr template with uid '%s'. " logger.exception(error, self.sr_template) return srtdict
def getDepartmentInfo(self): """ Returns a dict with the department infomration {'uid':'xxxx','id':'xxxx','title':'xxx','url':'xxx'} """ pc = getToolByName(api.portal.get(), 'portal_catalog') contentFilter = {'portal_type': 'Department', 'UID': self.department} departmentlist = pc(contentFilter) departmentdict = {'uid': '', 'id': '', 'title': '', 'url': ''} if len(departmentlist) == 1: department = departmentlist[0].getObject() departmentdict = { 'uid': department.id, 'id': department.UID(), 'title': department.title, 'url': department.absolute_url(), } else: from bika.lims import logger error = "Error when looking for department with uid '%s'. " logger.exception(error, self.department) return departmentdict
def getClientInChargeAtSamplingTime(self): """ Returns info from the Client contact who is in charge at sampling time """ pc = getToolByName(api.portal.get(), 'portal_catalog') contentFilter = {'portal_type': 'Contact', 'id': self.client_contact_in_charge_at_sampling_time} cnt = pc(contentFilter) cntdict = {'uid': '', 'id': '', 'fullname': '', 'url': ''} if len(cnt) == 1: cnt = cnt[0].getObject() cntdict = { 'uid': cnt.id, 'id': cnt.UID(), 'fullname': cnt.getFullname(), 'url': cnt.absolute_url(), } else: from bika.lims import logger error = "Error when looking for contact with id '%s'. " logger.exception( error, self.client_contact_in_charge_at_sampling_time) return cntdict