# Path: oauth/oauthmanager.py
# @cache_decorator(expiration=100 * 60)
# def get_oauth_apps():
#     configs = OAuthConfig.objects.filter(is_enable=True).all()
#     if not configs:
#         return []
#     configtypes = [x.type for x in configs]
#     applications = BaseOauthManager.__subclasses__()
#     apps = [x() for x in applications if x().ICON_NAME.lower() in configtypes]
#     return apps


from django import template
from django.urls import reverse
from oauth.oauthmanager import get_oauth_apps


register = template.Library()


@register.inclusion_tag('oauth/oauth_applications.html')
def load_oauth_applications(request):
    applications = get_oauth_apps()
    if applications:
        baseurl = reverse('oauth:oauthlogin')
        path = request.get_full_path()

        apps = list(map(lambda x: (x.ICON_NAME, '{baseurl}?type={type}&next_url={next}'.format(
            baseurl=baseurl, type=x.ICON_NAME, next=path)), applications))
    else:
        apps = []

# Path: oauth/oauthmanager.py
# @cache_decorator(expiration=100 * 60)
# def get_oauth_apps():
#     configs = OAuthConfig.objects.filter(is_enable=True).all()
#     if not configs:
#         return []
#     configtypes = [x.type for x in configs]
#     applications = BaseOauthManager.__subclasses__()
#     apps = [x() for x in applications if x().ICON_NAME.lower() in configtypes]
#     return apps


# Path: oauth/templatetags/oauth_tags.py
from django import template
from django.urls import reverse
from oauth.oauthmanager import get_oauth_apps



register = template.Library()


@register.inclusion_tag('oauth/oauth_applications.html')
def load_oauth_applications(request):
    applications = get_oauth_apps()
    if applications:
        baseurl = reverse('oauth:oauthlogin')
        path = request.get_full_path()

        apps = list(map(lambda x: (x.ICON_NAME, '{baseurl}?type={type}&next_url={next}'.format(
            baseurl=baseurl, type=x.ICON_NAME, next=path)), applications))
    else:
        apps = []

    return {