Move back to Python 🙃
This commit is contained in:
parent
f9d4ea8d4f
commit
d7be14f5a2
60 changed files with 757 additions and 5605 deletions
0
feeds/__init__.py
Normal file
0
feeds/__init__.py
Normal file
1
feeds/admin.py
Normal file
1
feeds/admin.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
# Register your models here.
|
||||
8
feeds/apps.py
Normal file
8
feeds/apps.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class FeedsConfig(AppConfig):
|
||||
"""This Django app is responsible for managing the feeds."""
|
||||
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "feeds"
|
||||
116
feeds/migrations/0001_initial.py
Normal file
116
feeds/migrations/0001_initial.py
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
# Generated by Django 5.0.2 on 2024-02-18 20:59
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Domain',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=255, unique=True)),
|
||||
('url', models.URLField()),
|
||||
('categories', models.JSONField()),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('modified_at', models.DateTimeField(auto_now=True)),
|
||||
('hidden', models.BooleanField(default=False)),
|
||||
('hidden_at', models.DateTimeField(blank=True, null=True)),
|
||||
('hidden_reason', models.TextField(blank=True)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Feed',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('modified_at', models.DateTimeField(auto_now=True)),
|
||||
('bozo', models.BooleanField()),
|
||||
('bozo_exception', models.TextField()),
|
||||
('encoding', models.TextField()),
|
||||
('etag', models.TextField()),
|
||||
('headers', models.JSONField()),
|
||||
('href', models.TextField()),
|
||||
('modified', models.DateTimeField()),
|
||||
('namespaces', models.JSONField()),
|
||||
('status', models.IntegerField()),
|
||||
('version', models.CharField(max_length=50)),
|
||||
('author', models.TextField()),
|
||||
('author_detail', models.JSONField()),
|
||||
('cloud', models.JSONField()),
|
||||
('contributors', models.JSONField()),
|
||||
('docs', models.TextField()),
|
||||
('errorreportsto', models.TextField()),
|
||||
('generator', models.TextField()),
|
||||
('generator_detail', models.TextField()),
|
||||
('icon', models.TextField()),
|
||||
('_id', models.TextField()),
|
||||
('image', models.JSONField()),
|
||||
('info', models.TextField()),
|
||||
('info_detail', models.JSONField()),
|
||||
('language', models.TextField()),
|
||||
('license', models.TextField()),
|
||||
('link', models.TextField()),
|
||||
('links', models.JSONField()),
|
||||
('logo', models.TextField()),
|
||||
('published', models.TextField()),
|
||||
('published_parsed', models.DateTimeField()),
|
||||
('publisher', models.TextField()),
|
||||
('publisher_detail', models.JSONField()),
|
||||
('rights', models.TextField()),
|
||||
('rights_detail', models.JSONField()),
|
||||
('subtitle', models.TextField()),
|
||||
('subtitle_detail', models.JSONField()),
|
||||
('tags', models.JSONField()),
|
||||
('textinput', models.JSONField()),
|
||||
('title', models.TextField()),
|
||||
('title_detail', models.JSONField()),
|
||||
('ttl', models.TextField()),
|
||||
('updated', models.TextField()),
|
||||
('updated_parsed', models.DateTimeField()),
|
||||
('domain', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='feeds.domain')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Entry',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('modified_at', models.DateTimeField(auto_now=True)),
|
||||
('author', models.TextField()),
|
||||
('author_detail', models.JSONField()),
|
||||
('comments', models.TextField()),
|
||||
('content', models.JSONField()),
|
||||
('contributors', models.JSONField()),
|
||||
('created', models.TextField()),
|
||||
('created_parsed', models.DateTimeField()),
|
||||
('enclosures', models.JSONField()),
|
||||
('expired', models.TextField()),
|
||||
('expired_parsed', models.DateTimeField()),
|
||||
('_id', models.TextField()),
|
||||
('license', models.TextField()),
|
||||
('link', models.TextField()),
|
||||
('links', models.JSONField()),
|
||||
('published', models.TextField()),
|
||||
('published_parsed', models.DateTimeField()),
|
||||
('publisher', models.TextField()),
|
||||
('publisher_detail', models.JSONField()),
|
||||
('source', models.JSONField()),
|
||||
('summary', models.TextField()),
|
||||
('summary_detail', models.JSONField()),
|
||||
('tags', models.JSONField()),
|
||||
('title', models.TextField()),
|
||||
('title_detail', models.JSONField()),
|
||||
('updated', models.TextField()),
|
||||
('updated_parsed', models.DateTimeField()),
|
||||
('feed', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='feeds.feed')),
|
||||
],
|
||||
),
|
||||
]
|
||||
0
feeds/migrations/__init__.py
Normal file
0
feeds/migrations/__init__.py
Normal file
122
feeds/models.py
Normal file
122
feeds/models.py
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import Literal
|
||||
|
||||
from django.db import models
|
||||
from django.db.models import JSONField
|
||||
|
||||
|
||||
class Domain(models.Model):
|
||||
"""A domain that has one or more feeds."""
|
||||
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
url = models.URLField()
|
||||
categories = models.JSONField()
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
modified_at = models.DateTimeField(auto_now=True)
|
||||
hidden = models.BooleanField(default=False)
|
||||
hidden_at = models.DateTimeField(null=True, blank=True)
|
||||
hidden_reason = models.TextField(blank=True)
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Return string representation of the domain."""
|
||||
if_hidden: Literal[" (hidden)", ""] = " (hidden)" if self.hidden else ""
|
||||
return self.name + if_hidden
|
||||
|
||||
|
||||
class Feed(models.Model):
|
||||
"""A RSS/Atom/JSON feed."""
|
||||
|
||||
domain = models.ForeignKey(Domain, on_delete=models.CASCADE)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
modified_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
# General data
|
||||
bozo = models.BooleanField()
|
||||
bozo_exception = models.TextField()
|
||||
encoding = models.TextField()
|
||||
etag = models.TextField()
|
||||
headers = JSONField()
|
||||
href = models.TextField()
|
||||
modified = models.DateTimeField()
|
||||
namespaces = JSONField()
|
||||
status = models.IntegerField()
|
||||
version = models.CharField(max_length=50)
|
||||
# Feed data
|
||||
author = models.TextField()
|
||||
author_detail = JSONField()
|
||||
cloud = JSONField()
|
||||
contributors = JSONField()
|
||||
docs = models.TextField()
|
||||
errorreportsto = models.TextField()
|
||||
generator = models.TextField()
|
||||
generator_detail = models.TextField()
|
||||
icon = models.TextField()
|
||||
_id = models.TextField()
|
||||
image = JSONField()
|
||||
info = models.TextField()
|
||||
info_detail = JSONField()
|
||||
language = models.TextField()
|
||||
license = models.TextField()
|
||||
link = models.TextField()
|
||||
links = JSONField()
|
||||
logo = models.TextField()
|
||||
published = models.TextField()
|
||||
published_parsed = models.DateTimeField()
|
||||
publisher = models.TextField()
|
||||
publisher_detail = JSONField()
|
||||
rights = models.TextField()
|
||||
rights_detail = JSONField()
|
||||
subtitle = models.TextField()
|
||||
subtitle_detail = JSONField()
|
||||
tags = JSONField()
|
||||
textinput = JSONField()
|
||||
title = models.TextField()
|
||||
title_detail = JSONField()
|
||||
ttl = models.TextField()
|
||||
updated = models.TextField()
|
||||
updated_parsed = models.DateTimeField()
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Return string representation of the feed."""
|
||||
return self.title_detail["value"] or "No title"
|
||||
|
||||
|
||||
class Entry(models.Model):
|
||||
"""Each feed has multiple entries."""
|
||||
|
||||
feed = models.ForeignKey(Feed, on_delete=models.CASCADE)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
modified_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
# Entry data
|
||||
author = models.TextField()
|
||||
author_detail = JSONField()
|
||||
comments = models.TextField()
|
||||
content = JSONField()
|
||||
contributors = JSONField()
|
||||
created = models.TextField()
|
||||
created_parsed = models.DateTimeField()
|
||||
enclosures = JSONField()
|
||||
expired = models.TextField()
|
||||
expired_parsed = models.DateTimeField()
|
||||
_id = models.TextField()
|
||||
license = models.TextField()
|
||||
link = models.TextField()
|
||||
links = JSONField()
|
||||
published = models.TextField()
|
||||
published_parsed = models.DateTimeField()
|
||||
publisher = models.TextField()
|
||||
publisher_detail = JSONField()
|
||||
source = JSONField()
|
||||
summary = models.TextField()
|
||||
summary_detail = JSONField()
|
||||
tags = JSONField()
|
||||
title = models.TextField()
|
||||
title_detail = JSONField()
|
||||
updated = models.TextField()
|
||||
updated_parsed = models.DateTimeField()
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Return string representation of the entry."""
|
||||
return self.title_detail["value"] or "No title"
|
||||
1
feeds/tests.py
Normal file
1
feeds/tests.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
# Create your tests here.
|
||||
13
feeds/urls.py
Normal file
13
feeds/urls.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from django.urls import URLPattern, path
|
||||
|
||||
from feeds import views
|
||||
|
||||
app_name: str = "feeds"
|
||||
|
||||
urlpatterns: list[URLPattern] = [
|
||||
path(route="", view=views.IndexView.as_view(), name="index"),
|
||||
path(route="feed/<int:feed_id>/", view=views.FeedView.as_view(), name="feed"),
|
||||
path(route="feeds/", view=views.FeedsView.as_view(), name="feeds"),
|
||||
]
|
||||
35
feeds/views.py
Normal file
35
feeds/views.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.template import loader
|
||||
from django.views import View
|
||||
|
||||
|
||||
class IndexView(View):
|
||||
"""Index path."""
|
||||
|
||||
def get(self, request: HttpRequest) -> HttpResponse:
|
||||
"""GET request for index path."""
|
||||
template = loader.get_template(template_name="index.html")
|
||||
context = {}
|
||||
return HttpResponse(content=template.render(context=context, request=request))
|
||||
|
||||
|
||||
class FeedView(View):
|
||||
"""A single feed."""
|
||||
|
||||
def get(self, request: HttpRequest, feed_id: int) -> HttpResponse:
|
||||
"""GET request for index path."""
|
||||
template = loader.get_template(template_name="feed.html")
|
||||
context = {"feed_id": feed_id}
|
||||
return HttpResponse(content=template.render(context=context, request=request))
|
||||
|
||||
|
||||
class FeedsView(View):
|
||||
"""All feeds."""
|
||||
|
||||
def get(self, request: HttpRequest) -> HttpResponse:
|
||||
"""GET request for index path."""
|
||||
template = loader.get_template(template_name="feeds.html")
|
||||
context = {}
|
||||
return HttpResponse(content=template.render(context=context, request=request))
|
||||
Loading…
Add table
Add a link
Reference in a new issue