Add /feeds
This commit is contained in:
parent
c5869024e0
commit
85ae466d3b
4 changed files with 54 additions and 8 deletions
|
|
@ -2,8 +2,13 @@
|
||||||
|
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from feeds.views import IndexView
|
from feeds.views import FeedsView, IndexView
|
||||||
|
|
||||||
|
app_name = "feeds"
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
# /
|
||||||
path("", IndexView.as_view(), name="index"),
|
path("", IndexView.as_view(), name="index"),
|
||||||
|
# /feeds
|
||||||
|
path("feeds", FeedsView.as_view(), name="feeds"),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,16 @@
|
||||||
"""Views for the feeds app.
|
"""Views for the feeds app.
|
||||||
|
|
||||||
/ - Index page
|
IndexView - /
|
||||||
|
FeedsView - /feeds
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import typing
|
||||||
|
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.views.generic.base import TemplateView
|
from django.views.generic.base import TemplateView
|
||||||
|
from django.views.generic.list import ListView
|
||||||
|
|
||||||
from feeds.models import Feed
|
from feeds.models import Feed
|
||||||
|
|
||||||
|
|
@ -26,7 +29,7 @@ def get_database_size() -> int:
|
||||||
if not cursor:
|
if not cursor:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
size_in_bytes = cursor.fetchone()[0]
|
size_in_bytes = cursor.fetchone()[0] # type: ignore # noqa: PGH003
|
||||||
|
|
||||||
if not size_in_bytes:
|
if not size_in_bytes:
|
||||||
return 0
|
return 0
|
||||||
|
|
@ -40,8 +43,25 @@ class IndexView(TemplateView):
|
||||||
template_name = "index.html"
|
template_name = "index.html"
|
||||||
|
|
||||||
def get_context_data(self: IndexView, **kwargs: dict) -> dict:
|
def get_context_data(self: IndexView, **kwargs: dict) -> dict:
|
||||||
"""Get context data."""
|
"""Add feed count and database size to context data."""
|
||||||
context = super().get_context_data(**kwargs)
|
context: dict = super().get_context_data(**kwargs)
|
||||||
|
context["feed_count"] = Feed.objects.count()
|
||||||
|
context["database_size"] = get_database_size()
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
class FeedsView(ListView):
|
||||||
|
"""Feeds page."""
|
||||||
|
|
||||||
|
model = Feed
|
||||||
|
template_name = "feeds.html"
|
||||||
|
context_object_name = "feeds"
|
||||||
|
paginate_by = 100
|
||||||
|
ordering: typing.ClassVar[list[str]] = ["-created_at"]
|
||||||
|
|
||||||
|
def get_context_data(self: FeedsView, **kwargs: dict) -> dict:
|
||||||
|
"""Add feed count and database size to context data."""
|
||||||
|
context: dict = super().get_context_data(**kwargs)
|
||||||
context["feed_count"] = Feed.objects.count()
|
context["feed_count"] = Feed.objects.count()
|
||||||
context["database_size"] = get_database_size()
|
context["database_size"] = get_database_size()
|
||||||
return context
|
return context
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,16 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<span class="title">
|
<span class="title">
|
||||||
<h1>FeedVault</h1>
|
<a href="{% url 'feeds:index' %}">
|
||||||
|
<h1>FeedVault</h1>
|
||||||
|
</a>
|
||||||
</span>
|
</span>
|
||||||
<small>An archive of <a href="https://en.wikipedia.org/wiki/Web_feed">web feeds</a>. Currently archiving {{ feed_count }} feeds. ~{{ database_size|floatformat:2 }} MB of data.</small>
|
<small>An archive of <a href="https://en.wikipedia.org/wiki/Web_feed">web feeds</a>. Currently archiving {{ feed_count }} feeds. ~{{ database_size|floatformat:2 }} MB of data.</small>
|
||||||
<nav>
|
<nav>
|
||||||
<small>
|
<small>
|
||||||
<div class="leftright">
|
<div class="leftright">
|
||||||
<div class="left">
|
<div class="left">
|
||||||
<a href="">Feeds</a> | <a href="">About</a> | <a href="">API</a> | <a href="">Stats</a> | <a href="">GitHub</a> | <a href="">Donate</a>
|
<a href="{% url 'feeds:feeds' %}">Feeds</a> | <a href="">About</a> | <a href="">API</a> | <a href="">Stats</a> | <a href="">GitHub</a> | <a href="">Donate</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="right">
|
<div class="right">
|
||||||
<a href="">Login</a>
|
<a href="">Login</a>
|
||||||
|
|
|
||||||
19
templates/feeds.html
Normal file
19
templates/feeds.html
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}<title>Feeds</title>{% endblock %}
|
||||||
|
{% block description %}FeedVault - A feed archive{% endblock %}
|
||||||
|
{% block keywords %}RSS, Atom, Feed, Archive{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
{% for feed in object_list %}
|
||||||
|
<div class="feed">
|
||||||
|
<h2>
|
||||||
|
<a href="{{ feed.url }}">{{ feed.title }}</a>
|
||||||
|
</h2>
|
||||||
|
<p>{{ feed.description }}</p>
|
||||||
|
<p>
|
||||||
|
<small>Updated {{ feed.updated }}</small>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
{% empty %}
|
||||||
|
<p>No feeds found.</p>
|
||||||
|
{% endfor %}
|
||||||
|
{% endblock %}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue