diff --git a/feeds/urls.py b/feeds/urls.py index 0f2dfcb..21cb99d 100644 --- a/feeds/urls.py +++ b/feeds/urls.py @@ -17,6 +17,8 @@ urlpatterns: list[URLPattern] = [ path(route="add", view=views.AddView.as_view(), name="add"), path(route="upload", view=views.UploadView.as_view(), name="upload"), path(route="robots.txt", view=cache_page(timeout=60 * 60 * 365)(views.RobotsView.as_view()), name="robots"), + path(route="domains/", view=views.DomainsView.as_view(), name="domains"), + path(route="domain//", view=views.DomainView.as_view(), name="domain"), ] # API urls diff --git a/feeds/views.py b/feeds/views.py index 3a5908b..dc1cd36 100644 --- a/feeds/views.py +++ b/feeds/views.py @@ -18,7 +18,7 @@ from django.views.generic.edit import CreateView from django.views.generic.list import ListView from feeds.add_feeds import add_feed -from feeds.models import Entry, Feed +from feeds.models import Domain, Entry, Feed if TYPE_CHECKING: from django.contrib.auth.models import User @@ -447,3 +447,41 @@ class APIFeedEntriesView(View): return response + +class DomainsView(View): + """All domains.""" + + def get(self, request: HttpRequest) -> HttpResponse: + """Load the domains page.""" + domains = Domain.objects.all() + template = loader.get_template(template_name="domains.html") + context = { + "domains": domains, + "description": "Domains", + "keywords": "feed, rss, atom, archive, rss list", + "author": "TheLovinator", + "canonical": "https://feedvault.se/domains/", + "title": "Domains", + } + return HttpResponse(content=template.render(context=context, request=request)) + + +class DomainView(View): + """A single domain.""" + + def get(self, request: HttpRequest, domain_id: int) -> HttpResponse: + """Load the domain page.""" + domain = get_object_or_404(Domain, id=domain_id) + feeds = Feed.objects.filter(domain=domain).order_by("-created_at")[:100] + + context = { + "domain": domain, + "feeds": feeds, + "description": f"Archive of {domain.name}", + "keywords": "feed, rss, atom, archive, rss list", + "author": "TheLovinator", + "canonical": f"https://feedvault.se/domain/{domain_id}/", + "title": f"{domain.name} - FeedVault", + } + + return render(request, "domain.html", context) diff --git a/templates/base.html b/templates/base.html index bf5402d..ef695a6 100644 --- a/templates/base.html +++ b/templates/base.html @@ -104,7 +104,9 @@
- Home | Feeds | + Home | + Domains | + Feeds | API
diff --git a/templates/domain.html b/templates/domain.html new file mode 100644 index 0000000..6fe780a --- /dev/null +++ b/templates/domain.html @@ -0,0 +1,15 @@ +{% extends "base.html" %} +{% block content %} +

{{ domain.url }}

+

This domain was added to the database on {{ domain.created_at|date }}.

+

Feeds for this domain:

+
    + {% for feed in feeds %} +
  • + {{ feed.feed_url }} +
  • + {% empty %} +
  • Found no feeds for this domain.
  • + {% endfor %} +
+{% endblock %} diff --git a/templates/domains.html b/templates/domains.html new file mode 100644 index 0000000..ce4ff2c --- /dev/null +++ b/templates/domains.html @@ -0,0 +1,19 @@ +{% extends "base.html" %} +{% block content %} +

Domains

+

+ These are the domains that have been added to the database. + {% if domains|length > 0 %}There are {{ domains|length }} domains in the database.{% endif %} +

+
    + {% for domain in domains %} + {% if not domain.hidden %} +
  • + {{ domain.url }} - {{ domain.created_at|date }} +
  • + {% endif %} + {% empty %} +
  • Found no domains in the database.
  • + {% endfor %} +
+{% endblock %}