# 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 hashlib
from django.http import JsonResponse
from django.contrib.admin import site
from django.contrib.admin.views.decorators import staff_member_required
from django.utils.decorators import method_decorator
from django.core.exceptions import ImproperlyConfigured
from django.views import View
from .config import get_config



class GetAppListJsonView(View):

    @method_decorator(staff_member_required)
    def dispatch(self, *args, **kwargs):
        """ Only staff members can access this view """
        return super(GetAppListJsonView, self).dispatch(*args, **kwargs)

    def get(self, request):
        """ Returns a json representing the menu voices
            in a format eaten by the js menu.
            Raised ImproperlyConfigured exceptions can be viewed
            in the browser console
        """
        self.app_list = site.get_app_list(request)
        self.apps_dict = self.create_app_list_dict()
        # no menu provided
        items = self.get_menu(request)
        if not items:
            voices = self.get_default_voices()
        else:
            voices = []
            for item in items:
                self.add_voice(voices, item)

        return JsonResponse(voices, safe=False)

    def get_menu(self, request):

# 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/views.py
import hashlib
from django.http import JsonResponse
from django.contrib.admin import site
from django.contrib.admin.views.decorators import staff_member_required
from django.utils.decorators import method_decorator
from django.core.exceptions import ImproperlyConfigured
from django.views import View
from .config import get_config




class GetAppListJsonView(View):

    @method_decorator(staff_member_required)
    def dispatch(self, *args, **kwargs):
        """ Only staff members can access this view """
        return super(GetAppListJsonView, self).dispatch(*args, **kwargs)

    def get(self, request):
        """ Returns a json representing the menu voices
            in a format eaten by the js menu.
            Raised ImproperlyConfigured exceptions can be viewed
            in the browser console
        """
        self.app_list = site.get_app_list(request)
        self.apps_dict = self.create_app_list_dict()
        # no menu provided
        items = self.get_menu(request)
        if not items:
            voices = self.get_default_voices()
        else:
            voices = []
            for item in items:
                self.add_voice(voices, item)

        return JsonResponse(voices, safe=False)

    def get_menu(self, request):

        return get_config('MENU')