Commit 84b6db7c by Tim Babych Committed by Oleg Marshev

sorting

parent 16a89a6e
......@@ -310,20 +310,20 @@ class AnnotationViewTests(BaseAnnotationViewTests):
self.assertEqual(len(results['rows']), 1)
self.assertEqual(results['rows'][0]['text'], 'Second note')
# def test_search_ordering(self):
# """
# Tests ordering of search results.
def test_search_ordering(self):
"""
Tests ordering of search results.
# Sorting is by descending order (most recent first).
# """
# note_1 = self._create_annotation(text=u'First one')
# note_2 = self._create_annotation(text=u'Second note')
# note_3 = self._create_annotation(text=u'Third note')
# results = self._get_search_results()
# self.assertEqual(results['rows'][0]['text'], 'Third note')
# self.assertEqual(results['rows'][1]['text'], 'Second note')
# self.assertEqual(results['rows'][2]['text'], 'First one')
Sorting is by descending order (most recent first).
"""
note_1 = self._create_annotation(text=u'First one')
note_2 = self._create_annotation(text=u'Second note')
note_3 = self._create_annotation(text=u'Third note')
results = self._get_search_results()
self.assertEqual(results['rows'][0]['text'], 'Third note')
self.assertEqual(results['rows'][1]['text'], 'Second note')
self.assertEqual(results['rows'][2]['text'], 'First one')
def test_read_all_no_annotations(self):
"""
......
......@@ -26,7 +26,7 @@ class AnnotationSearchView(APIView):
for k, v in self.request.QUERY_PARAMS.dict().items():
params[k] = v.lower()
results = NoteMappingType.process_result(
list(note_searcher.filter(**params).values_dict("_source"))
list(note_searcher.filter(**params).order_by("-created").values_dict("_source"))
)
return Response({'total': len(results), 'rows': results})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment