Commit 7d13f0b5 authored by Yohan's avatar Yohan
Browse files

Order content by modified_at desc on blog index page (fix #368)

parent 1a6dedf5
from datetime import date
from datetime import date, datetime
import pytest
......@@ -25,6 +25,23 @@ def test_only_published_should_be_in_index(app, published, draft, deleted,
assert published_in_the_future.title not in response.content.decode()
def test_content_are_ordered_by_last_modified(app):
content3 = ContentFactory(status=Content.PUBLISHED)
content1 = ContentFactory(status=Content.PUBLISHED)
content2 = ContentFactory(status=Content.PUBLISHED)
Content.objects.filter(pk=content1.pk).update(modified_at=datetime(2016, 6,
26, 16, 17))
Content.objects.filter(pk=content2.pk).update(modified_at=datetime(2016, 6,
26, 16, 16))
Content.objects.filter(pk=content3.pk).update(modified_at=datetime(2016, 6,
26, 16, 15))
response = app.get(reverse('blog:index'))
titles = response.pyquery.find('.card.blog h3')
assert titles[0].text == content1.title
assert titles[1].text == content2.title
assert titles[2].text == content3.title
def test_index_page_is_paginated(app, monkeypatch):
monkeypatch.setattr(Index, 'paginate_by', 2)
ContentFactory.create_batch(size=4, status=Content.PUBLISHED)
......
......@@ -9,7 +9,7 @@ from .models import Content
class Index(FilterableViewMixin, ListView):
model = Content
queryset = Content.objects.published()
queryset = Content.objects.published().order_by('-modified_at')
template_name = 'blog/index.html'
paginate_by = 10
......
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