Move views and add feeds

This commit is contained in:
Gabriel Augendre 2020-08-16 19:24:31 +02:00
parent 9a50fa408f
commit 17d2e7aa2e
6 changed files with 36 additions and 5 deletions

View file

@ -5,6 +5,7 @@
<meta charset="UTF-8">
<title>Gab's Notes</title>
<link rel="stylesheet" href="{% static 'style.css' %}" type="text/css">
<link rel="alternate" type="application/rss+xml" title="Gab's Notes » Feed" href="https://gabnotes.org/feed/">
</head>
<body>
<nav>

View file

24
articles/views/feeds.py Normal file
View file

@ -0,0 +1,24 @@
from django.contrib.syndication.views import Feed
from articles.models import Article
from blog import settings
class CompleteFeed(Feed):
title = "Gab's Notes"
link = settings.BLOG["base_url"]
description = settings.BLOG["description"]
def items(self):
return Article.objects.filter(status=Article.PUBLISHED).order_by(
"-published_at"
)[:15]
def item_title(self, item: Article):
return item.title
def item_description(self, item: Article):
return item.get_formatted_content()
def item_pubdate(self, item: Article):
return item.published_at

View file

@ -115,3 +115,8 @@ USE_TZ = True
STATIC_URL = "/static/"
AUTH_USER_MODEL = "articles.User"
BLOG = {
"description": "My take on tech-related subjects (but not only)",
"base_url": "https://gabnotes.org/",
}

View file

@ -16,11 +16,12 @@ Including another URLconf
from django.contrib import admin
from django.urls import path
from articles import views
from articles.views import feeds, html
urlpatterns = [
path("admin/", admin.site.urls),
path("", views.ArticlesListView.as_view(), name="articles-list"),
path("drafts/", views.DraftsListView.as_view(), name="drafts-list"),
path("<int:pk>", views.ArticleDetailView.as_view(), name="article-detail"),
path("", html.ArticlesListView.as_view(), name="articles-list"),
path("drafts/", html.DraftsListView.as_view(), name="drafts-list"),
path("<int:pk>", html.ArticleDetailView.as_view(), name="article-detail"),
path("feed/", feeds.CompleteFeed(), name="complete-feed"),
]