# Path: baton/config.py
# def get_config(key):
#     safe = ['SITE_HEADER', 'COPYRIGHT', 'POWERED_BY', ]
#     user_settings = getattr(settings, 'BATON', None)
# 
#     if user_settings is None:
#         value = default_config.get(key, None)
#     else:
#         value = user_settings.get(key, default_config.get(key, None))
# 
#     if key in safe:
#         return mark_safe(value)
# 
#     return value


import json
from django.urls import reverse
from django import template
from django.utils.html import escapejs
from django.core.exceptions import ImproperlyConfigured
from ..config import get_config
        from google.auth.transport.requests import Request
        from google.oauth2 import service_account
    # The location of the key file with the key data.
    SERVICE_ACCOUNT_FILE = analytics_settings['CREDENTIALS']

    _credentials = service_account.Credentials.from_service_account_file(
        SERVICE_ACCOUNT_FILE,
        scopes=SCOPES, )
    _credentials.refresh(Request())

    # Construct a credentials objects from the key data and OAuth2 scope.
    # _credentials = SignedJwtAssertionCredentials(
    #     _key_data['client_email'], _key_data['private_key'], SCOPE)

    return {
        'token': _credentials.token,
        'view_id': analytics_settings['VIEW_ID']
    }


@register.inclusion_tag('baton/footer.html', takes_context=True)
def footer(context):
    user = context['user']
    return {
        'user': user,
        'support_href': get_config('SUPPORT_HREF'),
        'site_title': get_config('SITE_TITLE'),
        'copyright': get_config('COPYRIGHT'),
        'powered_by': get_config('POWERED_BY'),
    }



# Path: baton/config.py
# def get_config(key):
#     safe = ['SITE_HEADER', 'COPYRIGHT', 'POWERED_BY', ]
#     user_settings = getattr(settings, 'BATON', None)
# 
#     if user_settings is None:
#         value = default_config.get(key, None)
#     else:
#         value = user_settings.get(key, default_config.get(key, None))
# 
#     if key in safe:
#         return mark_safe(value)
# 
#     return value


# Path: baton/templatetags/baton_tags.py
import json
from django.urls import reverse
from django import template
from django.utils.html import escapejs
from django.core.exceptions import ImproperlyConfigured
from ..config import get_config
        from google.auth.transport.requests import Request
        from google.oauth2 import service_account

    # The location of the key file with the key data.
    SERVICE_ACCOUNT_FILE = analytics_settings['CREDENTIALS']

    _credentials = service_account.Credentials.from_service_account_file(
        SERVICE_ACCOUNT_FILE,
        scopes=SCOPES, )
    _credentials.refresh(Request())

    # Construct a credentials objects from the key data and OAuth2 scope.
    # _credentials = SignedJwtAssertionCredentials(
    #     _key_data['client_email'], _key_data['private_key'], SCOPE)

    return {
        'token': _credentials.token,
        'view_id': analytics_settings['VIEW_ID']
    }


@register.inclusion_tag('baton/footer.html', takes_context=True)
def footer(context):
    user = context['user']
    return {
        'user': user,
        'support_href': get_config('SUPPORT_HREF'),
        'site_title': get_config('SITE_TITLE'),
        'copyright': get_config('COPYRIGHT'),
        'powered_by': get_config('POWERED_BY'),
    }



@register.simple_tag(takes_context=True)