Add list of domains

This commit is contained in:
Joakim Hellsén 2024-02-23 13:34:40 +01:00
commit 062c80c413
5 changed files with 78 additions and 2 deletions

View file

@ -17,6 +17,8 @@ urlpatterns: list[URLPattern] = [
path(route="add", view=views.AddView.as_view(), name="add"), path(route="add", view=views.AddView.as_view(), name="add"),
path(route="upload", view=views.UploadView.as_view(), name="upload"), 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="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/<int:domain_id>/", view=views.DomainView.as_view(), name="domain"),
] ]
# API urls # API urls

View file

@ -18,7 +18,7 @@ from django.views.generic.edit import CreateView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from feeds.add_feeds import add_feed from feeds.add_feeds import add_feed
from feeds.models import Entry, Feed from feeds.models import Domain, Entry, Feed
if TYPE_CHECKING: if TYPE_CHECKING:
from django.contrib.auth.models import User from django.contrib.auth.models import User
@ -447,3 +447,41 @@ class APIFeedEntriesView(View):
return response 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)

View file

@ -104,7 +104,9 @@
<small> <small>
<div class="leftright"> <div class="leftright">
<div class="left"> <div class="left">
<a href='{% url "feeds:index" %}'>Home</a> | <a href='{% url "feeds:feeds" %}'>Feeds</a> | <a href='{% url "feeds:index" %}'>Home</a> |
<a href='{% url "feeds:domains" %}'>Domains</a> |
<a href='{% url "feeds:feeds" %}'>Feeds</a> |
<a href='{% url "feeds:api" %}'>API</a> <a href='{% url "feeds:api" %}'>API</a>
</div> </div>
<div class="right"> <div class="right">

15
templates/domain.html Normal file
View file

@ -0,0 +1,15 @@
{% extends "base.html" %}
{% block content %}
<h2>{{ domain.url }}</h2>
<p>This domain was added to the database on {{ domain.created_at|date }}.</p>
<p>Feeds for this domain:</p>
<ul>
{% for feed in feeds %}
<li>
<a href="/feed/{{ feed.id }}">{{ feed.feed_url }}</a>
</li>
{% empty %}
<li>Found no feeds for this domain.</li>
{% endfor %}
</ul>
{% endblock %}

19
templates/domains.html Normal file
View file

@ -0,0 +1,19 @@
{% extends "base.html" %}
{% block content %}
<h2>Domains</h2>
<p>
These are the domains that have been added to the database.
{% if domains|length > 0 %}There are {{ domains|length }} domains in the database.{% endif %}
</p>
<ul>
{% for domain in domains %}
{% if not domain.hidden %}
<li>
<a href="/domain/{{ domain.id }}">{{ domain.url }}</a> - {{ domain.created_at|date }}
</li>
{% endif %}
{% empty %}
<li>Found no domains in the database.</li>
{% endfor %}
</ul>
{% endblock %}