Skip to content

Commit

Permalink
Merge pull request #208 from praekelt/feature/issue-197-faq-translati…
Browse files Browse the repository at this point in the history
…ons-dont-appear-with-labels-on-the-reply-modal

Issue 197 faq translations dont appear with labels on the reply modal
  • Loading branch information
rowanseymour committed Nov 30, 2016
2 parents c16c62f + 57a2486 commit 61c338c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions casepro/msgs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def search(cls, org, user, search):
if text:
queryset = queryset.filter(Q(question__icontains=text) | Q(answer__icontains=text))

queryset = queryset.prefetch_related('labels')
queryset = queryset.prefetch_related('labels', 'parent__labels')

return queryset.order_by('question')

Expand Down Expand Up @@ -266,13 +266,14 @@ def as_json(self, full=True):
if full:
if not self.parent:
parent_json = None
result['labels'] = [l.as_json() for l in self.labels.all()]
else:
parent_json = self.parent.id
result['labels'] = [l.as_json() for l in self.parent.labels.all()]

result['answer'] = self.answer
result['language'] = self.get_language()
result['parent'] = parent_json
result['labels'] = [l.as_json() for l in self.labels.all()]

return result

Expand Down
4 changes: 3 additions & 1 deletion casepro/msgs/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,9 @@ def test_search(self):
# log in as a non-administrator
self.login(self.user1)

response = self.url_get('unicef', url, {})
# check that appropriate number of queries are executed
with self.assertNumQueries(28):
response = self.url_get('unicef', url, {})
# should have 4 results as one is label restricted
self.assertEqual(len(response.json['results']), 4)

Expand Down

0 comments on commit 61c338c

Please sign in to comment.