ytsm/app/YtManagerApp/views/settings/providers_view.py

40 lines
1.6 KiB
Python
Raw Normal View History

2020-04-22 21:47:27 +00:00
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import TemplateView
2020-10-18 16:36:26 +00:00
from YtManagerApp.providers.video_provider import VideoProviderState
2020-04-22 21:47:27 +00:00
from YtManagerApp.services import Services
from collections import namedtuple
VideoProviderInfoViewModel = namedtuple('VideoProviderInfoViewModel',
2020-10-18 16:36:26 +00:00
['id', 'name', 'is_configured', 'has_error', 'image_src'])
2020-04-22 21:47:27 +00:00
class ProvidersView(LoginRequiredMixin, TemplateView):
template_name = 'YtManagerApp/settings/providers.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
providers = []
have_unconfigured = False
2020-10-18 16:36:26 +00:00
have_configured = False
2020-04-22 21:47:27 +00:00
for provider in Services.videoProviderManager().get_available_providers():
providers.append(VideoProviderInfoViewModel(
id=provider.id,
name=provider.name,
2020-10-18 16:36:26 +00:00
is_configured=provider.state != VideoProviderState.NOT_CONFIGURED,
has_error=provider.state == VideoProviderState.ERROR,
2020-04-22 21:47:27 +00:00
image_src=f"YtManagerApp/img/video_providers/{provider.id}.png"
))
2020-10-18 16:36:26 +00:00
if provider.state != VideoProviderState.NOT_CONFIGURED:
have_configured = True
if provider.state == VideoProviderState.NOT_CONFIGURED:
2020-04-22 21:47:27 +00:00
have_unconfigured = True
context['providers'] = sorted(providers, key=lambda x: x.name)
context['have_unconfigured'] = have_unconfigured
2020-10-18 16:36:26 +00:00
context['have_configured'] = have_configured
2020-04-22 21:47:27 +00:00
return context