import json

from django.conf import settings
from django.core.serializers.json import DjangoJSONEncoder
from django.db import models


class LocaleField(models.CharField):
    """CharField with locale settings specific to Kuma defaults."""
    def __init__(self, max_length=7, default=settings.LANGUAGE_CODE,
                 choices=settings.LANGUAGES, *args, **kwargs):
        return super(LocaleField, self).__init__(
            max_length=max_length, default=default, choices=choices,
            *args, **kwargs)


class JSONField(models.TextField):
    """
    JSONField is a generic textfield that neatly serializes/unserializes
    JSON objects seamlessly
    see: http://djangosnippets.org/snippets/1478/
    """

    # Used so to_python() is called
    __metaclass__ = models.SubfieldBase

    def to_python(self, value):
        """Convert our string value to JSON after we load it from the DB"""
        if not value:
            return dict()
        try:
            if (isinstance(value, basestring) or
                    type(value) is unicode):
                return json.loads(value)
        except ValueError:
            return dict()
        return value

    def get_db_prep_save(self, value, connection):
        """Convert our JSON object to a string before we save"""
        if not value:
            return '{}'
        if isinstance(value, dict):
            value = json.dumps(value, cls=DjangoJSONEncoder)
        return super(JSONField, self).get_db_prep_save(value, connection)

@@ -1,17 +1,4 @@
-import json%0A%0A
 from
@@ -30,67 +30,8 @@
 ngs%0A
-from django.core.serializers.json import DjangoJSONEncoder%0A
 from
@@ -413,16 +413,16 @@
 hoices,%0A
+
         
@@ -446,998 +446,4 @@
 gs)%0A
-%0A%0Aclass JSONField(models.TextField):%0A    %22%22%22%0A    JSONField is a generic textfield that neatly serializes/unserializes%0A    JSON objects seamlessly%0A    see: http://djangosnippets.org/snippets/1478/%0A    %22%22%22%0A%0A    # Used so to_python() is called%0A    __metaclass__ = models.SubfieldBase%0A%0A    def to_python(self, value):%0A        %22%22%22Convert our string value to JSON after we load it from the DB%22%22%22%0A        if not value:%0A            return dict()%0A        try:%0A            if (isinstance(value, basestring) or%0A                    type(value) is unicode):%0A                return json.loads(value)%0A        except ValueError:%0A            return dict()%0A        return value%0A%0A    def get_db_prep_save(self, value, connection):%0A        %22%22%22Convert our JSON object to a string before we save%22%22%22%0A        if not value:%0A            return '%7B%7D'%0A        if isinstance(value, dict):%0A            value = json.dumps(value, cls=DjangoJSONEncoder)%0A        return super(JSONField, self).get_db_prep_save(value, connection)%0A

Fix bug 1134650 - Deleted custom JSONField as it's unused.