def __call__(self, request, data): include_fields = get_include_fields(request) if not include_fields or "ServiceDependencies" in include_fields: data["ServiceDependencies"] = [] calc = self.context.getCalculation() if calc: services = [self.service_info(service) for service in calc.getCalculationDependencies(flat=True) if service.UID() != self.context.UID()] data["ServiceDependencies"] = services if not include_fields or "ServiceDependants" in include_fields: data["ServiceDependants"] = [] calcs = self.context.getBackReferences('CalculationAnalysisService') if calcs: for calc in calcs: services = [self.service_info(service) for service in calc.getCalculationDependants() if service.UID() != self.context.UID()] data["ServiceDependants"].extend(services) if not include_fields or "MethodInstruments" in include_fields: data["MethodInstruments"] = {} for method in self.context.getAvailableMethods(): for instrument in method.getInstruments(): if method.UID() not in data["MethodInstruments"]: data["MethodInstruments"][method.UID()] = [] data["MethodInstruments"][method.UID()].append( load_field_values(instrument, include_fields=[]))
def __call__(self, request, data): include_fields = get_include_fields(request) if not include_fields or "ServiceDependencies" in include_fields: data["ServiceDependencies"] = [] calc = self.context.getCalculation() if calc: services = [ self.service_info(service) for service in calc.getCalculationDependencies(flat=True) if service.UID() != self.context.UID() ] data["ServiceDependencies"] = services if not include_fields or "ServiceDependants" in include_fields: data["ServiceDependants"] = [] calcs = self.context.getBackReferences( 'CalculationAnalysisService') if calcs: for calc in calcs: services = [ self.service_info(service) for service in calc.getCalculationDependants() if service.UID() != self.context.UID() ] data["ServiceDependants"].extend(services) if not include_fields or "MethodInstruments" in include_fields: data["MethodInstruments"] = {} for method in self.context.getAvailableMethods(): for instrument in method.getInstruments(): if method.UID() not in data["MethodInstruments"]: data["MethodInstruments"][method.UID()] = [] data["MethodInstruments"][method.UID()].append( load_field_values(instrument, include_fields=[]))
def read(context, request): tag = AuthenticatorView(context, request).authenticator() pattern = '<input .*name="(\w+)".*value="(\w+)"' _authenticator = re.match(pattern, tag).groups()[1] ret = { "url": router.url_for("read", force_external=True), "success": True, "error": False, "objects": [], "_authenticator": _authenticator, } debug_mode = True #App.config.getConfiguration().debug_mode "Commented by Yasir" catalog_name = request.get("catalog_name", "portal_catalog") if not catalog_name: raise ValueError("bad or missing catalog_name: " + catalog_name) catalog = getToolByName(context, catalog_name) indexes = catalog.indexes() contentFilter = {} for index in indexes: if index in request: if index == 'review_state' and "{" in request[index]: continue contentFilter[index] = safe_unicode(request[index]) if "%s[]"%index in request: value = request["%s[]"%index] contentFilter[index] = [safe_unicode(v) for v in value] if 'limit' in request: try: contentFilter['sort_limit'] = int(request["limit"]) except ValueError: pass sort_on = request.get('sort_on', 'id') contentFilter['sort_on'] = sort_on # sort order sort_order = request.get('sort_order', '') if sort_order: contentFilter['sort_order'] = sort_order else: sort_order = 'ascending' contentFilter['sort_order'] = 'ascending' include_fields = get_include_fields(request) if debug_mode: logger.info("contentFilter: " + str(contentFilter)) # Get matching objects from catalog proxies = catalog(**contentFilter) # batching items page_nr = int(request.get("page_nr", 0)) try: page_size = int(request.get("page_size", 10)) except ValueError: page_size = 10 # page_size == 0: show all if page_size == 0: page_size = len(proxies) first_item_nr = page_size * page_nr if first_item_nr > len(proxies): first_item_nr = 0 page_proxies = proxies[first_item_nr:first_item_nr + page_size] for proxy in page_proxies: obj_data = {} # Place all proxy attributes into the result. obj_data.update(load_brain_metadata(proxy, include_fields)) # Place all schema fields ino the result. obj = proxy.getObject() obj_data.update(load_field_values(obj, include_fields)) obj_data['path'] = "/".join(obj.getPhysicalPath()) # call any adapters that care to modify this data. adapters = getAdapters((obj, ), IJSONReadExtender) for name, adapter in adapters: adapter(request, obj_data) ret['objects'].append(obj_data) ret['total_objects'] = len(proxies) ret['first_object_nr'] = first_item_nr last_object_nr = first_item_nr + len(page_proxies) if last_object_nr > ret['total_objects']: last_object_nr = ret['total_objects'] ret['last_object_nr'] = last_object_nr if debug_mode: logger.info("{0} objects returned".format(len(ret['objects']))) return ret
def __call__(self, request, data): self.request = request self.include_fields = get_include_fields(request) if not self.include_fields or "specification" in self.include_fields: data['specification'] = self.analysis_specification() return data
def read(context, request): tag = AuthenticatorView(context, request).authenticator() pattern = '<input .*name="(\w+)".*value="(\w+)"' _authenticator = re.match(pattern, tag).groups()[1] ret = { "url": router.url_for("read", force_external=True), "success": True, "error": False, "objects": [], "_authenticator": _authenticator, } debug_mode = True #App.config.getConfiguration().debug_mode "Commented by Yasir" catalog_name = request.get("catalog_name", "portal_catalog") if not catalog_name: raise ValueError("bad or missing catalog_name: " + catalog_name) catalog = getToolByName(context, catalog_name) indexes = catalog.indexes() contentFilter = {} for index in indexes: if index in request: if index == 'review_state' and "{" in request[index]: continue contentFilter[index] = safe_unicode(request[index]) if "%s[]" % index in request: value = request["%s[]" % index] contentFilter[index] = [safe_unicode(v) for v in value] if 'limit' in request: try: contentFilter['sort_limit'] = int(request["limit"]) except ValueError: pass sort_on = request.get('sort_on', 'id') contentFilter['sort_on'] = sort_on # sort order sort_order = request.get('sort_order', '') if sort_order: contentFilter['sort_order'] = sort_order else: sort_order = 'ascending' contentFilter['sort_order'] = 'ascending' include_fields = get_include_fields(request) if debug_mode: logger.info("contentFilter: " + str(contentFilter)) # Get matching objects from catalog proxies = catalog(**contentFilter) # batching items page_nr = int(request.get("page_nr", 0)) try: page_size = int(request.get("page_size", 10)) except ValueError: page_size = 10 # page_size == 0: show all if page_size == 0: page_size = len(proxies) first_item_nr = page_size * page_nr if first_item_nr > len(proxies): first_item_nr = 0 page_proxies = proxies[first_item_nr:first_item_nr + page_size] for proxy in page_proxies: obj_data = {} # Place all proxy attributes into the result. obj_data.update(load_brain_metadata(proxy, include_fields)) # Place all schema fields ino the result. obj = proxy.getObject() obj_data.update(load_field_values(obj, include_fields)) obj_data['path'] = "/".join(obj.getPhysicalPath()) # call any adapters that care to modify this data. adapters = getAdapters((obj, ), IJSONReadExtender) for name, adapter in adapters: adapter(request, obj_data) ret['objects'].append(obj_data) ret['total_objects'] = len(proxies) ret['first_object_nr'] = first_item_nr last_object_nr = first_item_nr + len(page_proxies) if last_object_nr > ret['total_objects']: last_object_nr = ret['total_objects'] ret['last_object_nr'] = last_object_nr if debug_mode: logger.info("{0} objects returned".format(len(ret['objects']))) return ret
def __call__(self, request, data): include_fields = get_include_fields(request) if not include_fields or "transitions" in include_fields: data['transitions'] = get_workflow_actions(self.context)
def __call__(self, request, data): self.request = request self.include_fields = get_include_fields(request) if not self.include_fields or "Analyses" in self.include_fields: data['Analyses'] = self.ar_analysis_values()