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
21 changes: 13 additions & 8 deletions apps/blogs/templates/blogs/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base.html" %}
{% load boxes %}
{% load boxes cms %}

{% block page_title %}Our Blogs | {{ SITE_INFO.site_name }}{% endblock %}
{% block og_title %}Our Blogs{% endblock %}
Expand Down Expand Up @@ -27,14 +27,9 @@ <h1 class="call-to-action">{{ latest_entry.title }}</h1>
<div class="most-recent-posts">
<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>
<ul class="list-recent-posts menu">

<ul class="menu">
{% for entry in entries %}
<li>
<h3 class="event-title"><a href="{{ entry.url }}">{{ entry.title }}</a></h3>
<p><time datetime="{{ entry.pub_date|date:"Y-m-d" }}">{{ entry.pub_date|date }}</time></p>
</li>
<li>{% iso_time_tag entry.pub_date %} <h3><a href="{{ entry.url }}">{{ entry.title }}</a></h3></li>
{% endfor %}
</ul>
</div>
Expand All @@ -44,6 +39,16 @@ <h3 class="event-title"><a href="{{ entry.url }}">{{ entry.title }}</a></h3>
{% box 'blogs-subscriptions' %}
</div>

<div class="small-widget news-sources-widget last">
<h2 class="widget-title">News Sources</h2>
<ul class="menu">
<li><a href="https://blog.python.org/">Python Insider</a></li>
<li><a href="https://pyfound.blogspot.com/">PSF Blog</a></li>
<li><a href="https://pycon.blogspot.com/">PyCon Blog</a></li>
<li><a href="https://planetpython.org/">Planet Python</a></li>
</ul>
</div>

<div class="small-widget copyright-widget last">
{% box 'blogs-copyright' %}
</div>
Expand Down
38 changes: 38 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 as dt

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,38 @@ 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)")

def test_blog_home_links_news_sources_instead_of_more(self):
"""The page already aggregates every source, so it links to each one rather than a single "More" page."""
resp = self.client.get(reverse("blog"))
self.assertNotContains(resp, 'class="give-me-more"')
for url in (
"https://blog.python.org/",
"https://pyfound.blogspot.com/",
"https://pycon.blogspot.com/",
"https://planetpython.org/",
):
self.assertContains(resp, f'href="{url}"')


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 - dt.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)
# Pin the concrete count too, so reverting the constant is caught.
self.assertEqual(len(resp.context["entries"]), 14)
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 = 15


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
6 changes: 4 additions & 2 deletions static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2287,8 +2287,10 @@ p.quote-by-organization {
.latest-blog-post .readmore:hover, .latest-blog-post .readmore:focus, .featured-event .readmore:hover, .featured-event .readmore:focus {
color: white; }

.most-recent-posts li time {
position: relative; }
.most-recent-posts li h3 {
font-size: 1.125em;
line-height: 1.4em;
margin: 0; }

/* ! ===== Events landing page ===== */
/*h3*/
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' %}">More news</a></p>

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