Skip to content

Commit 16e1fa7

Browse files
committed
Add "to" and "subject" fuzzy searches.
- Legacy-Id: 915
1 parent ed17c90 commit 16e1fa7

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

ietf/liaisons/feeds.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from django.contrib.syndication.feeds import Feed, FeedDoesNotExist
44
from django.utils.feedgenerator import Atom1Feed
5+
from django.db.models import Q
56
from ietf.liaisons.models import LiaisonDetail, FromBodies
67
from ietf.idtracker.models import Acronym
78
import re
@@ -44,6 +45,22 @@ def get_object(self, bits):
4445
obj['filter'] = {'from_id__in': frmlist}
4546
obj['title'] = 'Liaison Statements from %s' % body
4647
return obj
48+
if bits[0] == 'to':
49+
if len(bits) != 2:
50+
raise FeedDoesNotExist
51+
# The schema uses two different fields for the same
52+
# basic purpose, depending on whether it's a Secretariat-submitted
53+
# or Liaison-tool-submitted document.
54+
obj['q'] = [ (Q(by_secretariat=0) & Q(to_body__icontains=bits[1])) | (Q(by_secretariat=1) & Q(submitter_name__icontains=bits[1])) ]
55+
obj['title'] = 'Liaison Statements where to matches %s' % bits[1]
56+
return obj
57+
if bits[0] == 'subject':
58+
if len(bits) != 2:
59+
raise FeedDoesNotExist
60+
obj['q'] = [ Q(title__icontains=bits[1]) | Q(uploads__file_title__icontains=bits[1]) ]
61+
obj['title'] = 'Liaison Statements where subject matches %s' % bits[1]
62+
return obj
63+
raise FeedDoesNotExist
4764

4865
def title(self, obj):
4966
return obj['title']
@@ -58,6 +75,10 @@ def description(self, obj):
5875
def items(self, obj):
5976
# Start with the common queryset
6077
qs = LiaisonDetail.objects.all().order_by("-submitted_date")
78+
if obj.has_key('q'):
79+
qs = qs.filter(*obj['q'])
80+
select, sql, params = qs._get_sql_clause()
81+
print "applied Q: %s" % sql
6182
if obj.has_key('filter'):
6283
qs = qs.filter(**obj['filter'])
6384
if obj.has_key('limit'):

0 commit comments

Comments
 (0)