def parse_report(people, elem): from karl.views.peopledirectory import COLUMNS name, title = name_and_title(elem) link_title = elem.get("link-title", title) css_class = elem.get("class", "general") report = PeopleReport(title, link_title, css_class) categories = people.get("categories", {}) for e in elem.findall("filter"): f_name = e.get("name") typ = e.get("type") values = e.get("values", "").split() if typ in ("category", "groups") and not values: raise ParseError("No values given", e) if typ == "category": category = e.get("category") if category is None: raise ParseError("No category given", e) pc = categories.get(category) if pc is None: raise ParseError("No such category defined", e) for v in values: if v not in pc: raise ParseError("No such category value: %s" % v, e) report[category] = PeopleReportCategoryFilter(tuple(values)) elif typ == "groups": report[f_name] = PeopleReportGroupFilter(tuple(values)) elif typ == "is_staff": include_staff = report.get("include_staff", False) report[f_name] = PeopleReportIsStaffFilter(include_staff) else: raise ParseError("Unknown filter type", e) mlist_elem = elem.find("mailinglist") if mlist_elem is not None: mlist = report["mailinglist"] = PeopleReportMailingList() short_address = mlist_elem.get("short_address") if short_address is not None: if short_address in find_site(people).list_aliases: raise ParseError("Duplicate short address: %s" % short_address, mlist_elem) mlist.short_address = short_address columns = None e = elem.find("columns") if e is not None: columns = e.get("names", "").split() if not columns: columns = e.get("ids", "").split() # BBB if not columns: raise ParseError("No columns given", elem) for colid in columns: if not colid in COLUMNS: raise ParseError("No such column defined: %s" % colid, e) report.columns = tuple(columns) return name, report
def parse_report(people, elem): from karl.views.peopledirectory import COLUMNS name, title = name_and_title(elem) link_title = elem.get('link-title', title) css_class = elem.get('class', 'general') report = PeopleReport(title, link_title, css_class) categories = people.get('categories', {}) for e in elem.findall('filter'): f_name = e.get('name') typ = e.get('type') values = e.get('values', '').split() if typ in ('category', 'groups') and not values: raise ParseError("No values given", e) if typ == 'category': category = e.get('category') if category is None: raise ParseError("No category given", e) pc = categories.get(category) if pc is None: raise ParseError("No such category defined", e) for v in values: if v not in pc: raise ParseError("No such category value: %s" % v, e) report[category] = PeopleReportCategoryFilter(tuple(values)) elif typ == 'groups': report[f_name] = PeopleReportGroupFilter(tuple(values)) elif typ == 'is_staff': include_staff = report.get('include_staff', False) report[f_name] = PeopleReportIsStaffFilter(include_staff) else: raise ParseError("Unknown filter type", e) mlist_elem = elem.find('mailinglist') if mlist_elem is not None: mlist = report['mailinglist'] = PeopleReportMailingList() short_address = mlist_elem.get('short_address') if short_address is not None: if short_address in find_site(people).list_aliases: raise ParseError("Duplicate short address: %s" % short_address, mlist_elem) mlist.short_address = short_address columns = None e = elem.find('columns') if e is not None: columns = e.get('names', '').split() if not columns: columns = e.get('ids', '').split() # BBB if not columns: raise ParseError("No columns given", elem) for colid in columns: if not colid in COLUMNS: raise ParseError("No such column defined: %s" % colid, e) report.columns = tuple(columns) return name, report
def parse_report(people, elem): reportid, title = id_and_title(elem) link_title = elem.get('link-title', title) css_class = elem.get('class', 'general') obj = PeopleReport(title, link_title, css_class) query = None e = elem.find('query') if e is not None: query = eval(e.text.strip()) if query: obj.set_query(query) for e in elem.findall('filter'): catid = e.get('category') values = e.get('values', '').split() pc = people.categories.get(catid) if pc is None: raise ParseError("No such category defined", e) if not values: raise ParseError("No category values given", e) for v in values: if v not in pc: raise ParseError("No such category value: %s" % v, e) obj.set_filter(catid, values) columns = None e = elem.find('columns') if e is not None: columns = e.get('ids', '').split() if not columns: raise ParseError("No columns given", elem) for colid in columns: if not colid in COLUMNS: raise ParseError("No such column defined: %s" % colid, e) obj.set_columns(columns) return reportid, obj