Skip to content

Commit

Permalink
feat: Use IETF IAB blog feed on the home page
Browse files Browse the repository at this point in the history
Fixes #317
  • Loading branch information
kesara committed Jul 17, 2023
1 parent 360e8b9 commit 3152510
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 34 deletions.
38 changes: 27 additions & 11 deletions ietf/home/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from __future__ import unicode_literals

from datetime import datetime
from xml.etree import ElementTree

from django.conf import settings
from django.db import models
from django.db.models.expressions import RawSQL
from modelcluster.fields import ParentalKey
from requests import get as get_request
from wagtail.admin.panels import FieldPanel, InlinePanel, MultiFieldPanel
from wagtail.models import Page
from wagtail.search import index
Expand Down Expand Up @@ -204,6 +206,8 @@ class Meta:
index.SearchField("heading"),
]

blog_index_url = settings.IAB_IETF_BLOG_URL

def announcements(self):
return (
IABAnnouncementPage.objects.all()
Expand All @@ -218,17 +222,29 @@ def blog_index(self):
return BlogIndexPage.objects.live().first()

def blogs(self, bp_kwargs={}):
return (
BlogPage.objects.live()
.filter(topics__topic__slug="iab")
.annotate(
date_sql=RawSQL(
"CASE WHEN (date_published IS NOT NULL) THEN date_published ELSE first_published_at END",
(),
)
)
.order_by("-date_sql")[:2]
)
entries = []
try:
response = get_request(settings.IAB_FEED_URL)
xml_data = response.text

root = ElementTree.fromstring(xml_data)
for item in root.iter('item'):
title = item.find('title').text
description = item.find('description').text
link = item.find('link').text
published_date = datetime.strptime(item.find('pubDate').text, '%a, %d %b %Y %H:%M:%S %z')

entry_data = {
'title': title,
'description': description,
'link': link,
'published_date': published_date,
}
entries.append(entry_data)
except Exception as _:
pass

return entries

content_panels = Page.content_panels + [
MultiFieldPanel(
Expand Down
2 changes: 1 addition & 1 deletion ietf/home/templates/home/iab_home_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h2 class="mb-4">Blog posts</h2>
</ul>
<a
class="btn iab-btn-secondary text-white"
href="{{ self.blog_index.url }}iab/"
href="{{ self.blog_index_url }}"
>All IAB Posts on the IETF Blog</a
>
</section>
Expand Down
24 changes: 3 additions & 21 deletions ietf/home/templates/includes/post_iab.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
{% load wagtailimages_tags %}

<li class="card mb-4 row g-0 align-items-stretch iab-blog-post">
<div>
{% if post.feed_image and show_image %}
{% image post.feed_image height-245 as post_image %}
<img class="blog-post-image-iab u-obj-cover w-100 h-100" src="{{ post_image.url }}" alt="{{ post.main_image.title }}">
{% endif %}
</div>
{# col-* classes include positioning, position static cancels that and allows the stretched link to cover the image #}
<div class="card-body card-body--iab">
<h3 class="mb-3 h5"><a class="stretched-link" href="{{ post.url }}">{{ post.title }}</a></h3>
<p class="iab-card-text">{{ post.introduction|truncatechars:250 }}</p>
<h3 class="mb-3 h5"><a class="stretched-link" href="{{ post.link }}">{{ post.title }}</a></h3>
<p class="iab-card-text">{{ post.description|truncatechars:250 }}</p>
<div class="d-flex justify-content-between align-items-center iab-date-text">
<small>
{% if post.date %}
<p>{{ post.date|date:"DATE_FORMAT" }}</p>
{% elif post.start_date %}
<p>{{ post.start_date|date:"DATE_FORMAT" }}</p>
{% endif %}

{% if post.listing_location %}
<p>{{ post.listing_location }}</p>
{% endif %}

{% if post.host %}
<p>{{ post.host.title }}</p>
{% endif %}
<p>{{ post.published_date|date:"DATE_FORMAT" }}</p>
</small>
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion ietf/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,7 @@
"home.IABHomePage",
]

NOTE_WELL_REPO = "https://raw.githubusercontent.com/ietf/note-well/main/note-well.md"
IAB_FEED_URL = "https://www.ietf.org/blog/iab/feed"
IAB_IETF_BLOG_URL = "https://www.ietf.org/blog/iab/"

NOTE_WELL_REPO = "https://raw.githubusercontent.com/ietf/note-well/main/note-well.md"

0 comments on commit 3152510

Please sign in to comment.