# 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
                              self.type_and_model_to_query_url),
                self.admin_view(self.type_and_model_to_query),
                name="type_and_model_to_query",
            )
        )
        return urlpatterns + super(TypeAndModelQueryMixin, self).get_urls()

    def type_and_model_to_query(self, request):
        """
        Return JSON for an individual Model instance

        If the required parameters are wrong, return 400 Bad Request
        If the parameters are correct but there is no data, return empty JSON

        """
        try:
            content_type_id = request.GET["content_type_id"]
            object_id = request.GET["object_id"]
        except KeyError:
            return HttpResponseBadRequest()

        try:
            content_type = ContentType.objects.get(pk=content_type_id)
            model = content_type.model_class()
            result = model.objects.get(pk=object_id)
        except ObjectDoesNotExist:
            data = ""
        else:
            data = '%s: "%d: %s"' % (content_type.model, result.pk, result)


# 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

                              self.type_and_model_to_query_url),
                self.admin_view(self.type_and_model_to_query),
                name="type_and_model_to_query",
            )
        )
        return urlpatterns + super(TypeAndModelQueryMixin, self).get_urls()

    def type_and_model_to_query(self, request):
        """
        Return JSON for an individual Model instance

        If the required parameters are wrong, return 400 Bad Request
        If the parameters are correct but there is no data, return empty JSON

        """
        try:
            content_type_id = request.GET["content_type_id"]
            object_id = request.GET["object_id"]
        except KeyError:
            return HttpResponseBadRequest()

        try:
            content_type = ContentType.objects.get(pk=content_type_id)
            model = content_type.model_class()
            result = model.objects.get(pk=object_id)
        except ObjectDoesNotExist:
            data = ""
        else:
            data = '%s: "%d: %s"' % (content_type.model, result.pk, result)


        return JsonResponse({"query": data})