# Path: chemtrails/conf.py
# USER_SETTINGS = getattr(django_settings, 'CHEMTRAILS', None)
# DEFAULTS = {
#     'ENABLED': True,
#     'MAX_CONNECTION_DEPTH': 1,
#     'NAMED_RELATIONSHIPS': True,
#     'CONNECT_META_NODES': False,
#     'IGNORE_MODELS': [
#         'admin.logentry',
#         'migrations.migration',
#     ],
# }
# class CSettings:
#     def __init__(self, user_settings=None, defaults=None):
#     def __getattr__(self, attr):
#     def user_settings(self):
# def reload_settings(*args, **kwargs):
# 
# Path: chemtrails/utils.py
# def get_model_string(model):
#     """
#     :param model: model
#     :returns: <app_label>.<model_name> string representation for the model
#     """
#     return "{app_label}.{model_name}".format(app_label=model._meta.app_label, model_name=model._meta.model_name)
# 
# def flatten(sequence):
#     """
#     Flatten an arbitrary nested sequence.
#     Example usage:
#       >> my_list = list(flatten(nested_lists))
#     :param sequence: A nested list or tuple.
#     :returns: A generator with all values in a flat structure.
#     """
#     for i in sequence:
#         if isinstance(i, Sequence) and not isinstance(i, (str, bytes)):
#             yield from flatten(i)
#         else:
#             yield i
# 
# def timeit(func):
#     """
#     Decorator which logs the timing of executing a function
#     or method call to DEBUG logger.
#     """
#     @functools.wraps(func)
#     def f(*args, **kwargs):
#         timestamp = time.time()
#         func(*args, **kwargs)
#         logger.debug('function [{0}] executed in {1}s'.format(
#             f.__name__, '%.5f' % (time.time() - timestamp)
#         ))
#     return f


import itertools
import logging
import operator
        import csv
from collections import defaultdict, MutableMapping
from functools import reduce
from django.db import models
from django.db.models import Manager
from django.contrib.contenttypes.fields import GenericRelation, GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ImproperlyConfigured, ValidationError, ObjectDoesNotExist
from django.contrib.postgres.fields import HStoreField, JSONField, RangeField
from django.utils.translation import ungettext
from neomodel import *
from chemtrails.conf import settings
from chemtrails.utils import get_model_string, flatten, timeit
        from chemtrails.neoutils import __node_cache__
        from chemtrails.conf import settings
        from chemtrails.neoutils.managers import PathManager
        from chemtrails.neoutils import (
            __meta_cache__, __node_cache__,
            get_node_class_for_model, get_meta_node_class_for_model
        )
            from chemtrails.neoutils import get_node_class_for_model
        from chemtrails.neoutils import get_node_for_object
        from chemtrails.neoutils import get_node_for_object
        from chemtrails.neoutils import __meta_cache__
        from chemtrails.neoutils import get_meta_node_for_model

class MetaNodeMixin(ModelNodeMixin):
    """
    Mixin class for ``StructuredNode`` which adds a number of class methods
    in order to calculate relationship fields from a Django model class.
    """

    def __init__(self, *args, **kwargs):
        self._instance = self.__class__.Meta.model
        self.__recursion_depth__ = 0

        defaults = {key: getattr(self._instance._meta, key, kwargs.get(key, None))
                    for key, _ in self.__all_properties__}
        kwargs.update(defaults)
        StructuredNode.__init__(self, *args, **kwargs)

        # FIXME: Don't look up against id if using inflate with a raw query.
        if not hasattr(self, 'id'):
            params = self.deflate(self.__properties__)

            # Remove any attributes we don't want to include in the MATCH query.
            exclude = ('model_permisssions', 'is_intermediary')
            for attr in exclude:
                if attr in params:
                    del params[attr]

            node_id = self._get_id_from_database(params)
            if node_id:
                self.id = node_id


# Path: chemtrails/conf.py
# USER_SETTINGS = getattr(django_settings, 'CHEMTRAILS', None)
# DEFAULTS = {
#     'ENABLED': True,
#     'MAX_CONNECTION_DEPTH': 1,
#     'NAMED_RELATIONSHIPS': True,
#     'CONNECT_META_NODES': False,
#     'IGNORE_MODELS': [
#         'admin.logentry',
#         'migrations.migration',
#     ],
# }
# class CSettings:
#     def __init__(self, user_settings=None, defaults=None):
#     def __getattr__(self, attr):
#     def user_settings(self):
# def reload_settings(*args, **kwargs):
# 
# Path: chemtrails/utils.py
# def get_model_string(model):
#     """
#     :param model: model
#     :returns: <app_label>.<model_name> string representation for the model
#     """
#     return "{app_label}.{model_name}".format(app_label=model._meta.app_label, model_name=model._meta.model_name)
# 
# def flatten(sequence):
#     """
#     Flatten an arbitrary nested sequence.
#     Example usage:
#       >> my_list = list(flatten(nested_lists))
#     :param sequence: A nested list or tuple.
#     :returns: A generator with all values in a flat structure.
#     """
#     for i in sequence:
#         if isinstance(i, Sequence) and not isinstance(i, (str, bytes)):
#             yield from flatten(i)
#         else:
#             yield i
# 
# def timeit(func):
#     """
#     Decorator which logs the timing of executing a function
#     or method call to DEBUG logger.
#     """
#     @functools.wraps(func)
#     def f(*args, **kwargs):
#         timestamp = time.time()
#         func(*args, **kwargs)
#         logger.debug('function [{0}] executed in {1}s'.format(
#             f.__name__, '%.5f' % (time.time() - timestamp)
#         ))
#     return f


# Path: chemtrails/neoutils/core.py
import itertools
import logging
import operator
        import csv
from collections import defaultdict, MutableMapping
from functools import reduce
from django.db import models
from django.db.models import Manager
from django.contrib.contenttypes.fields import GenericRelation, GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ImproperlyConfigured, ValidationError, ObjectDoesNotExist
from django.contrib.postgres.fields import HStoreField, JSONField, RangeField
from django.utils.translation import ungettext
from neomodel import *
from chemtrails.conf import settings
from chemtrails.utils import get_model_string, flatten, timeit
        from chemtrails.neoutils import __node_cache__
        from chemtrails.conf import settings
        from chemtrails.neoutils.managers import PathManager
        from chemtrails.neoutils import (
            __meta_cache__, __node_cache__,
            get_node_class_for_model, get_meta_node_class_for_model
        )
            from chemtrails.neoutils import get_node_class_for_model
        from chemtrails.neoutils import get_node_for_object
        from chemtrails.neoutils import get_node_for_object
        from chemtrails.neoutils import __meta_cache__
        from chemtrails.neoutils import get_meta_node_for_model


class MetaNodeMixin(ModelNodeMixin):
    """
    Mixin class for ``StructuredNode`` which adds a number of class methods
    in order to calculate relationship fields from a Django model class.
    """

    def __init__(self, *args, **kwargs):
        self._instance = self.__class__.Meta.model
        self.__recursion_depth__ = 0

        defaults = {key: getattr(self._instance._meta, key, kwargs.get(key, None))
                    for key, _ in self.__all_properties__}
        kwargs.update(defaults)
        StructuredNode.__init__(self, *args, **kwargs)

        # FIXME: Don't look up against id if using inflate with a raw query.
        if not hasattr(self, 'id'):
            params = self.deflate(self.__properties__)

            # Remove any attributes we don't want to include in the MATCH query.
            exclude = ('model_permisssions', 'is_intermediary')
            for attr in exclude:
                if attr in params:
                    del params[attr]

            node_id = self._get_id_from_database(params)
            if node_id:
                self.id = node_id


    @timeit