80 lines
2.7 KiB
Python
80 lines
2.7 KiB
Python
"""
|
|
RSS Feeds for the Servala website
|
|
"""
|
|
|
|
from django.contrib.syndication.views import Feed
|
|
from django.urls import reverse
|
|
from django.utils.feedgenerator import Rss201rev2Feed
|
|
from django.utils.html import strip_tags
|
|
from django.conf import settings
|
|
|
|
from .models import Article
|
|
|
|
|
|
class ArticleRSSFeed(Feed):
|
|
"""RSS feed for published articles"""
|
|
|
|
title = "Servala Articles"
|
|
link = "/articles/"
|
|
description = "Latest articles about cloud services, consulting partners, and technology insights from Servala"
|
|
feed_type = Rss201rev2Feed
|
|
|
|
def items(self):
|
|
"""Return the latest 20 published articles"""
|
|
return Article.objects.filter(is_published=True).order_by("-article_date")[:20]
|
|
|
|
def item_title(self, item):
|
|
"""Return the article title"""
|
|
return item.title
|
|
|
|
def item_description(self, item):
|
|
"""Return the article excerpt with 'Read more' link"""
|
|
base_url = "https://servala.com"
|
|
|
|
# Use the excerpt and add a proper HTML read more link
|
|
excerpt = strip_tags(item.excerpt)
|
|
article_url = f"{base_url}{item.get_absolute_url()}"
|
|
|
|
# Return HTML content for the RSS description
|
|
return f'{excerpt} <a href="{article_url}">Read more...</a>'
|
|
|
|
def item_link(self, item):
|
|
"""Return the link to the article detail page"""
|
|
return item.get_absolute_url()
|
|
|
|
def item_guid(self, item):
|
|
"""Return a unique identifier for the item"""
|
|
return f"article-{item.id}"
|
|
|
|
def item_pubdate(self, item):
|
|
"""Return the publication date"""
|
|
# Convert date to datetime for RSS compatibility
|
|
from datetime import datetime, time
|
|
from django.utils import timezone
|
|
|
|
# Combine the date with midnight time and make it timezone-aware
|
|
dt = datetime.combine(item.article_date, time.min)
|
|
return timezone.make_aware(dt, timezone.get_current_timezone())
|
|
|
|
def item_author_name(self, item):
|
|
"""Return the author name"""
|
|
return item.author.get_full_name() or item.author.username
|
|
|
|
def item_categories(self, item):
|
|
"""Return categories for the article"""
|
|
categories = []
|
|
|
|
# Add related entity as category
|
|
if item.related_service:
|
|
categories.append(f"Service: {item.related_service.name}")
|
|
if item.related_consulting_partner:
|
|
categories.append(f"Partner: {item.related_consulting_partner.name}")
|
|
if item.related_cloud_provider:
|
|
categories.append(f"Provider: {item.related_cloud_provider.name}")
|
|
|
|
# Add meta keywords as categories if available
|
|
if item.meta_keywords:
|
|
keywords = [keyword.strip() for keyword in item.meta_keywords.split(",")]
|
|
categories.extend(keywords)
|
|
|
|
return categories
|