From 3e835af295fde1776a8f6ca3919f64b8cb9f3da5 Mon Sep 17 00:00:00 2001 From: Tiberiu Chibici Date: Mon, 23 Dec 2019 23:52:38 +0200 Subject: [PATCH] Continued refactoring. --- app/YtManagerApp/appmain.py | 7 ++++- app/YtManagerApp/models.py | 55 ++++++++++++++++++++++++++------- app/YtManagerApp/views/index.py | 6 ++-- 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/app/YtManagerApp/appmain.py b/app/YtManagerApp/appmain.py index 091782d..fe52f52 100644 --- a/app/YtManagerApp/appmain.py +++ b/app/YtManagerApp/appmain.py @@ -31,13 +31,18 @@ def __initialize_logger(): logging.root.addHandler(console_handler) +def __load_main_jobs(): + SynchronizeJob.schedule_global_job() + + def main(): __initialize_logger() try: if Services.appConfig().initialized: Services.scheduler().initialize() - SynchronizeJob.schedule_global_job() + __load_main_jobs() + except OperationalError: # Settings table is not created when running migrate or makemigrations; # Just don't do anything in this case. diff --git a/app/YtManagerApp/models.py b/app/YtManagerApp/models.py index 94e3520..5b715f6 100644 --- a/app/YtManagerApp/models.py +++ b/app/YtManagerApp/models.py @@ -29,10 +29,25 @@ VIDEO_ORDER_MAPPING = { } +class Provider(models.Model): + + class_name = models.CharField(null=False, max_length=64, unique=True, + help_text='Class name in the "providers" package.') + + config = models.CharField(max_length=1024, + help_text='Provider configuration (stored as JSON)') + + class SubscriptionFolder(models.Model): - name = models.CharField(null=False, max_length=250) - parent = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True) - user = models.ForeignKey(User, on_delete=models.CASCADE, null=False, blank=False) + + name = models.CharField(null=False, max_length=250, + help_text='Folder name') + + parent = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, + help_text='Parent folder') + + user = models.ForeignKey(User, on_delete=models.CASCADE, null=False, blank=False, + help_text='User who owns the subscription') class Meta: ordering = [Lower('parent__name'), Lower('name')] @@ -98,17 +113,33 @@ class SubscriptionFolder(models.Model): class Subscription(models.Model): - name = models.CharField(null=False, max_length=1024) - description = models.TextField() - original_url = models.CharField(null=False, max_length=1024) - thumbnail = models.CharField(max_length=1024) + name = models.CharField(null=False, max_length=1024, + help_text='Name of playlist or channel.') - provider = models.CharField(null=False, max_length=64) - provider_id = models.CharField(null=False, max_length=64) - provider_data = models.CharField(null=True, max_length=1024) + description = models.TextField(help_text='Description of the playlist/channel.') - parent_folder = models.ForeignKey(SubscriptionFolder, on_delete=models.CASCADE, null=True, blank=True) - user = models.ForeignKey(User, on_delete=models.CASCADE) + original_url = models.CharField(null=False, max_length=1024, + help_text='Original URL added by user.') + + thumbnail = models.CharField(max_length=1024, + help_text='An URL to the thumbnail.') + + # + provider = models.ForeignKey(Provider, null=True, on_delete=models.SET_DEFAULT, + help_text='Provider who manages this subscription (e.g. YouTube, Vimeo etc)') + + provider_id = models.CharField(null=False, max_length=64, + help_text='Identifier according to provider (e.g. YouTube video ID)') + + provider_data = models.CharField(null=True, max_length=1024, + help_text='Extra data stored by the provider serialized as JSON') + + # + parent_folder = models.ForeignKey(SubscriptionFolder, on_delete=models.CASCADE, null=True, blank=True, + help_text='Parent folder') + + user = models.ForeignKey(User, on_delete=models.CASCADE, + help_text='Owner user') # overrides auto_download = models.BooleanField(null=True, blank=True) diff --git a/app/YtManagerApp/views/index.py b/app/YtManagerApp/views/index.py index b79eb7e..5086bc7 100644 --- a/app/YtManagerApp/views/index.py +++ b/app/YtManagerApp/views/index.py @@ -10,10 +10,10 @@ from django.views.generic import CreateView, UpdateView, DeleteView, FormView from django.views.generic.edit import FormMixin from django.conf import settings from django.core.paginator import Paginator -from YtManagerApp.management.videos import get_videos +from YtManagerApp.services.videos import get_videos from YtManagerApp.models import Subscription, SubscriptionFolder, VIDEO_ORDER_CHOICES, VIDEO_ORDER_MAPPING -from YtManagerApp.management.services import Services -from YtManagerApp.utils import youtube, subscription_file_parser +from YtManagerApp.services import Services +from YtManagerApp.utils import subscription_file_parser from YtManagerApp.views.controls.modal import ModalMixin import logging