mirror of
				https://github.com/chibicitiberiu/ytsm.git
				synced 2024-02-24 05:43:31 +00:00 
			
		
		
		
	Improve error handling for settings. Instead of failing with an exception, an alert is displayed on the main page when something isn't set properly.
This commit is contained in:
		@@ -1,19 +1,19 @@
 | 
			
		||||
import logging
 | 
			
		||||
import sys
 | 
			
		||||
from apscheduler.schedulers.background import BackgroundScheduler
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
 | 
			
		||||
scheduler: BackgroundScheduler = None
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def initialize_scheduler():
 | 
			
		||||
    from .appconfig import settings
 | 
			
		||||
    global scheduler
 | 
			
		||||
 | 
			
		||||
    logger = logging.getLogger('scheduler')
 | 
			
		||||
    executors = {
 | 
			
		||||
        'default': {
 | 
			
		||||
            'type': 'threadpool',
 | 
			
		||||
            'max_workers': settings.getint('global', 'SchedulerConcurrency')
 | 
			
		||||
            'max_workers': settings.SCHEDULER_CONCURRENCY
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    job_defaults = {
 | 
			
		||||
 
 | 
			
		||||
@@ -24,6 +24,8 @@
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    {% include 'YtManagerApp/index_errors_banner.html' %}
 | 
			
		||||
 | 
			
		||||
    <div class="row">
 | 
			
		||||
 | 
			
		||||
        <div class="col-3">
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,24 @@
 | 
			
		||||
{% if config_errors %}
 | 
			
		||||
    <div class="alert alert-danger alert-card mx-auto">
 | 
			
		||||
        <p>Attention! Some critical configuration errors have been found!</p>
 | 
			
		||||
        <ul>
 | 
			
		||||
            {% for err in config_errors %}
 | 
			
		||||
                <li>{{ err }}</li>
 | 
			
		||||
            {% endfor %}
 | 
			
		||||
        </ul>
 | 
			
		||||
        <p>Until these problems are fixed, the server may have encounter serious problems while running.
 | 
			
		||||
            Please correct these errors, and then restart the server.</p>
 | 
			
		||||
    </div>
 | 
			
		||||
{% endif %}
 | 
			
		||||
 | 
			
		||||
{% if config_warnings %}
 | 
			
		||||
    <div class="alert alert-warning alert-card mx-auto">
 | 
			
		||||
        <p>Warning: some configuration problems have been found!</p>
 | 
			
		||||
        <ul>
 | 
			
		||||
            {% for err in config_warnings %}
 | 
			
		||||
                <li>{{ err }}</li>
 | 
			
		||||
            {% endfor %}
 | 
			
		||||
        </ul>
 | 
			
		||||
        <p>We recommend that you fix these issues before continuing.</p>
 | 
			
		||||
    </div>
 | 
			
		||||
{% endif %}
 | 
			
		||||
@@ -3,6 +3,8 @@
 | 
			
		||||
 | 
			
		||||
{% block body %}
 | 
			
		||||
 | 
			
		||||
    {% include 'YtManagerApp/index_errors_banner.html' %}
 | 
			
		||||
 | 
			
		||||
    <h1>Hello</h1>
 | 
			
		||||
    <h2>Please log in to continue</h2>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@ from django.http import HttpRequest, HttpResponseBadRequest, JsonResponse
 | 
			
		||||
from django.shortcuts import render
 | 
			
		||||
from django.views.generic import CreateView, UpdateView, DeleteView, FormView
 | 
			
		||||
from django.views.generic.edit import FormMixin
 | 
			
		||||
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
from YtManagerApp.management.videos import get_videos
 | 
			
		||||
from YtManagerApp.models import Subscription, SubscriptionFolder, VIDEO_ORDER_CHOICES, VIDEO_ORDER_MAPPING
 | 
			
		||||
from YtManagerApp.utils import youtube, subscription_file_parser
 | 
			
		||||
@@ -94,13 +94,17 @@ def __tree_sub_id(sub_id):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def index(request: HttpRequest):
 | 
			
		||||
    context = {
 | 
			
		||||
        'config_errors': settings.CONFIG_ERRORS,
 | 
			
		||||
        'config_warnings': settings.CONFIG_WARNINGS,
 | 
			
		||||
    }
 | 
			
		||||
    if request.user.is_authenticated:
 | 
			
		||||
        context = {
 | 
			
		||||
            'filter_form': VideoFilterForm()
 | 
			
		||||
        }
 | 
			
		||||
        context.update({
 | 
			
		||||
            'filter_form': VideoFilterForm(),
 | 
			
		||||
        })
 | 
			
		||||
        return render(request, 'YtManagerApp/index.html', context)
 | 
			
		||||
    else:
 | 
			
		||||
        return render(request, 'YtManagerApp/index_unauthenticated.html')
 | 
			
		||||
        return render(request, 'YtManagerApp/index_unauthenticated.html', context)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user