from os import getenv

DEBUG = True

DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": "test.db",}}
# DATABASES = {
#     "default": {
#         "ENGINE": "django.db.backends.postgresql",
#         "NAME": getenv("TEST_DB_NAME", "elasticsearch_django"),
#         "USER": getenv("TEST_DB_USER", "postgres"),
#         "PASSWORD": getenv("TEST_DB_PASSWORD", "postgres"),
#         "HOST": getenv("TEST_DB_HOST", "localhost"),
#         "PORT": getenv("TEST_DB_PORT", "5432"),
#     }
# }

INSTALLED_APPS = (
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.sessions",
    "django.contrib.contenttypes",
    "django.contrib.sites",
    "django.contrib.staticfiles",
    "django.contrib.messages",
    "elasticsearch_django",
    "tests",
)

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
]

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [],
        "APP_DIRS": True,
        "OPTIONS": {
            "context_processors": [
                "django.template.context_processors.debug",
                "django.template.context_processors.request",
                "django.contrib.auth.context_processors.auth",
                "django.contrib.messages.context_processors.messages",
            ]
        },
    }
]

SECRET_KEY = "elasticsearch_django"

ROOT_URLCONF = "tests.urls"

APPEND_SLASH = True

STATIC_URL = "/static/"
STATIC_ROOT = "staticfiles"

TIME_ZONE = "UTC"

SITE_ID = 1

###########
# LOGGING #
###########
LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "formatters": {"simple": {"format": "%(levelname)s %(message)s"}},
    "handlers": {
        "console": {
            "level": "DEBUG",
            "class": "logging.StreamHandler",
            "formatter": "simple",
        },
        "null": {"level": "DEBUG", "class": "logging.NullHandler"},
    },
    "loggers": {
        "": {"handlers": ["null"], "propagate": True, "level": "DEBUG"},
        "elasticsearch_django": {
            "handlers": ["console"],
            "level": "DEBUG",
            "propagate": False,
        },
        # 'django': {
        #     'handlers': ['console'],
        #     'level': getenv('LOGGING_LEVEL_DJANGO', 'WARNING'),
        #     'propagate': False,
        # },
        # 'django.db.backends': {
        #     'level': 'ERROR',
        #     'handlers': ['console'],
        #     'propagate': False,
        # },
        # 'elasticsearch': {
        #     'handlers': ['console'],
        #     'level': getenv('LOGGING_LEVEL_SEARCH', 'WARNING'),
        #     'propagate': False,
        # },
        # 'elasticsearch.trace': {
        #     'handlers': ['console'],
        #     'level': getenv('LOGGING_LEVEL_SEARCH', 'WARNING'),
        #     'propagate': False,
        # },
        # 'requests': {
        #     'handlers': ['console'],
        #     'level': getenv('LOGGING_LEVEL_REQUESTS', 'WARNING'),
        #     'propagate': False,
        # },
        # 'requests.packages.urllib3': {
        #     'handlers': ['console'],
        #     'level': getenv('LOGGING_LEVEL_REQUESTS', 'WARNING'),
        #     'propagate': False,
        # },
        # 'urllib3': {
        #     'handlers': ['console'],
        #     'level': getenv('LOGGING_LEVEL_REQUESTS', 'WARNING'),
        #     'propagate': False,
        # },
    },
}

SEARCH_SETTINGS = {
    "connections": {"default": getenv("ELASTICSEARCH_URL")},
    "indexes": {
        # name of the index
        "examples": {
            "models": [
                # model used to populate the index, in app.model format
                "tests.ExampleModel",
            ]
        },
    },
    "settings": {
        # batch size for ES bulk api operations
        "chunk_size": 500,
        # default page size for search results
        "page_size": 25,
        # set to False to prevent automatic signal connections
        "auto_sync": True,
        # List of models which will never auto_sync even if auto_sync is True
        # Use the same app.model format as in 'indexes' above.
        "never_auto_sync": [],
        "update_strategy": "full",
        # if True, raise ImproperlyConfigured if an index has no mapping file
        "strict_validation": False,
        # path/to/mappings/dir - where mapping files will be expected
        "mappings_dir": "mappings",
    },
}

assert DEBUG is True, "This project is only intended to be used for testing."

@@ -30,16 +30,64 @@
 = True%0A%0A
+try:%0A    import django.db.models.JSONField%0A%0A    
 DATABASE
@@ -91,16 +91,25 @@
 ASES = %7B
+%0A        
 %22default
@@ -171,19 +171,46 @@
 st.db%22,%7D
-%7D%0A#
+%0A    %7D%0Aexcept ImportError:%0A   
  DATABAS
@@ -216,17 +216,19 @@
 SES = %7B%0A
-#
+   
      %22de
@@ -237,17 +237,19 @@
 ult%22: %7B%0A
-#
+   
         
@@ -292,17 +292,19 @@
 resql%22,%0A
-#
+   
         
@@ -356,25 +356,27 @@
 h_django%22),%0A
-#
+   
          %22US
@@ -408,33 +408,35 @@
 %22, %22postgres%22),%0A
-#
+   
          %22PASSWO
@@ -476,25 +476,24 @@
 postgres%22),%0A
-#
          %22HO
@@ -489,16 +489,19 @@
         
+   
 %22HOST%22: 
@@ -533,25 +533,24 @@
 ocalhost%22),%0A
-#
          %22PO
@@ -546,16 +546,19 @@
         
+   
 %22PORT%22: 
@@ -593,17 +593,21 @@
 %22),%0A
-#
+   
      %7D%0A
-#
+   
  %7D%0A%0A

Add sqlite or postgres settings based on JSONField import