from typing import TYPE_CHECKING from django.http import HttpResponse from django.shortcuts import get_object_or_404 from feeds.models import Entry from feeds.models import Feed if TYPE_CHECKING: from django.http import HttpRequest from pytest_django.asserts import QuerySet def feed_list(request: HttpRequest) -> HttpResponse: """View to list all feeds. Returns: HttpResponse: An HTML response containing the list of feeds. """ feeds = Feed.objects.all().order_by("id") html = [ "", "FeedVault - Feeds", "

Feed List

", "", "")) return HttpResponse("\n".join(html)) def feed_detail(request: HttpRequest, feed_id: int) -> HttpResponse: """View to display the details of a specific feed. Args: request (HttpRequest): The HTTP request object. feed_id (int): The ID of the feed to display. Returns: HttpResponse: An HTML response containing the feed details and its entries. """ feed: Feed = get_object_or_404(Feed, id=feed_id) entries: QuerySet[Entry, Entry] = Entry.objects.filter(feed=feed).order_by( "-published_at", "-fetched_at", )[:50] html: list[str] = [ "", f"FeedVault - {feed.url}", "

Feed Detail

", f"

URL: {feed.url}

", f"

Domain: {feed.domain}

", f"

Active: {'yes' if feed.is_active else 'no'}

", f"

Created: {feed.created_at}

", f"

Last fetched: {feed.last_fetched_at}

", "

Entries (latest 50)

", "", '

Back to list

', "")) return HttpResponse("\n".join(html))