Skip to content

Commit 0f065f2

Browse files
committed
Fixed a bug when not specifying a limit when using the more_like_this template tag. Thanks to symroe for the original patch.
1 parent 74fc093 commit 0f065f2

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ Thanks to
4141
* piquadrat for a patch regarding the more_like_this template tag.
4242
* dedsm for a patch regarding the pickling of SearchResult objects.
4343
* EmilStenstrom for a patch to the Highlighter.
44+
* symroe for a patch regarding the more_like_this template tag.

haystack/templatetags/more_like_this.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ def __init__(self, model, varname, for_types=None, limit=None):
1111
self.model = template.Variable(model)
1212
self.varname = varname
1313
self.for_types = for_types
14-
self.limit = int(limit)
14+
self.limit = limit
15+
16+
if not self.limit is None:
17+
self.limit = int(self.limit)
1518

1619
def render(self, context):
1720
try:

tests/solr_tests/tests/templatetags.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,11 @@ def test_more_like_this_with_limit(self):
5353
'entry': mock,
5454
}
5555
self.assertEqual(self.render(template, context), u'core.mockmodel.2 core.mockmodel.18 core.mockmodel.23 core.mockmodel.15 core.mockmodel.21 ')
56+
57+
def test_more_like_this_without_limit(self):
58+
mock = MockModel.objects.get(pk=3)
59+
template = """{% load more_like_this %}{% more_like_this entry as related_content %}{% for rc in related_content %}{{ rc.id }} {% endfor %}"""
60+
context = {
61+
'entry': mock,
62+
}
63+
self.assertEqual(self.render(template, context), u'core.mockmodel.2 core.mockmodel.18 core.mockmodel.23 core.mockmodel.15 core.mockmodel.21 core.mockmodel.13 core.mockmodel.17 core.mockmodel.16 core.mockmodel.20 core.mockmodel.1 core.mockmodel.22 core.mockmodel.19 core.mockmodel.8 core.mockmodel.6 core.mockmodel.4 core.mockmodel.11 core.mockmodel.14 core.mockmodel.12 core.mockmodel.9 core.mockmodel.7 core.mockmodel.10 core.mockmodel.5 ')

0 commit comments

Comments
 (0)