from __future__ import annotations import html import json from typing import TYPE_CHECKING from django.http import HttpResponse from django.shortcuts import get_object_or_404 from django.shortcuts import redirect from django.shortcuts import render 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") return render(request, "feeds/feed_list.html", {"feeds": feeds}) 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"
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}
", "{escaped_json}"
else:
entry_data_html: str = "[No data]
" html_lines: list[str] = [ "", f"Feed: {feed.url}
", f"Entry ID: {entry.entry_id}
", f"Published: {entry.published_at}
", f"Fetched: {entry.fetched_at}
", f"Content Hash: {entry.content_hash}
", f"Error Message: {entry.error_message or '[none]'}
", "