# Path: armstrong/hatband/http.py
# class JsonResponse(HttpResponse):
#     """
#     Simple HttpResponse object that takes a JSON value as it's parameter
# 
#     TODO: Find a proper home for this.
#     """
#     def __init__(self, data, *args, **kwargs):
#         super(JsonResponse, self).__init__(json.dumps(data), *args, **kwargs)


from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.db.models import Q
from django.http import HttpResponse
from django.http import HttpResponseBadRequest, HttpResponseNotFound
from django.core.exceptions import ObjectDoesNotExist
    from django.conf.urls import patterns, url
    from django.conf.urls.defaults import patterns, url
from armstrong.core.arm_layout.utils import render_model
from ..http import JsonResponse
    ])


class ArmstrongBaseMixin(object):
    url_prefix = "armstrong"


class GenericKeyFacetsMixin(ArmstrongBaseMixin):
    url = "search/generickey/facets/"

    def get_urls(self):
        urlpatterns = patterns('',
            url(r"^%s/%s$" % (self.url_prefix, self.url),
                self.admin_view(self.generic_key_facets),
                name="generic_key_facets",
            )
        )
        return urlpatterns + super(GenericKeyFacetsMixin, self).get_urls()

    def generic_key_facets(self, request):
        """Find all available facets/Models for VisualSearch"""

        excluded_apps = Q(app_label__in=EXCLUDED_APPS_FROM_FACETS)
        excluded_models = Q()
        for app_label, model in EXCLUDED_MODELS_FROM_FACETS:
            excluded_models = excluded_models | Q(app_label=app_label,
                    model=model)
        values = "model", "app_label", "id"
        content_types = ContentType.objects.values_list(*values) \
                .exclude(excluded_apps | excluded_models)

# Path: armstrong/hatband/http.py
# class JsonResponse(HttpResponse):
#     """
#     Simple HttpResponse object that takes a JSON value as it's parameter
# 
#     TODO: Find a proper home for this.
#     """
#     def __init__(self, data, *args, **kwargs):
#         super(JsonResponse, self).__init__(json.dumps(data), *args, **kwargs)


# Path: armstrong/hatband/views/search.py
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.db.models import Q
from django.http import HttpResponse
from django.http import HttpResponseBadRequest, HttpResponseNotFound
from django.core.exceptions import ObjectDoesNotExist
    from django.conf.urls import patterns, url
    from django.conf.urls.defaults import patterns, url
from armstrong.core.arm_layout.utils import render_model
from ..http import JsonResponse

    ])


class ArmstrongBaseMixin(object):
    url_prefix = "armstrong"


class GenericKeyFacetsMixin(ArmstrongBaseMixin):
    url = "search/generickey/facets/"

    def get_urls(self):
        urlpatterns = patterns('',
            url(r"^%s/%s$" % (self.url_prefix, self.url),
                self.admin_view(self.generic_key_facets),
                name="generic_key_facets",
            )
        )
        return urlpatterns + super(GenericKeyFacetsMixin, self).get_urls()

    def generic_key_facets(self, request):
        """Find all available facets/Models for VisualSearch"""

        excluded_apps = Q(app_label__in=EXCLUDED_APPS_FROM_FACETS)
        excluded_models = Q()
        for app_label, model in EXCLUDED_MODELS_FROM_FACETS:
            excluded_models = excluded_models | Q(app_label=app_label,
                    model=model)
        values = "model", "app_label", "id"
        content_types = ContentType.objects.values_list(*values) \
                .exclude(excluded_apps | excluded_models)

        return JsonResponse(dict([(str(a), {"app_label": str(b), "id": str(c)})