Update post ordering for categories
By (descending) publication and rule name
This commit is contained in:
parent
a99e3c1980
commit
35d848401e
3 changed files with 10 additions and 7 deletions
|
|
@ -27,7 +27,11 @@ export const filterPostsByCategory = (category = {}, rules = [], posts = []) =>
|
|||
return filteredPosts.map(post => ({ ...post, rule: { ...rule } }));
|
||||
});
|
||||
|
||||
return filteredData.length > 0 ? [...filteredData.flat()] : [];
|
||||
const sortedPosts = [...filteredData.flat()].sort((firstPost, secondPost) => {
|
||||
return new Date(secondPost.publicationDate) - new Date(firstPost.publicationDate);
|
||||
});
|
||||
|
||||
return sortedPosts;
|
||||
};
|
||||
|
||||
export const filterPosts = state => {
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class NestedPostCategoryView(ListAPIView):
|
|||
|
||||
queryset = Post.objects.filter(
|
||||
rule__in=category.rules.values_list("id", flat=True)
|
||||
).order_by("rule", "-publication_date")
|
||||
).order_by("-publication_date", "rule__name")
|
||||
|
||||
return queryset
|
||||
|
||||
|
|
|
|||
|
|
@ -498,13 +498,12 @@ class NestedCategoryPostView(TestCase):
|
|||
self.assertEquals(data["count"], 6)
|
||||
|
||||
self.assertEquals(posts[0]["title"], "Second BBC post")
|
||||
self.assertEquals(posts[1]["title"], "First BBC post")
|
||||
|
||||
self.assertEquals(posts[1]["title"], "Second Reuters post")
|
||||
self.assertEquals(posts[2]["title"], "Second Guardian post")
|
||||
self.assertEquals(posts[3]["title"], "First Guardian post")
|
||||
|
||||
self.assertEquals(posts[4]["title"], "Second Reuters post")
|
||||
self.assertEquals(posts[5]["title"], "First Reuters post")
|
||||
self.assertEquals(posts[3]["title"], "First BBC post")
|
||||
self.assertEquals(posts[4]["title"], "First Reuters post")
|
||||
self.assertEquals(posts[5]["title"], "First Guardian post")
|
||||
|
||||
def test_only_posts_from_category_are_returned(self):
|
||||
category = CategoryFactory.create(user=self.user)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue