Continued refactoring.

This commit is contained in:
Tiberiu Chibici 2019-12-23 23:52:38 +02:00
parent 6b843f1fc2
commit 3e835af295
3 changed files with 52 additions and 16 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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