+ def apply_filter(filt):
+ if 'not' in filt:
+ return ~apply_filter(filt['not'])
+ if 'startswith' in filt:
+ q = None
+ for prefix in filt['startswith']:
+ q2 = Q(code__startswith=prefix)
+ if q:
+ q |= q2
+ else:
+ q = q2
+ return q
+ assert False
+
+ qs = self.queryset
+ try:
+ filt = json.loads(request.GET.get('filter'))
+ except:
+ pass
+ else:
+ qs = qs.filter(apply_filter(filt))
+
+ for thema in qs: