def folderitem(self, obj, item, index): """Service triggered each time an item is iterated in folderitems. The use of this service prevents the extra-loops in child objects. :obj: the instance of the class to be foldered :item: dict containing the properties of the object to be used by the template :index: current index of the item """ item["Description"] = obj.Description() item["replace"]["Title"] = get_link(item["url"], item["Title"]) instrument = obj.getInstrument() if instrument: instrument_url = api.get_url(instrument) instrument_title = api.get_title(instrument) item["Instrument"] = instrument_title item["replace"]["Instrument"] = get_link( instrument_url, value=instrument_title) # Method method_uid = obj.getMethodUID() if method_uid: method = api.get_object_by_uid(method_uid) method_url = api.get_url(method) method_title = api.get_title(method) item["Method"] = method_title item["replace"]["Method"] = get_link( method_url, value=method_title) return item
def get_samples_data(self): """Returns a list of AR data """ for obj in self.get_objects_from_request(): obj = api.get_object(obj) yield { "obj": obj, "id": api.get_id(obj), "uid": api.get_uid(obj), "title": api.get_title(obj), "path": api.get_path(obj), "url": api.get_url(obj), "sample_type": api.get_title(obj.getSampleType()) }
def get_clients_vocabulary(self): client = api.get_current_client() if client: # Current user is a client contact. Load only this client return DisplayList([(api.get_uid(client), api.get_title(client))]) # Current user is not a client contact. Load all active clients query = dict(portal_type="Client", is_active=True) clients = api.search(query, "portal_catalog") clients = map(lambda cl: [api.get_uid(cl), api.get_title(cl)], clients) clients.sort(lambda x, y: cmp(x[1].lower(), y[1].lower())) # Lab personnel can set a Patient to be visible for all Clients clients.insert(0, ['', '']) return DisplayList(clients)
def get_sample_container_info(self): """Returns the storage container this Sample is stored in """ # Search the container the sample is stored in query = { "portal_type": "StorageSamplesContainer", "get_samples_uids": api.get_uid(self.context) } brains = api.search(query, SENAITE_STORAGE_CATALOG) if not brains: return None # Get the data info from the container container = api.get_object(brains[0]) position = container.get_object_position(self.context) position = container.position_to_alpha(position[0], position[1]) return { "uid": api.get_uid(container), "id": api.get_id(container), "title": api.get_title(container), "url": api.get_url(container), "position": position, "full_title": container.get_full_title(), "when": wf.getTransitionDate(self.context, "store"), }
def get_microorganisms(analyses): """Returns the list of microorganisms from the analyses passed-in """ names = map(lambda a: a.getShortTitle(), analyses) objects = api.get_setup().microorganisms.objectValues() objects = filter(lambda m: api.get_title(m) in names, objects) return filter(None, objects)
def get_microorganisms(self): """Returns the list of microorganism objects assigned to this sample, sorted by title ascending """ analyses = self.get_analyses(skip_invalid=True) microorganisms = utils.get_microorganisms(analyses) return sorted(microorganisms, key=lambda m: api.get_title(m))
def get_antibiotics(self): """Returns the list of antibiotics objects assigned to this sample, sorted by title ascending """ analyses = self.get_analyses(skip_invalid=True) antibiotics = utils.get_antibiotics(analyses) return sorted(antibiotics, key=lambda ab: api.get_title(ab))
def __call__(self, value, *args, **kwargs): instance = kwargs['instance'] request = kwargs.get('REQUEST', {}) fieldname = kwargs['field'].getName() # This value in request prevents running once per subfield value. # self.name returns the name of the validator. This allows other # subfield validators to be called if defined (eg. in other add-ons) key = '{}-{}-{}'.format(self.name, instance.getId(), fieldname) if instance.REQUEST.get(key, False): return True # Walk through all AS UIDs and validate each parameter for that AS service_uids = request.get("uids", []) for uid in service_uids: err_msg = self.validate_service(request, uid) if not err_msg: continue # Validation failed service = api.get_object_by_uid(uid) title = api.get_title(service) err_msg = "{}: {}".format(title, _(err_msg)) translate = api.get_tool('translation_service').translate instance.REQUEST[key] = to_utf8(translate(safe_unicode(err_msg))) return instance.REQUEST[key] instance.REQUEST[key] = True return True
def Vocabulary(self, content_instance=None): """Create a vocabulary from analysis services """ vocab = [] for service in self._get_services(): vocab.append((api.get_uid(service), api.get_title(service))) return vocab
def folderitem(self, obj, item, index): """Applies new properties to the item to be rendered """ obj = api.get_object(obj) # Replace client name with the link item['getPrimaryReferrer'] = "" client = obj.getClient() if client: client_link = get_link(api.get_url(client), api.get_title(client)) item["replace"]["getPrimaryReferrer"] = client_link # Replace doctor's full name with a link fullname = obj.getFullname() doctor_url = "{}/analysisrequests".format(api.get_url(obj)) doctor_link = get_link(doctor_url, fullname) item["replace"]["getFullname"] = doctor_link doctor_link = get_link(doctor_url, obj.getDoctorID()) item["replace"]["getDoctorID"] = doctor_link # Replace doctor's full name with a link email = obj.getEmailAddress() if email: item["replace"]['getEmailAddress'] = get_email_link(email) # Display the internal/external icons, but only if the logged-in user # does not belong to an external client if not self.is_external_user(): item["before"]["getFullname"] = get_client_aware_html_image(obj) return item
def folderitem(self, obj, item, index): obj = api.get_object(obj) url = api.get_url(obj) title = api.get_title(obj) item["replace"]["Title"] = get_link(url, value=title) item["query_type"] = getattr(obj, "query_type", None) return item
def getInstruments(self): """Get the allowed instruments """ query = {"portal_type": "Instrument", "inactive_state": "active"} if self.getRestrictToMethod(): query.update({ "getMethodUIDs": { "query": api.get_uid(self.getRestrictToMethod()), "operator": "or", } }) instruments = api.search(query, "bika_setup_catalog") items = map(lambda i: (i.UID, i.Title), instruments) instrument = self.getInstrument() if instrument: instrument_uids = map(api.get_uid, instruments) if api.get_uid(instrument) not in instrument_uids: items.append( (api.get_uid(instrument), api.get_title(instrument))) items.sort(lambda x, y: cmp(x[1], y[1])) items.insert(0, ("", _("No instrument"))) return DisplayList(list(items))
def folderitem(self, obj, item, index): """Service triggered each time an item is iterated in folderitems. The use of this service prevents the extra-loops in child objects. :obj: the instance of the class to be foldered :item: dict containing the properties of the object to be used by the template :index: current index of the item """ item = super(ReferenceSamplesView, self).folderitem(obj, item, index) # ensure we have an object and not a brain obj = api.get_object(obj) url = api.get_url(obj) title = api.get_title(obj) item["Title"] = title item["replace"]["Title"] = get_link(url, value=title) item["allow_edit"] = self.get_editable_columns() # Supported Services supported_services_choices = self.make_supported_services_choices(obj) item["choices"]["SupportedServices"] = supported_services_choices # Position item["Position"] = "new" item["choices"]["Position"] = self.make_position_choices() return item
def get_instrument_title(self): """Return the current instrument title """ instrument = self.context.getInstrument() if not instrument: return "" return api.get_title(instrument)
def getInstrumentTitle(self): """Return the instrument title """ instrument = self.getInstrument() if not instrument: return "" return api.get_title(instrument)
def folderitem(self, obj, item, index): """Service triggered each time an item is iterated in folderitems. The use of this service prevents the extra-loops in child objects. :obj: the instance of the class to be foldered :item: dict containing the properties of the object to be used by the template :index: current index of the item """ layout = obj.getLayout title = api.get_title(obj) url = api.get_url(obj) item["CreationDate"] = self.ulocalized_time(obj.created) if len(obj.getAnalysesUIDs) == 0: item["table_row_class"] = "state-empty-worksheet" title_link = "{}/{}".format(url, "add_analyses") if len(layout) > 0: title_link = "{}/{}".format(url, "manage_results") item["Title"] = title item["replace"]["Title"] = get_link(title_link, value=title) pos_parent = {} for slot in layout: # compensate for bad data caused by a stupid bug. if type(slot["position"]) in (list, tuple): slot["position"] = slot["position"][0] if slot["position"] == "new": continue if slot["position"] in pos_parent: continue pos_parent[slot["position"]] =\ self.rc.lookupObject(slot.get("container_uid")) # Total QC Analyses item["NumQCAnalyses"] = str(obj.getNumberOfQCAnalyses) # Total Routine Analyses item["NumRegularAnalyses"] = str(obj.getNumberOfRegularAnalyses) # Total Number of Samples item["NumRegularSamples"] = str(obj.getNumberOfRegularSamples) # Progress progress_perc = obj.getProgressPercentage item["replace"]["Progress"] = get_progress_bar_html(progress_perc) review_state = item["review_state"] if self.can_reassign and review_state == "open": item["Analyst"] = obj.getAnalyst item["allow_edit"] = ["Analyst"] item["required"] = ["Analyst"] item["choices"] = {"Analyst": self.analyst_choices} else: fullname = user_fullname(self.context, obj.getAnalyst) item["Analyst"] = fullname return item
def get_display_list(brains_or_objects=None, none_item=False): """ Returns a DisplayList with the items sorted by Title :param brains_or_objects: list of brains or objects :param none_item: adds an item with empty uid and text "Select.." in pos 0 :return: DisplayList (uid, title) sorted by title ascending :rtype: DisplayList """ if brains_or_objects is None: return get_display_list(list(), none_item) items = list() for brain in brains_or_objects: uid = api.get_uid(brain) if not uid: continue title = api.get_title(brain) items.append((uid, title)) # Sort items by title ascending items.sort(lambda x, y: cmp(x[1], y[1])) # Add the first item? if none_item: items.insert(0, ('', t('Select...'))) return DisplayList(items)
def to_str(self, analysis): """Returns a string representation of the analysis """ return "{} ({}) {}".format( api.get_title(analysis), analysis.getKeyword(), utils.get_formatted_panic(analysis)).strip()
def __init__(self, context, request): super(DynamicAnalysisSpecView, self).__init__(context, request) self.pagesize = 50 self.context_actions = {} self.title = api.get_title(self.context) self.description = api.get_description(self.context) self.show_search = False self.show_column_toggles = False if self.context.specs_file: filename = self.context.specs_file.filename self.description = _("Contents of the file {}".format(filename)) self.specs = self.context.get_specs() self.total = len(self.specs) self.columns = collections.OrderedDict() for title in self.context.get_header(): self.columns[title] = {"title": title, "toggle": True} self.review_states = [{ "id": "default", "title": _("All"), "contentFilter": {}, "transitions": [], "custom_transitions": [], "columns": self.columns.keys() }]
def folderitem(self, obj, item, index): """Service triggered each time an item is iterated in folderitems. The use of this service prevents the extra-loops in child objects. :obj: the instance of the class to be foldered :item: dict containing the properties of the object to be used by the template :index: current index of the item """ # ensure we have an object and not a brain obj = api.get_object(obj) uid = api.get_uid(obj) url = api.get_url(obj) title = api.get_title(obj) # get the category if self.show_categories_enabled(): category = obj.getCategoryTitle() if category not in self.categories: self.categories.append(category) item["category"] = category config = self.configuration.get(uid, {}) hidden = config.get("hidden", False) item["replace"]["Title"] = get_link(url, value=title) item["Price"] = self.format_price(obj.Price) item["allow_edit"] = self.get_editable_columns() item["selected"] = False item["Hidden"] = hidden item["selected"] = uid in self.configuration # Add methods methods = obj.getMethods() if methods: links = map( lambda m: get_link( m.absolute_url(), value=m.Title(), css_class="link"), methods) item["replace"]["Methods"] = ", ".join(links) else: item["methods"] = "" # Icons after_icons = "" if obj.getAccredited(): after_icons += get_image( "accredited.png", title=_("Accredited")) if obj.getAttachmentOption() == "r": after_icons += get_image( "attach_reqd.png", title=_("Attachment required")) if obj.getAttachmentOption() == "n": after_icons += get_image( "attach_no.png", title=_("Attachment not permitted")) if after_icons: item["after"]["Title"] = after_icons return item
def get_title_or_id_from_uid(uid): """Returns the title or ID from the given UID """ obj = api.get_object_by_uid(uid, default=None) if obj is None: return "" title_or_id = api.get_title(obj) or api.get_id(obj) return title_or_id
def folderitem(self, obj, item, index): obj = api.get_object(obj) title = api.get_title(obj) desc = api.get_description(obj) item['sample'] = obj.sample item['analyte'] = obj.analyte item['result'] = obj.result return item
def get_link_for(obj, **kwargs): """Returns a well-formed html anchor to the object """ if not obj: return "" href = api.get_url(obj) value = api.get_title(obj) return get_link(href=href, value=value, **kwargs)
def _get_title_or_id_from_uid(uid): """Returns the title or ID from the given UID """ try: obj = api.get_object_by_uid(uid) except api.APIError: return "<Deleted {}>".format(uid) title_or_id = api.get_title(obj) or api.get_id(obj) return title_or_id
def folderitem(self, obj, item, index): obj = api.get_object(obj) method = obj.getMethod() if method: item["Method"] = api.get_title(method) item["replace"]["Method"] = get_link_for(method) item["replace"]["Title"] = get_link(item["url"], item["Title"]) return item
def _defaultDepsVoc(self): """Vocabulary of all departments """ # Getting the assigned departments deps = self.getDepartments() items = [] for d in deps: items.append((api.get_uid(d), api.get_title(d))) return api.to_display_list(items, sort_by="value", allow_empty=True)
def get_calculations_choices(self): """Build a list of listing specific calculation choices """ calculations = self.get_calculations() return map( lambda brain: { "ResultValue": api.get_uid(brain), "ResultText": api.get_title(brain) }, calculations)
def folderitems(self): """Custom folderitems for Worksheet ARs """ items = [] for ar, pos in self.get_container_mapping().items(): ar = api.get_object_by_uid(ar) ar_id = api.get_id(ar) ar_uid = api.get_uid(ar) ar_url = api.get_url(ar) ar_title = api.get_title(ar) url = api.get_url(ar) client = ar.getClient() client_url = api.get_url(client) client_title = api.get_title(client) item = { "obj": ar, "id": ar_id, "uid": ar_uid, "title": ar_title, "type_class": "contenttype-AnalysisRequest", "url": url, "relative_url": url, "view_url": url, "Position": pos, "RequestID": ar_id, "Client": client_title, "created": self.ulocalized_time(ar.created(), long_format=1), "replace": { "Client": get_link(client_url, value=client_title), "RequestID": get_link(ar_url, value=ar_title), }, "before": {}, "after": {}, "choices": {}, "class": {}, "state_class": "state-active", "allow_edit": [], "required": [], } items.append(item) items = sorted(items, key=itemgetter("Position")) return items
def getSampleTypeTitle(self): """Returns the title or a comma separated list of sample type titles """ sample_type = self.getSampleType() if isinstance(sample_type, (list, tuple)): title = map(api.get_title, sample_type) return ", ".join(title) elif sample_type: return api.get_title(sample_type) return None
def get_full_title(self, breadcrumbs=None): """Returns the full title of this container in breadcrumbs format """ if not breadcrumbs: breadcrumbs = "{} - {}".format(self.Title(), self.getId()) parent = self.aq_parent breadcrumbs = "{} > {}".format(api.get_title(parent), breadcrumbs) if IStorageFacility.providedBy(parent): return breadcrumbs return parent.get_full_title(breadcrumbs)
def to_string(v): if isinstance(v, basestring): return v return api.get_title(v)