def get_active_letters(self): report = self.context catalog = find_peopledirectory_catalog(report) # Use the lastnamestartswith index directly for speed. index = catalog["lastnamestartswith"] filters = [(name, obj) for name, obj in report.items() if IPeopleReportFilter.providedBy(obj)] if not filters: # Any letter in the index will suffice. This is a fast # common case. # XXX using undocumented _fwd_index attribute return set(index._fwd_index.keys()) # Perform a catalog search, but don't resolve any paths. kw = {} for catid, filter in filters: if IPeopleReportCategoryFilter.providedBy(filter): kw["category_%s" % str(catid)] = {"query": filter.values, "operator": "or"} elif IPeopleReportGroupFilter.providedBy(filter): kw["groups"] = {"query": filter.values, "operator": "or"} total, docids = catalog.search(**kw) # Intersect the search result docids with the docid set # for each letter. docid_set = index.family.IF.Set(docids) active = set() intersection = index.family.IF.intersection for letter in string.uppercase: # XXX using undocumented _fwd_index attribute letter_set = index._fwd_index.get(letter) if not letter_set: continue if intersection(letter_set, docid_set): active.add(letter) return active
def getQuery(self): """ See IPeopleReport. """ query = {} for catid, filter in self.items(): if IPeopleReportCategoryFilter.providedBy(filter): query['category_%s' % str(catid)] = {'query': filter.values, 'operator': 'or'} elif IPeopleReportGroupFilter.providedBy(filter): query['groups'] = {'query': filter.values, 'operator': 'or'} elif IPeopleReportIsStaffFilter.providedBy(filter): query['is_staff'] = filter.include_staff return query
def getQuery(self): """ See IPeopleReport. """ query = {} for catid, filter in self.items(): if IPeopleReportCategoryFilter.providedBy(filter): query['category_%s' % str(catid)] = { 'query': filter.values, 'operator': 'or' } elif IPeopleReportGroupFilter.providedBy(filter): query['groups'] = {'query': filter.values, 'operator': 'or'} elif IPeopleReportIsStaffFilter.providedBy(filter): query['is_staff'] = filter.include_staff return query
def _report_filter_items(report): if "filters" in report.__dict__: # Old-skool for key, values in report.filters.items(): yield {"name": key, "type": "category", "values": " ".join(values)} # return [(name, filter.values) for name, filter in report.items()] else: for name, obj in sorted(report.items()): info = {"name": name, "type": "unknown", "obj": obj} if IPeopleReportCategoryFilter.providedBy(obj): info["type"] = "category" info["values"] = " ".join(obj.values) elif IPeopleReportGroupFilter.providedBy(obj): info["type"] = "groups" info["values"] = " ".join(obj.values) elif IPeopleReportIsStaffFilter.providedBy(obj): info["type"] = "is_staff" info["include_staff"] = str(obj.include_staff) yield info
def get_active_letters(self): report = self.context catalog = find_peopledirectory_catalog(report) # Use the lastnamestartswith index directly for speed. index = catalog['lastnamestartswith'] filters = [(name, obj) for name, obj in report.items() if IPeopleReportFilter.providedBy(obj)] if not filters: # Any letter in the index will suffice. This is a fast # common case. # XXX using undocumented _fwd_index attribute return set(index._fwd_index.keys()) # Perform a catalog search, but don't resolve any paths. kw = {} for catid, filter in filters: if IPeopleReportCategoryFilter.providedBy(filter): kw['category_%s' % str(catid)] = { 'query': filter.values, 'operator': 'or', } elif IPeopleReportGroupFilter.providedBy(filter): kw['groups'] = { 'query': filter.values, 'operator': 'or', } total, docids = catalog.search(**kw) # Intersect the search result docids with the docid set # for each letter. docid_set = index.family.IF.Set(docids) active = set() intersection = index.family.IF.intersection for letter in string.uppercase: # XXX using undocumented _fwd_index attribute letter_set = index._fwd_index.get(letter) if not letter_set: continue if intersection(letter_set, docid_set): active.add(letter) return active
def _report_filter_items(report): if 'filters' in report.__dict__: # Old-skool for key, values in report.filters.items(): yield {'name': key, 'type': 'category', 'values': ' '.join(values), } #return [(name, filter.values) for name, filter in report.items()] else: for name, obj in sorted(report.items()): info = {'name': name, 'type': 'unknown', 'obj': obj} if IPeopleReportCategoryFilter.providedBy(obj): info['type'] = 'category' info['values'] = ' '.join(obj.values) elif IPeopleReportGroupFilter.providedBy(obj): info['type'] = 'groups' info['values'] = ' '.join(obj.values) elif IPeopleReportIsStaffFilter.providedBy(obj): info['type'] = 'is_staff' info['include_staff'] = str(obj.include_staff) yield info
def _xxx_report_filter_items(report): if 'filters' in report.__dict__: # Old-skool for key, values in report.filters.items(): yield {'name': key, 'type': 'category', 'values': ' '.join(values), } #return [(name, filter.values) for name, filter in report.items()] else: for name, obj in sorted(report.items()): info = {'name': name, 'type': 'unknown', 'obj': obj} if IPeopleReportCategoryFilter.providedBy(obj): info['type'] = 'category' info['values'] = ' '.join(obj.values) elif IPeopleReportGroupFilter.providedBy(obj): info['type'] = 'groups' info['values'] = ' '.join(obj.values) elif IPeopleReportIsStaffFilter.providedBy(obj): info['type'] = 'is_staff' info['include_staff'] = str(obj.include_staff) yield info