"""
App views
"""
from django.conf import settings
from django.views import generic

from .store import WebfontStore


class WebfontIconListFreeView(generic.TemplateView):
    """
    View listing icon found from Icomoon manifest
    """
    template_name = "icomoon/index.html"

    def get_context_data(self, **kwargs):
        context = super(WebfontIconListFreeView, self).get_context_data(**kwargs)

        webfonts = getattr(settings, 'ICOMOON_WEBFONTS', {})
        if webfonts is not None:
            webfont_store = WebfontStore(settings.ICOMOON_MANIFEST_FILENAME)
            webfont_store.fetch(webfonts)
            context['webfont_store'] = webfont_store

        return context


if getattr(settings, 'ICOMOON_PRIVATE', True):
    from django.contrib.auth.mixins import LoginRequiredMixin

    class WebfontIconListView(LoginRequiredMixin, WebfontIconListFreeView):
        pass
else:
    class WebfontIconListView(WebfontIconListFreeView):
        pass
