# Path: yak/rest_notifications/models.py
# class NotificationSetting(CoreModel):
#     notification_type = models.ForeignKey(NotificationType, related_name="user_settings", on_delete=models.CASCADE)
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='notification_settings', on_delete=models.CASCADE)
#     allow_push = models.BooleanField(default=True)
#     allow_email = models.BooleanField(default=True)
# 
#     class Meta:
#         unique_together = ('notification_type', 'user')
#         ordering = ['-created']
# 
#     def __unicode__(self):
#         return "{}: {}".format(self.user, self.notification_type)
# 
#     def name(self):
#         return "{}: {}".format(self.user, self.notification_type)
# 
# class Notification(CoreModel):
#     PUSH = "push"
#     EMAIL = "email"
# 
#     notification_type = models.ForeignKey(NotificationType, related_name="notifications", on_delete=models.CASCADE)
#     template_override = models.CharField(max_length=100, blank=True, null=True)
#     deep_link = models.CharField(max_length=100, blank=True, null=True)
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="notifications_received", null=True, blank=True,
#                              on_delete=models.CASCADE)
#     reporter = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="notifications_sent", null=True, blank=True,
#                                  on_delete=models.CASCADE)
# 
#     # The object that the notification is about, not the social model related to it
#     # E.g., if you Like a Post, the content_object for the notification is the Post, not the Like
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField(db_index=True)
#     content_object = GenericForeignKey()
# 
#     def message(self, location):
#         """
#         Takes our configured notifications and creates a message
#         replacing the appropriate variables from the content object
#         """
# 
#         data = defaultdict(str)
#         # get the domain from Site
#         data['domain'] = Site.objects.get_current().domain
# 
#         if self.content_object:
#             data['identifier'] = self.content_object.identifier()
#         if self.reporter:
#             data['reporter'] = self.reporter.identifier()
# 
#         if hasattr(self.content_object, 'extra_notification_params'):
#             data.update(self.content_object.extra_notification_params())
# 
#         configured_template_name = "{}.html".format(self.notification_type.slug)
#         template_name = self.template_override if self.template_override else configured_template_name
#         return render_to_string("notifications/{}/{}".format(location, template_name), data)
# 
#     def email_message(self):
#         return self.message(Notification.EMAIL)
# 
#     def push_message(self):
#         message = self.message(Notification.PUSH)
#         if self.reporter:
#             return "{0} {1}".format(self.reporter, message)
#         else:
#             return "{0}".format(message)
# 
#     @property
#     def name(self):
#         return "{}".format(self.notification_type)
# 
#     def __unicode__(self):
#         return "{}: {}".format(self.user, self.notification_type)
# 
#     class Meta:
#         ordering = ['-created']
# 
# class PushwooshToken(CoreModel):
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="pushwoosh_tokens", on_delete=models.CASCADE)
#     token = models.CharField(max_length=255)
# 
# class NotificationType(CachingMixin, CoreModel):
#     name = models.CharField(max_length=32)
#     slug = models.SlugField(unique=True)
#     description = models.CharField(max_length=255)
#     is_active = models.BooleanField(default=True)
# 
#     objects = CachingManager()
# 
#     def __unicode__(self):
#         return "{}".format(self.name)
# 
# Path: yak/rest_user/serializers.py
# class UserSerializer(AuthSerializerMixin, YAKModelSerializer):
# 
#     def __new__(cls, *args, **kwargs):
#         """
#         Can't just inherit in the class definition due to lots of import issues
#         """
#         return yak_settings.USER_SERIALIZER(*args, **kwargs)
# 
# 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 rest_framework import serializers
from yak.rest_notifications.models import NotificationSetting, Notification, PushwooshToken, NotificationType
from yak.rest_user.serializers import UserSerializer
from yak.settings import yak_settings


class PushwooshTokenSerializer(serializers.ModelSerializer):
    user = UserSerializer(read_only=True, default=serializers.CurrentUserDefault())
    hwid = serializers.CharField(write_only=True)
    language = serializers.CharField(write_only=True)
    platform = serializers.CharField(write_only=True)

    class Meta:

# Path: yak/rest_notifications/models.py
# class NotificationSetting(CoreModel):
#     notification_type = models.ForeignKey(NotificationType, related_name="user_settings", on_delete=models.CASCADE)
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='notification_settings', on_delete=models.CASCADE)
#     allow_push = models.BooleanField(default=True)
#     allow_email = models.BooleanField(default=True)
# 
#     class Meta:
#         unique_together = ('notification_type', 'user')
#         ordering = ['-created']
# 
#     def __unicode__(self):
#         return "{}: {}".format(self.user, self.notification_type)
# 
#     def name(self):
#         return "{}: {}".format(self.user, self.notification_type)
# 
# class Notification(CoreModel):
#     PUSH = "push"
#     EMAIL = "email"
# 
#     notification_type = models.ForeignKey(NotificationType, related_name="notifications", on_delete=models.CASCADE)
#     template_override = models.CharField(max_length=100, blank=True, null=True)
#     deep_link = models.CharField(max_length=100, blank=True, null=True)
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="notifications_received", null=True, blank=True,
#                              on_delete=models.CASCADE)
#     reporter = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="notifications_sent", null=True, blank=True,
#                                  on_delete=models.CASCADE)
# 
#     # The object that the notification is about, not the social model related to it
#     # E.g., if you Like a Post, the content_object for the notification is the Post, not the Like
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField(db_index=True)
#     content_object = GenericForeignKey()
# 
#     def message(self, location):
#         """
#         Takes our configured notifications and creates a message
#         replacing the appropriate variables from the content object
#         """
# 
#         data = defaultdict(str)
#         # get the domain from Site
#         data['domain'] = Site.objects.get_current().domain
# 
#         if self.content_object:
#             data['identifier'] = self.content_object.identifier()
#         if self.reporter:
#             data['reporter'] = self.reporter.identifier()
# 
#         if hasattr(self.content_object, 'extra_notification_params'):
#             data.update(self.content_object.extra_notification_params())
# 
#         configured_template_name = "{}.html".format(self.notification_type.slug)
#         template_name = self.template_override if self.template_override else configured_template_name
#         return render_to_string("notifications/{}/{}".format(location, template_name), data)
# 
#     def email_message(self):
#         return self.message(Notification.EMAIL)
# 
#     def push_message(self):
#         message = self.message(Notification.PUSH)
#         if self.reporter:
#             return "{0} {1}".format(self.reporter, message)
#         else:
#             return "{0}".format(message)
# 
#     @property
#     def name(self):
#         return "{}".format(self.notification_type)
# 
#     def __unicode__(self):
#         return "{}: {}".format(self.user, self.notification_type)
# 
#     class Meta:
#         ordering = ['-created']
# 
# class PushwooshToken(CoreModel):
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="pushwoosh_tokens", on_delete=models.CASCADE)
#     token = models.CharField(max_length=255)
# 
# class NotificationType(CachingMixin, CoreModel):
#     name = models.CharField(max_length=32)
#     slug = models.SlugField(unique=True)
#     description = models.CharField(max_length=255)
#     is_active = models.BooleanField(default=True)
# 
#     objects = CachingManager()
# 
#     def __unicode__(self):
#         return "{}".format(self.name)
# 
# Path: yak/rest_user/serializers.py
# class UserSerializer(AuthSerializerMixin, YAKModelSerializer):
# 
#     def __new__(cls, *args, **kwargs):
#         """
#         Can't just inherit in the class definition due to lots of import issues
#         """
#         return yak_settings.USER_SERIALIZER(*args, **kwargs)
# 
# 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/serializers.py
from rest_framework import serializers
from yak.rest_notifications.models import NotificationSetting, Notification, PushwooshToken, NotificationType
from yak.rest_user.serializers import UserSerializer
from yak.settings import yak_settings



class PushwooshTokenSerializer(serializers.ModelSerializer):
    user = UserSerializer(read_only=True, default=serializers.CurrentUserDefault())
    hwid = serializers.CharField(write_only=True)
    language = serializers.CharField(write_only=True)
    platform = serializers.CharField(write_only=True)

    class Meta:

        model = PushwooshToken