Example #1
0
    def outlet_type_filter(self):
        categories = supply_point_type_categories(self.domain)
        selected = self.request.GET.getlist('outlet_type')
        if not selected:
            selected = ['_all']

        def types_for_sel(sel):
            if sel == '_oth':
                return categories['_oth']
            elif sel.startswith('cat:'):
                return categories[sel[len('cat:'):]]
            else:
                return [sel]
        active_outlet_types = reduce(lambda a, b: a.union(b), (types_for_sel(sel) for sel in selected), set())

        return lambda outlet_type: ('_all' in selected) or (outlet_type in active_outlet_types)
Example #2
0
    def outlet_type_filter(self):
        categories = supply_point_type_categories(self.domain)
        selected = self.request.GET.getlist('outlet_type')
        if not selected:
            selected = ['_all']

        def types_for_sel(sel):
            if sel == '_oth':
                return categories['_oth']
            elif sel.startswith('cat:'):
                return categories[sel[len('cat:'):]]
            else:
                return [sel]

        active_outlet_types = reduce(lambda a, b: a.union(b),
                                     (types_for_sel(sel) for sel in selected),
                                     set())

        def match_filter(loc):
            outlet_type = loc.dynamic_properties().get('outlet_type')
            return ('_all' in selected) or (outlet_type in active_outlet_types)

        return match_filter