Skip to content

Commit 9d119f2

Browse files
committed
The syntax for feeds from bodies is now /feed/liaison/from/body-name/
where body-name is lowercased and has non-word characters replaced by hyphens. This is accomplished with a 'like' query using an extra() statement, making this bit of code mysql-specific. - Legacy-Id: 912
1 parent 610f685 commit 9d119f2

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

ietf/liaisons/feeds.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.utils.feedgenerator import Atom1Feed
55
from ietf.liaisons.models import LiaisonDetail, FromBodies
66
from ietf.idtracker.models import Acronym
7+
import re
78

89
# A slightly funny feed class, the 'object' is really
910
# just a dict with some parameters that items() uses
@@ -21,17 +22,27 @@ def get_object(self, bits):
2122
if bits[0] == 'from':
2223
if len(bits) != 2:
2324
raise FeedDoesNotExist
24-
obj['title'] = 'Liaison Statements from %s' % bits[1]
2525
try:
2626
acronym = Acronym.objects.get(acronym=bits[1])
2727
obj['filter'] = {'from_id': acronym.acronym_id}
28+
body = bits[1]
2829
except Acronym.DoesNotExist:
29-
# would like to use from_body__body_name but relation
30-
# is broken due to database structure
31-
frmlist = [b['from_id'] for b in FromBodies.objects.filter(body_name=bits[1]).values('from_id')]
32-
if not frmlist:
30+
# Find body matches. Turn all non-word characters
31+
# into wildcards for the like search.
32+
# Note that supplying sql here means that this is
33+
# mysql-specific (e.g., postgresql wants 'ilike' for
34+
# the same operation)
35+
body_list = FromBodies.objects.values('from_id','body_name').extra(where=['body_name like "%s"' % re.sub('\W', '_', bits[1])])
36+
if not body_list:
3337
raise FeedDoesNotExist
38+
frmlist = [b['from_id'] for b in body_list]
39+
# Assume that all of the matches have the same name.
40+
# This is not guaranteed (e.g., a url like '-----------'
41+
# will match several bodies) but is true of well-formed
42+
# inputs.
43+
body = body_list[0]['body_name']
3444
obj['filter'] = {'from_id__in': frmlist}
45+
obj['title'] = 'Liaison Statements from %s' % body
3546
return obj
3647

3748
def title(self, obj):

0 commit comments

Comments
 (0)