Use templates
This commit is contained in:
parent
08dbefa417
commit
297b95a3a8
4 changed files with 65 additions and 12 deletions
|
|
@ -10,7 +10,8 @@ if TYPE_CHECKING:
|
||||||
|
|
||||||
|
|
||||||
urlpatterns: list[URLPattern | URLResolver] = [
|
urlpatterns: list[URLPattern | URLResolver] = [
|
||||||
path("", views.feed_list, name="feed-list"),
|
path("", views.home, name="home"),
|
||||||
|
path("feeds/", views.feed_list, name="feed-list"),
|
||||||
path("feeds/<int:feed_id>/", views.feed_detail, name="feed-detail"),
|
path("feeds/<int:feed_id>/", views.feed_detail, name="feed-detail"),
|
||||||
path(
|
path(
|
||||||
"feeds/<int:feed_id>/entries/<int:entry_id>/",
|
"feeds/<int:feed_id>/entries/<int:entry_id>/",
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import html
|
import html
|
||||||
import json
|
import json
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.shortcuts import get_object_or_404
|
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 Entry
|
||||||
from feeds.models import Feed
|
from feeds.models import Feed
|
||||||
|
|
@ -20,17 +24,7 @@ def feed_list(request: HttpRequest) -> HttpResponse:
|
||||||
HttpResponse: An HTML response containing the list of feeds.
|
HttpResponse: An HTML response containing the list of feeds.
|
||||||
"""
|
"""
|
||||||
feeds = Feed.objects.all().order_by("id")
|
feeds = Feed.objects.all().order_by("id")
|
||||||
html = [
|
return render(request, "feeds/feed_list.html", {"feeds": feeds})
|
||||||
"<!DOCTYPE html>",
|
|
||||||
"<html><head><title>FeedVault - Feeds</title></head><body>",
|
|
||||||
"<h1>Feed List</h1>",
|
|
||||||
"<ul>",
|
|
||||||
]
|
|
||||||
html.extend(
|
|
||||||
f'<li><a href="/feeds/{feed.pk}/">{feed.url}</a></li>' for feed in feeds
|
|
||||||
)
|
|
||||||
html.extend(("</ul>", "</body></html>"))
|
|
||||||
return HttpResponse("\n".join(html))
|
|
||||||
|
|
||||||
|
|
||||||
def feed_detail(request: HttpRequest, feed_id: int) -> HttpResponse:
|
def feed_detail(request: HttpRequest, feed_id: int) -> HttpResponse:
|
||||||
|
|
@ -115,3 +109,15 @@ def entry_detail(request: HttpRequest, feed_id: int, entry_id: int) -> HttpRespo
|
||||||
"</body></html>",
|
"</body></html>",
|
||||||
]
|
]
|
||||||
return HttpResponse("\n".join(html_lines))
|
return HttpResponse("\n".join(html_lines))
|
||||||
|
|
||||||
|
|
||||||
|
def home(request: HttpRequest) -> HttpResponse:
|
||||||
|
"""Redirect to the feed list as the homepage.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request: The HTTP request object.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
HttpResponse: A redirect response to the feed list.
|
||||||
|
"""
|
||||||
|
return redirect("/feeds/")
|
||||||
|
|
|
||||||
35
templates/base.html
Normal file
35
templates/base.html
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<meta name="keywords" content="feeds, archive, FeedVault" />
|
||||||
|
<title>
|
||||||
|
{% block title %}
|
||||||
|
FeedVault
|
||||||
|
{% endblock title %}
|
||||||
|
</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<h1>FeedVault</h1>
|
||||||
|
<nav>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'home' %}">Home</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'feed-list' %}">Feeds</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
<main>
|
||||||
|
{% block content %}
|
||||||
|
{% endblock content %}
|
||||||
|
</main>
|
||||||
|
<footer>
|
||||||
|
<p>Web scraping is not a crime. - No rights reserved. - A birthday present for Plipp ❤️</p>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
11
templates/feeds/feed_list.html
Normal file
11
templates/feeds/feed_list.html
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% block content %}
|
||||||
|
<h1>Feed List</h1>
|
||||||
|
<ul>
|
||||||
|
{% for feed in feeds %}
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'feed-detail' feed.pk %}">{{ feed.url }}</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endblock content %}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue