From 315251071ce3fe2ae544aa3cf77dd18c07576edf Mon Sep 17 00:00:00 2001 From: Kesara Rathnayake Date: Tue, 18 Jul 2023 00:47:41 +1200 Subject: [PATCH] feat: Use IETF IAB blog feed on the home page Fixes #317 --- ietf/home/models.py | 38 +++++++++++++++------ ietf/home/templates/home/iab_home_page.html | 2 +- ietf/home/templates/includes/post_iab.html | 24 ++----------- ietf/settings/base.py | 5 ++- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/ietf/home/models.py b/ietf/home/models.py index de8eb0a1..fae373b7 100644 --- a/ietf/home/models.py +++ b/ietf/home/models.py @@ -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 @@ -204,6 +206,8 @@ class Meta: index.SearchField("heading"), ] + blog_index_url = settings.IAB_IETF_BLOG_URL + def announcements(self): return ( IABAnnouncementPage.objects.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( diff --git a/ietf/home/templates/home/iab_home_page.html b/ietf/home/templates/home/iab_home_page.html index 29105978..504d2399 100644 --- a/ietf/home/templates/home/iab_home_page.html +++ b/ietf/home/templates/home/iab_home_page.html @@ -46,7 +46,7 @@

Blog posts

All IAB Posts on the IETF Blog diff --git a/ietf/home/templates/includes/post_iab.html b/ietf/home/templates/includes/post_iab.html index 382ba922..2e25e15d 100644 --- a/ietf/home/templates/includes/post_iab.html +++ b/ietf/home/templates/includes/post_iab.html @@ -1,31 +1,13 @@ {% load wagtailimages_tags %}
  • -
    - {% if post.feed_image and show_image %} - {% image post.feed_image height-245 as post_image %} - {{ post.main_image.title }} - {% endif %} -
    {# col-* classes include positioning, position static cancels that and allows the stretched link to cover the image #}
    -

    {{ post.title }}

    -

    {{ post.introduction|truncatechars:250 }}

    +

    {{ post.title }}

    +

    {{ post.description|truncatechars:250 }}

    - {% if post.date %} -

    {{ post.date|date:"DATE_FORMAT" }}

    - {% elif post.start_date %} -

    {{ post.start_date|date:"DATE_FORMAT" }}

    - {% endif %} - - {% if post.listing_location %} -

    {{ post.listing_location }}

    - {% endif %} - - {% if post.host %} -

    {{ post.host.title }}

    - {% endif %} +

    {{ post.published_date|date:"DATE_FORMAT" }}

    diff --git a/ietf/settings/base.py b/ietf/settings/base.py index f0da61f9..0c4cb0a0 100644 --- a/ietf/settings/base.py +++ b/ietf/settings/base.py @@ -244,4 +244,7 @@ "home.IABHomePage", ] -NOTE_WELL_REPO = "https://raw.githubusercontent.com/ietf/note-well/main/note-well.md" \ No newline at end of file +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"