mirror of
https://github.com/chibicitiberiu/ytsm.git
synced 2024-02-24 05:43:31 +00:00
Began work on refactoring the YTSM application.
This commit is contained in:
@ -2,8 +2,8 @@ from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.http import JsonResponse
|
||||
from django.views.generic import View
|
||||
|
||||
from YtManagerApp.management.jobs.synchronize import SynchronizeJob
|
||||
from YtManagerApp.models import Video
|
||||
from YtManagerApp.scheduler.jobs.synchronize_job import SynchronizeJob
|
||||
|
||||
|
||||
class SyncNowView(LoginRequiredMixin, View):
|
||||
|
@ -6,7 +6,7 @@ from django.http import HttpResponseForbidden
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic import FormView, TemplateView
|
||||
|
||||
from YtManagerApp.management.appconfig import appconfig
|
||||
from YtManagerApp.services import Services
|
||||
from YtManagerApp.views.forms.auth import ExtendedAuthenticationForm, ExtendedUserCreationForm
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@ class RegisterView(FormView):
|
||||
return context
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
if not appconfig.allow_registrations:
|
||||
if not Services.appConfig.allow_registrations:
|
||||
return HttpResponseForbidden("Registrations are disabled!")
|
||||
|
||||
return super().post(request, *args, **kwargs)
|
||||
|
@ -8,9 +8,8 @@ from django.shortcuts import redirect
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic import FormView
|
||||
|
||||
from YtManagerApp.management.appconfig import appconfig
|
||||
from YtManagerApp.management.jobs.synchronize import SynchronizeJob
|
||||
from YtManagerApp.scheduler import scheduler
|
||||
from YtManagerApp.scheduler.jobs.synchronize_job import SynchronizeJob
|
||||
from YtManagerApp.services import Services
|
||||
from YtManagerApp.views.forms.first_time import WelcomeForm, ApiKeyForm, PickAdminUserForm, ServerConfigForm, DoneForm, \
|
||||
UserCreationForm, LoginForm
|
||||
|
||||
@ -25,7 +24,7 @@ class WizardStepMixin:
|
||||
def get(self, request, *args, **kwargs):
|
||||
|
||||
# Prevent access if application is already initialized
|
||||
if appconfig.initialized:
|
||||
if Services.appConfig.initialized:
|
||||
logger.debug(f"Attempted to access {request.path}, but first time setup already run. Redirected to home "
|
||||
f"page.")
|
||||
return redirect('home')
|
||||
@ -33,7 +32,7 @@ class WizardStepMixin:
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
if appconfig.initialized:
|
||||
if Services.appConfig.initialized:
|
||||
logger.debug(f"Attempted to post {request.path}, but first time setup already run.")
|
||||
return HttpResponseForbidden()
|
||||
return super().post(request, *args, **kwargs)
|
||||
@ -66,14 +65,14 @@ class Step1ApiKeyView(WizardStepMixin, FormView):
|
||||
|
||||
def get_initial(self):
|
||||
initial = super().get_initial()
|
||||
initial['api_key'] = appconfig.youtube_api_key
|
||||
initial['api_key'] = Services.appConfig.youtube_api_key
|
||||
return initial
|
||||
|
||||
def form_valid(self, form):
|
||||
key = form.cleaned_data['api_key']
|
||||
# TODO: validate key
|
||||
if key is not None and len(key) > 0:
|
||||
appconfig.youtube_api_key = key
|
||||
Services.appConfig.youtube_api_key = key
|
||||
|
||||
return super().form_valid(form)
|
||||
|
||||
@ -150,8 +149,8 @@ class Step3ConfigureView(WizardStepMixin, FormView):
|
||||
|
||||
def get_initial(self):
|
||||
initial = super().get_initial()
|
||||
initial['allow_registrations'] = appconfig.allow_registrations
|
||||
initial['sync_schedule'] = appconfig.sync_schedule
|
||||
initial['allow_registrations'] = Services.appConfig.allow_registrations
|
||||
initial['sync_schedule'] = Services.appConfig.sync_schedule
|
||||
initial['auto_download'] = self.request.user.preferences['auto_download']
|
||||
initial['download_location'] = self.request.user.preferences['download_path']
|
||||
return initial
|
||||
@ -159,11 +158,11 @@ class Step3ConfigureView(WizardStepMixin, FormView):
|
||||
def form_valid(self, form):
|
||||
allow_registrations = form.cleaned_data['allow_registrations']
|
||||
if allow_registrations is not None:
|
||||
appconfig.allow_registrations = allow_registrations
|
||||
Services.appConfig.allow_registrations = allow_registrations
|
||||
|
||||
sync_schedule = form.cleaned_data['sync_schedule']
|
||||
if sync_schedule is not None and len(sync_schedule) > 0:
|
||||
appconfig.sync_schedule = sync_schedule
|
||||
Services.appConfig.sync_schedule = sync_schedule
|
||||
|
||||
auto_download = form.cleaned_data['auto_download']
|
||||
if auto_download is not None:
|
||||
@ -174,10 +173,10 @@ class Step3ConfigureView(WizardStepMixin, FormView):
|
||||
self.request.user.preferences['download_path'] = download_location
|
||||
|
||||
# Set initialized to true
|
||||
appconfig.initialized = True
|
||||
Services.appConfig.initialized = True
|
||||
|
||||
# Start scheduler if not started
|
||||
scheduler.initialize()
|
||||
Services.scheduler.initialize()
|
||||
SynchronizeJob.schedule_global_job()
|
||||
|
||||
return super().form_valid(form)
|
||||
|
@ -6,8 +6,8 @@ from YtManagerApp.dynamic_preferences_registry import MarkDeletedAsWatched, Auto
|
||||
DownloadGlobalLimit, DownloadGlobalSizeLimit, DownloadSubscriptionLimit, DownloadMaxAttempts, DownloadOrder, \
|
||||
DownloadPath, DownloadFilePattern, DownloadFormat, DownloadSubtitles, DownloadAutogeneratedSubtitles, \
|
||||
DownloadAllSubtitles, DownloadSubtitlesLangs, DownloadSubtitlesFormat
|
||||
from YtManagerApp.management.appconfig import appconfig
|
||||
from YtManagerApp.models import VIDEO_ORDER_CHOICES
|
||||
from YtManagerApp.services import Services
|
||||
|
||||
|
||||
class SettingsForm(forms.Form):
|
||||
@ -234,25 +234,25 @@ class AdminSettingsForm(forms.Form):
|
||||
@staticmethod
|
||||
def get_initials():
|
||||
return {
|
||||
'api_key': appconfig.youtube_api_key,
|
||||
'allow_registrations': appconfig.allow_registrations,
|
||||
'sync_schedule': appconfig.sync_schedule,
|
||||
'scheduler_concurrency': appconfig.concurrency,
|
||||
'api_key': Services.appConfig.youtube_api_key,
|
||||
'allow_registrations': Services.appConfig.allow_registrations,
|
||||
'sync_schedule': Services.appConfig.sync_schedule,
|
||||
'scheduler_concurrency': Services.appConfig.concurrency,
|
||||
}
|
||||
|
||||
def save(self):
|
||||
api_key = self.cleaned_data['api_key']
|
||||
if api_key is not None and len(api_key) > 0:
|
||||
appconfig.youtube_api_key = api_key
|
||||
Services.appConfig.youtube_api_key = api_key
|
||||
|
||||
allow_registrations = self.cleaned_data['allow_registrations']
|
||||
if allow_registrations is not None:
|
||||
appconfig.allow_registrations = allow_registrations
|
||||
Services.appConfig.allow_registrations = allow_registrations
|
||||
|
||||
sync_schedule = self.cleaned_data['sync_schedule']
|
||||
if sync_schedule is not None and len(sync_schedule) > 0:
|
||||
appconfig.sync_schedule = sync_schedule
|
||||
Services.appConfig.sync_schedule = sync_schedule
|
||||
|
||||
concurrency = self.cleaned_data['scheduler_concurrency']
|
||||
if concurrency is not None:
|
||||
appconfig.concurrency = concurrency
|
||||
Services.appConfig.concurrency = concurrency
|
||||
|
@ -11,8 +11,8 @@ 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.management.appconfig import appconfig
|
||||
from YtManagerApp.models import Subscription, SubscriptionFolder, VIDEO_ORDER_CHOICES, VIDEO_ORDER_MAPPING
|
||||
from YtManagerApp.services import Services
|
||||
from YtManagerApp.utils import youtube, subscription_file_parser
|
||||
from YtManagerApp.views.controls.modal import ModalMixin
|
||||
|
||||
@ -111,7 +111,7 @@ def __tree_sub_id(sub_id):
|
||||
|
||||
def index(request: HttpRequest):
|
||||
|
||||
if not appconfig.initialized:
|
||||
if not Services.appConfig.initialized:
|
||||
return redirect('first_time_0')
|
||||
|
||||
context = {
|
||||
|
@ -3,7 +3,7 @@ from django.http import HttpResponseForbidden
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic import FormView
|
||||
|
||||
from YtManagerApp.management.jobs.synchronize import SynchronizeJob
|
||||
from YtManagerApp.scheduler.jobs.synchronize_job import SynchronizeJob
|
||||
from YtManagerApp.views.forms.settings import SettingsForm, AdminSettingsForm
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user