# Path: yak/rest_core/models.py
# class CoreModel(models.Model):
#     created = models.DateTimeField(auto_now_add=True, null=True)
# 
#     def __repr__(self):
#         return '<{}:{} {}>'.format(self.__class__.__name__, self.pk, str(self))
# 
#     class Meta:
#         abstract = True
# 
# Path: yak/settings.py
# def perform_import(val, setting_name):
#     def __getattr__(self, attr):
# class YAKAPISettings(APISettings):
# USER_SETTINGS = getattr(settings, 'YAK', None)
# DEFAULTS = {
#     'USER_APP_LABEL': 'test_app',
#     'USER_MODEL': 'user',
#     'USER_SERIALIZER': "test_app.api.serializers.UserSerializer",
#     'API_SCHEMA': 'api-schema-1.0.json',
#     'SOCIAL_MODEL': "test_app.models.Post",
#     'ALLOW_EMAIL': True,
#     'ALLOW_PUSH': True,
#     'EMAIL_NOTIFICATION_SUBJECT': 'Test Project Notification',
#     'PUSHWOOSH_AUTH_TOKEN': "",
#     'PUSHWOOSH_APP_CODE': "",
#     'PUSH_NOTIFICATION_HANDLER': "yak.rest_notifications.utils.send_pushwoosh_notification",
#     'SOCIAL_SHARE_DELAY': 60,
#     'USE_FACEBOOK_OG': False,
#     'FACEBOOK_OG_NAMESPACE': "",
#     'SERIALIZER_MAPPING': {},
#     'FLAKE8_CONFIG': None,
# }
# IMPORT_STRINGS = (
#     "USER_SERIALIZER",
#     "SOCIAL_MODEL",
#     "SERIALIZER_MAPPING",
# )


from collections import defaultdict
from caching.base import CachingMixin, CachingManager
from django.conf import settings
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from django.db import models
from django.template.loader import render_to_string
from celery.task import task
from yak.rest_core.models import CoreModel
from yak.settings import yak_settings
        from .utils import send_push_notification
        from .utils import send_email_notification
    def name(self):
        return "{}".format(self.notification_type)

    def __unicode__(self):
        return "{}: {}".format(self.user, self.notification_type)

    class Meta:
        ordering = ['-created']


@task
def create_notification(receiver, reporter, content_object, notification_type, template_override=None, reply_to=None,
                        deep_link=None):
    # If the receiver of this notification is the same as the reporter or
    # if the user has blocked this type, then don't create
    if receiver == reporter:
        return

    notification = Notification.objects.create(user=receiver,
                                               reporter=reporter,
                                               content_object=content_object,
                                               notification_type=notification_type,
                                               template_override=template_override,
                                               deep_link=deep_link)
    notification.save()

    notification_setting = NotificationSetting.objects.get(notification_type=notification_type, user=receiver)
    if notification_setting.allow_push and yak_settings.ALLOW_PUSH:
        send_push_notification(receiver, notification.push_message(), deep_link=deep_link)


# Path: yak/rest_core/models.py
# class CoreModel(models.Model):
#     created = models.DateTimeField(auto_now_add=True, null=True)
# 
#     def __repr__(self):
#         return '<{}:{} {}>'.format(self.__class__.__name__, self.pk, str(self))
# 
#     class Meta:
#         abstract = True
# 
# Path: yak/settings.py
# def perform_import(val, setting_name):
#     def __getattr__(self, attr):
# class YAKAPISettings(APISettings):
# USER_SETTINGS = getattr(settings, 'YAK', None)
# DEFAULTS = {
#     'USER_APP_LABEL': 'test_app',
#     'USER_MODEL': 'user',
#     'USER_SERIALIZER': "test_app.api.serializers.UserSerializer",
#     'API_SCHEMA': 'api-schema-1.0.json',
#     'SOCIAL_MODEL': "test_app.models.Post",
#     'ALLOW_EMAIL': True,
#     'ALLOW_PUSH': True,
#     'EMAIL_NOTIFICATION_SUBJECT': 'Test Project Notification',
#     'PUSHWOOSH_AUTH_TOKEN': "",
#     'PUSHWOOSH_APP_CODE': "",
#     'PUSH_NOTIFICATION_HANDLER': "yak.rest_notifications.utils.send_pushwoosh_notification",
#     'SOCIAL_SHARE_DELAY': 60,
#     'USE_FACEBOOK_OG': False,
#     'FACEBOOK_OG_NAMESPACE': "",
#     'SERIALIZER_MAPPING': {},
#     'FLAKE8_CONFIG': None,
# }
# IMPORT_STRINGS = (
#     "USER_SERIALIZER",
#     "SOCIAL_MODEL",
#     "SERIALIZER_MAPPING",
# )


# Path: yak/rest_notifications/models.py
from collections import defaultdict
from caching.base import CachingMixin, CachingManager
from django.conf import settings
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from django.db import models
from django.template.loader import render_to_string
from celery.task import task
from yak.rest_core.models import CoreModel
from yak.settings import yak_settings
        from .utils import send_push_notification
        from .utils import send_email_notification

    def name(self):
        return "{}".format(self.notification_type)

    def __unicode__(self):
        return "{}: {}".format(self.user, self.notification_type)

    class Meta:
        ordering = ['-created']


@task
def create_notification(receiver, reporter, content_object, notification_type, template_override=None, reply_to=None,
                        deep_link=None):
    # If the receiver of this notification is the same as the reporter or
    # if the user has blocked this type, then don't create
    if receiver == reporter:
        return

    notification = Notification.objects.create(user=receiver,
                                               reporter=reporter,
                                               content_object=content_object,
                                               notification_type=notification_type,
                                               template_override=template_override,
                                               deep_link=deep_link)
    notification.save()

    notification_setting = NotificationSetting.objects.get(notification_type=notification_type, user=receiver)
    if notification_setting.allow_push and yak_settings.ALLOW_PUSH:
        send_push_notification(receiver, notification.push_message(), deep_link=deep_link)


    if notification_setting.allow_email and yak_settings.ALLOW_EMAIL and receiver.email: