Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions apps/blogs/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import datetime

from django.core.management import call_command
from django.test import TestCase
from django.urls import reverse
from django.utils import timezone

from apps.blogs.models import BlogEntry, Feed
from apps.blogs.tests.utils import get_test_rss_path
from apps.blogs.views import ENTRY_LIST_LIMIT


class BlogViewTest(TestCase):
Expand Down Expand Up @@ -38,3 +41,24 @@ def test_blog_home_escapes_excerpt(self):
resp = self.client.get(reverse("blog"))
self.assertNotContains(resp, "<img src=x onerror=alert(1)")
self.assertContains(resp, "&lt;img src=x onerror=alert(1)")


class BlogHomeEntryCountTest(TestCase):
"""The blog page shows ENTRY_LIST_LIMIT entries: one header plus the list."""

def test_page_shows_the_limit_with_the_newest_in_the_header(self):
feed = Feed.objects.create(name="test", website_url="http://example.org", feed_url="http://example.org/feed")
now = timezone.now()
for index in range(ENTRY_LIST_LIMIT + 5):
BlogEntry.objects.create(
title=f"Post {index}",
summary="",
pub_date=now - datetime.timedelta(days=index),
url=f"http://example.org/post/{index}",
feed=feed,
)

resp = self.client.get(reverse("blog"))

self.assertEqual(resp.context["latest_entry"].title, "Post 0")
self.assertEqual(len(resp.context["entries"]), ENTRY_LIST_LIMIT - 1)
6 changes: 5 additions & 1 deletion apps/blogs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

from apps.blogs.models import BlogEntry

# Number of entries the page shows. The newest one goes in the page
# header, the rest go in the "Latest News" list.
ENTRY_LIST_LIMIT = 10


class BlogHome(TemplateView):
"""Main blog view."""
Expand All @@ -14,7 +18,7 @@ def get_context_data(self, **kwargs):
"""Return the latest blog entries for the blog homepage."""
context = super().get_context_data(**kwargs)

entries = BlogEntry.objects.order_by("-pub_date")[:6]
entries = BlogEntry.objects.order_by("-pub_date")[:ENTRY_LIST_LIMIT]
latest_entry = None
other_entries = []

Expand Down
4 changes: 2 additions & 2 deletions fixtures/boxes.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,9 @@
"created": "2014-02-13T18:27:05.680Z",
"updated": "2014-07-20T16:51:28.177Z",
"label": "blogs-copyright",
"content": "<h2 class=\"widget-title\">Copyright</h2>\r\n<p>Python Insider by the Python Core Developers is licensed under a <a href=\"https://creativecommons.org/licenses/by-nc-sa/3.0/us/\">Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License</a>. Based on a work at <a href=\"http://blog.python.org\">blog.python.org</a>.</p>",
"content": "<h2 class=\"widget-title\">Copyright</h2>\r\n<p>Python Insider by the Python core team is licensed under a <a href=\"https://creativecommons.org/licenses/by-nc-sa/3.0/us/\">Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License</a>. Based on a work at <a href=\"https://blog.python.org\">blog.python.org</a>.</p>",
"content_markup_type": "html",
"_content_rendered": "<h2 class=\"widget-title\">Copyright</h2>\r\n<p>Python Insider by the Python Core Developers is licensed under a <a href=\"https://creativecommons.org/licenses/by-nc-sa/3.0/us/\">Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License</a>. Based on a work at <a href=\"http://blog.python.org\">blog.python.org</a>.</p>"
"_content_rendered": "<h2 class=\"widget-title\">Copyright</h2>\r\n<p>Python Insider by the Python core team is licensed under a <a href=\"https://creativecommons.org/licenses/by-nc-sa/3.0/us/\">Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License</a>. Based on a work at <a href=\"https://blog.python.org\">blog.python.org</a>.</p>"
}
},
{
Expand Down
46 changes: 35 additions & 11 deletions fixtures/sitetree_menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@
"fields": {
"title": "PSF Blog",
"hint": "",
"url": "http://pyfound.blogspot.com/",
"url": "https://pyfound.blogspot.com/",
"urlaspattern": false,
"tree": 1,
"hidden": false,
Expand Down Expand Up @@ -2076,13 +2076,13 @@
"pk": 96,
"fields": {
"title": "Python News",
"hint": "Python Insider Blog Posts",
"hint": "Python news and blog posts",
"url": "blog",
"urlaspattern": true,
"tree": 1,
"hidden": false,
"alias": null,
"description": "Python Insider is the blog used by the Python Core Developers to announce news related to the Python programming language.",
"description": "News about the Python programming language, including posts from Python Insider, the blog of the Python core team.",
"inmenu": true,
"inbreadcrumbs": true,
"insitetree": true,
Expand All @@ -2095,13 +2095,37 @@
"access_permissions": []
}
},
{
"model": "sitetree.treeitem",
"pk": 126,
"fields": {
"title": "Python Insider",
"hint": "News and updates from the Python core team",
"url": "https://blog.python.org/",
"urlaspattern": false,
"tree": 1,
"hidden": false,
"alias": null,
"description": "Python Insider carries news and updates from the Python core team.",
"inmenu": true,
"inbreadcrumbs": true,
"insitetree": true,
"access_loggedin": false,
"access_guest": false,
"access_restricted": false,
"access_perm_type": 1,
"parent": 12,
"sort_order": 97,
"access_permissions": []
}
},
{
"model": "sitetree.treeitem",
"pk": 97,
"fields": {
"title": "PSF News",
"hint": "PSF Blog",
"url": "http://pyfound.blogspot.com/",
"url": "https://pyfound.blogspot.com/",
"urlaspattern": false,
"tree": 1,
"hidden": false,
Expand All @@ -2115,7 +2139,7 @@
"access_restricted": false,
"access_perm_type": 1,
"parent": 12,
"sort_order": 98,
"sort_order": 99,
"access_permissions": []
}
},
Expand All @@ -2125,7 +2149,7 @@
"fields": {
"title": "Community News",
"hint": "Planet Python",
"url": "http://planetpython.org/",
"url": "https://planetpython.org/",
"urlaspattern": false,
"tree": 1,
"hidden": false,
Expand All @@ -2139,7 +2163,7 @@
"access_restricted": false,
"access_perm_type": 1,
"parent": 12,
"sort_order": 97,
"sort_order": 98,
"access_permissions": []
}
},
Expand All @@ -2149,7 +2173,7 @@
"fields": {
"title": "PyCon News",
"hint": "PyCon Blog",
"url": "http://pycon.blogspot.com/",
"url": "https://pycon.blogspot.com/",
"urlaspattern": false,
"tree": 1,
"hidden": false,
Expand All @@ -2163,7 +2187,7 @@
"access_restricted": false,
"access_perm_type": 1,
"parent": 12,
"sort_order": 99,
"sort_order": 100,
"access_permissions": []
}
},
Expand Down Expand Up @@ -2389,7 +2413,7 @@
"fields": {
"title": "Self-certify as voting member",
"hint": "",
"url": "http://pyfound.blogspot.de/2015/02/enroll-as-psf-voting-member.html",
"url": "https://pyfound.blogspot.com/2015/02/enroll-as-psf-voting-member.html",
"urlaspattern": false,
"tree": 1,
"hidden": false,
Expand Down Expand Up @@ -2509,7 +2533,7 @@
"fields": {
"title": "Python Brochure",
"hint": "",
"url": "http://brochure.getpython.info/",
"url": "https://brochure.getpython.info/",
"urlaspattern": false,
"tree": 1,
"hidden": false,
Expand Down
2 changes: 1 addition & 1 deletion templates/components/blog-posts.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="shrubbery">

<h2 class="widget-title"><span aria-hidden="true" class="icon-news"></span>Latest News</h2>
<p class="give-me-more"><a href="{{ BLOG_URL }}" title="More News">More</a></p>
<p class="give-me-more"><a href="{% url 'blog' %}" title="More News">More</a></p>

<ul class="menu">
{% get_latest_blog_entries limit=5 as entries %}
Expand Down