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 feeds.views import IndexView
|
||||
from feeds.views import FeedsView, IndexView
|
||||
|
||||
app_name = "feeds"
|
||||
|
||||
urlpatterns = [
|
||||
# /
|
||||
path("", IndexView.as_view(), name="index"),
|
||||
# /feeds
|
||||
path("feeds", FeedsView.as_view(), name="feeds"),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
"""Views for the feeds app.
|
||||
|
||||
/ - Index page
|
||||
|
||||
IndexView - /
|
||||
FeedsView - /feeds
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import typing
|
||||
|
||||
from django.db import connection
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.views.generic.list import ListView
|
||||
|
||||
from feeds.models import Feed
|
||||
|
||||
|
|
@ -26,7 +29,7 @@ def get_database_size() -> int:
|
|||
if not cursor:
|
||||
return 0
|
||||
|
||||
size_in_bytes = cursor.fetchone()[0]
|
||||
size_in_bytes = cursor.fetchone()[0] # type: ignore # noqa: PGH003
|
||||
|
||||
if not size_in_bytes:
|
||||
return 0
|
||||
|
|
@ -40,8 +43,25 @@ class IndexView(TemplateView):
|
|||
template_name = "index.html"
|
||||
|
||||
def get_context_data(self: IndexView, **kwargs: dict) -> dict:
|
||||
"""Get context data."""
|
||||
context = super().get_context_data(**kwargs)
|
||||
"""Add feed count and database size to context data."""
|
||||
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["database_size"] = get_database_size()
|
||||
return context
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue