# Path: hedwig/django/settings.py
# HEDWIG_USER_SETTINGS = getattr(settings, 'HEDWIG', None)
# HEDWIG_DJANGO_USER_SETTINGS = getattr(settings, 'HEDWIG_DJANGO', None)
# DJANGO_DEFAULTS = {
#     'MODEL_SIGNALS': False,
#     'HIDE_FIELDS': False,
#     'NATURAL_PRIMARY_KEYS': True,
#     'NATURAL_FOREIGN_KEYS': True
# }
# MODEL_DEFAULTS = {
#     'fields': not bool(hedwig_django_settings.HIDE_FIELDS),
#     'natural_primary_keys': bool(hedwig_django_settings.NATURAL_PRIMARY_KEYS),
#     'natural_foreign_keys': bool(hedwig_django_settings.NATURAL_FOREIGN_KEYS),
#     'created': True,
#     'updated': True,
#     'deleted': True
# }
# 
# Path: hedwig/core/settings.py
# class Settings(object):
#     """
#     A settings object, that allows HEDWIG settings to be accessed as properties.
#     """
# 
#     def __init__(self, user_settings=None, defaults=None):
#         self.user_settings = user_settings or {}
#         self.defaults = defaults or DEFAULTS
#         if isinstance(self.user_settings, dict):
#             self.user_settings = dict_merge(self.defaults, self.user_settings)
#         else:
#             raise TypeError("Expected settings to be a dict")
# 
#     def __getattr__(self, attr):
#         if attr not in self.defaults.keys():
#             raise AttributeError("Invalid HEDWIG setting: '%s'" % attr)
# 
#         try:
#             # Check if present in user settings
#             val = self.user_settings[attr]
#         except KeyError:
#             # Fall back to defaults
#             val = self.defaults[attr]
# 
#         # Cache the result
#         setattr(self, attr, val)
#         return val
# 
#     def __getitem__(self, item):
#         return getattr(self, item)
# 
# Path: hedwig/django/emitter.py



import json
import inspect
import logging
from django.db.models.signals import post_save, post_delete
from django.core import serializers
from .settings import project_name, MODEL_DEFAULTS
from hedwig.core.settings import Settings
from .emitter import hedwig_emitter



LOGGER = logging.getLogger(__name__)


def coerce_model_settings(instance):
    model_hedwig_dict = {}
    model_hedwig = getattr(instance, 'Hedwig', None)
    if inspect.isclass(model_hedwig):
        model_hedwig_dict = dict((name, getattr(model_hedwig, name)) for name in dir(model_hedwig) if not name.startswith('__'))
    return Settings(user_settings=model_hedwig_dict, defaults=MODEL_DEFAULTS)


def saved_hedwig_models(sender, instance, created, **kwargs):
    if created:
        action = 'created'
    else:

# Path: hedwig/django/settings.py
# HEDWIG_USER_SETTINGS = getattr(settings, 'HEDWIG', None)
# HEDWIG_DJANGO_USER_SETTINGS = getattr(settings, 'HEDWIG_DJANGO', None)
# DJANGO_DEFAULTS = {
#     'MODEL_SIGNALS': False,
#     'HIDE_FIELDS': False,
#     'NATURAL_PRIMARY_KEYS': True,
#     'NATURAL_FOREIGN_KEYS': True
# }
# MODEL_DEFAULTS = {
#     'fields': not bool(hedwig_django_settings.HIDE_FIELDS),
#     'natural_primary_keys': bool(hedwig_django_settings.NATURAL_PRIMARY_KEYS),
#     'natural_foreign_keys': bool(hedwig_django_settings.NATURAL_FOREIGN_KEYS),
#     'created': True,
#     'updated': True,
#     'deleted': True
# }
# 
# Path: hedwig/core/settings.py
# class Settings(object):
#     """
#     A settings object, that allows HEDWIG settings to be accessed as properties.
#     """
# 
#     def __init__(self, user_settings=None, defaults=None):
#         self.user_settings = user_settings or {}
#         self.defaults = defaults or DEFAULTS
#         if isinstance(self.user_settings, dict):
#             self.user_settings = dict_merge(self.defaults, self.user_settings)
#         else:
#             raise TypeError("Expected settings to be a dict")
# 
#     def __getattr__(self, attr):
#         if attr not in self.defaults.keys():
#             raise AttributeError("Invalid HEDWIG setting: '%s'" % attr)
# 
#         try:
#             # Check if present in user settings
#             val = self.user_settings[attr]
#         except KeyError:
#             # Fall back to defaults
#             val = self.defaults[attr]
# 
#         # Cache the result
#         setattr(self, attr, val)
#         return val
# 
#     def __getitem__(self, item):
#         return getattr(self, item)
# 
# Path: hedwig/django/emitter.py



# Path: hedwig/django/signals.py
import json
import inspect
import logging
from django.db.models.signals import post_save, post_delete
from django.core import serializers
from .settings import project_name, MODEL_DEFAULTS
from hedwig.core.settings import Settings
from .emitter import hedwig_emitter




LOGGER = logging.getLogger(__name__)


def coerce_model_settings(instance):
    model_hedwig_dict = {}
    model_hedwig = getattr(instance, 'Hedwig', None)
    if inspect.isclass(model_hedwig):
        model_hedwig_dict = dict((name, getattr(model_hedwig, name)) for name in dir(model_hedwig) if not name.startswith('__'))
    return Settings(user_settings=model_hedwig_dict, defaults=MODEL_DEFAULTS)


def saved_hedwig_models(sender, instance, created, **kwargs):
    if created:
        action = 'created'
    else:

        action = 'updated'