space-accessstablestage
Last change
on this file was
7b00af8,
checked in by Alex Dehnert <adehnert@…>, 13 years ago
|
Allow search by account number, officer list
Both had privacy concerns, but I think they're fine:
Account numbers (ASA-#122) can already be looked up, entirely unauthenticated,
with the account lookup tool (https://asa.mit.edu/groups/account_lookup/).
Exposing a search for exact account numbers on the search page too seems
acceptable in this light.
Officer lists (ASA-#123) are mostly public --- they're available to anybody
with certs, they're on most groups' websites, and I believe we'd display them
obfuscated to the whole world if we had obfuscation code. The possibility of
somebody scraping the search page with progressively more refined search terms
to get this data seems acceptable.
|
-
Property mode set to
100644
|
File size:
961 bytes
|
Line | |
---|
1 | from django.db.models import Q |
---|
2 | |
---|
3 | from django_filters.filters import Filter, NumberFilter |
---|
4 | |
---|
5 | class MultiFilter(Filter): |
---|
6 | def __init__(self, names, *args, **kwargs): |
---|
7 | super(MultiFilter, self).__init__(self, *args, **kwargs) |
---|
8 | assert len(names) > 0 |
---|
9 | self.names = names |
---|
10 | |
---|
11 | def initial_q(self, value): |
---|
12 | return Q() |
---|
13 | |
---|
14 | def filter(self, qs, value): |
---|
15 | if not value: |
---|
16 | return qs |
---|
17 | if isinstance(value, (list, tuple)): |
---|
18 | lookup = str(value[1]) |
---|
19 | if not lookup: |
---|
20 | lookup = 'exact' # we fallback to exact if no choice for lookup is provided |
---|
21 | value = value[0] |
---|
22 | else: |
---|
23 | lookup = self.lookup_type |
---|
24 | if value: |
---|
25 | q = self.initial_q(value) |
---|
26 | for name in self.names: |
---|
27 | q = q | Q(**{'%s__%s' % (name, lookup): value}) |
---|
28 | qs = qs.filter(q) |
---|
29 | return qs |
---|
30 | |
---|
31 | class MultiNumberFilter(MultiFilter,NumberFilter): |
---|
32 | pass |
---|
Note: See
TracBrowser
for help on using the repository browser.