# Path: chemtrails/utils.py
# def get_environment_variable(name, fallback=None):
#     """
#     Get environment variable and try to cast it to proper python type.
#     :param name: Environment variable name to look for.
#     :param fallback: Default fallback value if ``name`` is not found.
#     :returns: Environment variable value if found, else None.
#     """
#     value = os.environ.get(name, fallback)
#     try:
#         if value in ('true', 'TRUE', 'false', 'FALSE'):
#             value = value.capitalize()
#         value = ast.literal_eval(value)
#     except ValueError:
#         pass
#     return value


import os
from django.apps import AppConfig
from django.conf import settings
from django.db.models.signals import m2m_changed, post_migrate, post_save, pre_delete
from neomodel import config
from chemtrails.utils import get_environment_variable
        from .signals.handlers import (
            m2m_changed_handler, post_migrate_handler,
            post_save_handler, pre_delete_handler
        )




config.AUTO_INSTALL_LABELS = False


class ChemtrailsConfig(AppConfig):
    name = 'chemtrails'

    def ready(self):

        m2m_changed.connect(receiver=m2m_changed_handler,
                            dispatch_uid='chemtrails.signals.handlers.m2m_changed_handler')
        post_save.connect(receiver=post_save_handler,
                          dispatch_uid='chemtrails.signals.handlers.post_save_handler')
        pre_delete.connect(receiver=pre_delete_handler,
                           dispatch_uid='chemtrails.signals.handlers.pre_delete_handler')

        post_migrate.connect(receiver=post_migrate_handler,
                             dispatch_uid='neomodel.core.post_migrate_handler')

        # Neo4j config
        config.DATABASE_URL = getattr(settings, 'NEO4J_BOLT_URL',
                                      os.environ.get('NEO4J_BOLT_URL', config.DATABASE_URL))
        config.FORCE_TIMEZONE = getattr(settings, 'NEO4J_FORCE_TIMEZONE',
                                        get_environment_variable('NEO4J_FORCE_TIMEZONE', False))
        config.ENCRYPTED_CONNECTION = getattr(settings, 'NEO4J_ENCRYPTED_CONNECTION',
                                              get_environment_variable('NEO4J_ENCRYPTED_CONNECTION', True))
        config.MAX_POOL_SIZE = getattr(settings, 'NEO4J_MAX_POOL_SIZE',

# Path: chemtrails/utils.py
# def get_environment_variable(name, fallback=None):
#     """
#     Get environment variable and try to cast it to proper python type.
#     :param name: Environment variable name to look for.
#     :param fallback: Default fallback value if ``name`` is not found.
#     :returns: Environment variable value if found, else None.
#     """
#     value = os.environ.get(name, fallback)
#     try:
#         if value in ('true', 'TRUE', 'false', 'FALSE'):
#             value = value.capitalize()
#         value = ast.literal_eval(value)
#     except ValueError:
#         pass
#     return value


# Path: chemtrails/apps.py
import os
from django.apps import AppConfig
from django.conf import settings
from django.db.models.signals import m2m_changed, post_migrate, post_save, pre_delete
from neomodel import config
from chemtrails.utils import get_environment_variable
        from .signals.handlers import (
            m2m_changed_handler, post_migrate_handler,
            post_save_handler, pre_delete_handler
        )





config.AUTO_INSTALL_LABELS = False


class ChemtrailsConfig(AppConfig):
    name = 'chemtrails'

    def ready(self):

        m2m_changed.connect(receiver=m2m_changed_handler,
                            dispatch_uid='chemtrails.signals.handlers.m2m_changed_handler')
        post_save.connect(receiver=post_save_handler,
                          dispatch_uid='chemtrails.signals.handlers.post_save_handler')
        pre_delete.connect(receiver=pre_delete_handler,
                           dispatch_uid='chemtrails.signals.handlers.pre_delete_handler')

        post_migrate.connect(receiver=post_migrate_handler,
                             dispatch_uid='neomodel.core.post_migrate_handler')

        # Neo4j config
        config.DATABASE_URL = getattr(settings, 'NEO4J_BOLT_URL',
                                      os.environ.get('NEO4J_BOLT_URL', config.DATABASE_URL))
        config.FORCE_TIMEZONE = getattr(settings, 'NEO4J_FORCE_TIMEZONE',
                                        get_environment_variable('NEO4J_FORCE_TIMEZONE', False))
        config.ENCRYPTED_CONNECTION = getattr(settings, 'NEO4J_ENCRYPTED_CONNECTION',
                                              get_environment_variable('NEO4J_ENCRYPTED_CONNECTION', True))
        config.MAX_POOL_SIZE = getattr(settings, 'NEO4J_MAX_POOL_SIZE',

                                       get_environment_variable('NEO4J_MAX_POOL_SIZE', 50))