Cleanup in home
This commit is contained in:
parent
190615491e
commit
3a3c909a86
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from .models import Subscription, SavedGuilds
|
from .models import Subscription, SavedGuilds, Filter, SubChannel, TrackedContent
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Subscription)
|
@admin.register(Subscription)
|
||||||
@ -12,6 +12,26 @@ class SubscriptionAdmin(admin.ModelAdmin):
|
|||||||
"creation_datetime", "active"
|
"creation_datetime", "active"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@admin.register(SubChannel)
|
||||||
|
class SubChannelAdmin(admin.ModelAdmin):
|
||||||
|
list_display = [
|
||||||
|
"id", "channel_id", "subscription"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(Filter)
|
||||||
|
class FilterAdmin(admin.ModelAdmin):
|
||||||
|
list_display = [
|
||||||
|
"id", "name", "keywords", "regex", "whitelist", "guild_id"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(TrackedContent)
|
||||||
|
class TrackedContentAdmin(admin.ModelAdmin):
|
||||||
|
list_display = [
|
||||||
|
"guid", "title", "url", "subscription", "blocked", "creation_datetime"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@admin.register(SavedGuilds)
|
@admin.register(SavedGuilds)
|
||||||
class SavedGuildAdmin(admin.ModelAdmin):
|
class SavedGuildAdmin(admin.ModelAdmin):
|
||||||
|
@ -1,43 +1,15 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from uuid import uuid4
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Q
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.core.files.storage import FileSystemStorage
|
|
||||||
from django.utils.deconstruct import deconstructible
|
|
||||||
from django.core.exceptions import ValidationError
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class OverwriteStorage(FileSystemStorage):
|
|
||||||
"""
|
|
||||||
Storage class that allows overriding files, instead of django appending random
|
|
||||||
characters to prevent conflicts.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def get_available_name(self, name, max_length=None) -> str:
|
|
||||||
if self.exists(name):
|
|
||||||
(Path(self.location) / name).unlink()
|
|
||||||
|
|
||||||
return name
|
|
||||||
|
|
||||||
|
|
||||||
@deconstructible
|
|
||||||
class IconPathGenerator:
|
|
||||||
"""
|
|
||||||
Icon path generator.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __call__(self, instance, filename: str) -> Path:
|
|
||||||
return Path(instance.__class__.__name__.lower()) / str(instance.uuid) / "icon.webp"
|
|
||||||
|
|
||||||
|
|
||||||
class SavedGuilds(models.Model):
|
class SavedGuilds(models.Model):
|
||||||
"""
|
"""
|
||||||
Represents a saved Discord Guild (aka Server).
|
Represents a saved Discord Guild (aka Server).
|
||||||
@ -100,7 +72,7 @@ class SavedGuilds(models.Model):
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self) -> str:
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@ -142,6 +114,9 @@ class SubChannel(models.Model):
|
|||||||
name="unique channel id and subscription pair")
|
name="unique channel id and subscription pair")
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return self.channel_id
|
||||||
|
|
||||||
|
|
||||||
class Filter(models.Model):
|
class Filter(models.Model):
|
||||||
id = models.AutoField(primary_key=True)
|
id = models.AutoField(primary_key=True)
|
||||||
@ -188,8 +163,16 @@ class Filter(models.Model):
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Subscription(models.Model):
|
class Subscription(models.Model):
|
||||||
|
"""
|
||||||
|
The Subscription Model.
|
||||||
|
'Subscription' in the context of PYRSS is an RSS Feed with various settings.
|
||||||
|
"""
|
||||||
|
|
||||||
id = models.AutoField(primary_key=True)
|
id = models.AutoField(primary_key=True)
|
||||||
|
|
||||||
name = models.CharField(
|
name = models.CharField(
|
||||||
@ -200,6 +183,7 @@ class Subscription(models.Model):
|
|||||||
|
|
||||||
url = models.URLField()
|
url = models.URLField()
|
||||||
|
|
||||||
|
# NOTE:
|
||||||
# Have to use charfield instead of positiveBigIntegerField due to an Sqlite
|
# Have to use charfield instead of positiveBigIntegerField due to an Sqlite
|
||||||
# issue that rounds down the value
|
# issue that rounds down the value
|
||||||
# https://github.com/sequelize/sequelize/issues/9335
|
# https://github.com/sequelize/sequelize/issues/9335
|
||||||
@ -220,9 +204,7 @@ class Subscription(models.Model):
|
|||||||
|
|
||||||
filters = models.ManyToManyField(to="home.Filter", blank=True)
|
filters = models.ManyToManyField(to="home.Filter", blank=True)
|
||||||
|
|
||||||
active = models.BooleanField(
|
active = models.BooleanField(default=True)
|
||||||
default=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""
|
"""
|
||||||
@ -238,22 +220,47 @@ class Subscription(models.Model):
|
|||||||
]
|
]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def channels_count(self):
|
def channels_count(self) -> int:
|
||||||
return len(SubChannel.objects.filter(subscription=self))
|
"""
|
||||||
|
Returns the number of 'SubChannel' objects assocaited
|
||||||
|
with this subscription.
|
||||||
|
"""
|
||||||
|
|
||||||
def __str__(self):
|
return len(SubChannel.objects.filter(subscription=self))
|
||||||
return self.name
|
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
new_text = "New " if self._state.adding else ""
|
new_text = "New " if self._state.adding else ""
|
||||||
log.debug("%sSubscription Saved %s", new_text, self.id)
|
log.debug("%sSubscription Saved %s", new_text, self.id)
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class TrackedContent(models.Model):
|
class TrackedContent(models.Model):
|
||||||
guid = models.CharField(primary_key=True, max_length=128)
|
"""
|
||||||
|
Tracked Content Model
|
||||||
|
'Tracked Content' identifies articles and tracks them being sent.
|
||||||
|
This is used to ensure duplicate articles aren't sent in feeds.
|
||||||
|
"""
|
||||||
|
|
||||||
|
guid = models.CharField(
|
||||||
|
primary_key=True,
|
||||||
|
max_length=128
|
||||||
|
)
|
||||||
|
|
||||||
title = models.CharField(max_length=128)
|
title = models.CharField(max_length=128)
|
||||||
|
|
||||||
url = models.URLField()
|
url = models.URLField()
|
||||||
|
|
||||||
subscription = models.ForeignKey(to=Subscription, on_delete=models.CASCADE)
|
subscription = models.ForeignKey(to=Subscription, on_delete=models.CASCADE)
|
||||||
|
|
||||||
blocked = models.BooleanField(default=False)
|
blocked = models.BooleanField(default=False)
|
||||||
creation_datetime = models.DateTimeField(default=timezone.now, editable=False)
|
|
||||||
|
creation_datetime = models.DateTimeField(
|
||||||
|
default=timezone.now,
|
||||||
|
editable=False
|
||||||
|
)
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return self.title
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
from django.urls import path, include, re_path
|
from django.urls import path
|
||||||
from django.shortcuts import redirect
|
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
|
||||||
from .views import IndexView
|
from .views import IndexView
|
||||||
|
|
||||||
# def reverse_to_index(reqeust):
|
|
||||||
# return redirect("admin:index")
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", login_required(IndexView.as_view()), name="index"),
|
path("", login_required(IndexView.as_view()), name="index"),
|
||||||
]
|
]
|
||||||
|
@ -1,32 +1,11 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
# from django import template
|
|
||||||
# from django.contrib.auth.decorators import login_required
|
|
||||||
# from django.http import HttpResponse, HttpResponseRedirect
|
|
||||||
# from django.template import loader
|
|
||||||
# from django.urls import reverse
|
|
||||||
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
from django.utils.decorators import classonlymethod
|
|
||||||
from django.contrib.auth.decorators import login_required
|
|
||||||
|
|
||||||
|
|
||||||
class IndexView(TemplateView):
|
class IndexView(TemplateView):
|
||||||
"""
|
"""
|
||||||
|
View for the Index page.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
template_name = "home/index.html"
|
template_name = "home/index.html"
|
||||||
# view_is_async = True
|
|
||||||
|
|
||||||
# @classonlymethod
|
|
||||||
# def as_view(cls, **initkwargs):
|
|
||||||
# view = super().as_view(**initkwargs)
|
|
||||||
# view._is_coroutine = asyncio.coroutines._is_coroutine
|
|
||||||
# return view
|
|
||||||
|
|
||||||
# async def get(self, request, *args, **kwargs):
|
|
||||||
# context = self.get_context_data(**kwargs)
|
|
||||||
# return self.render_to_response(context)
|
|
Loading…
x
Reference in New Issue
Block a user