# Path: yak/rest_social_network/models.py
# class Tag(CoreModel):
#     name = models.CharField(max_length=75, unique=True)
# 
#     class Meta:
#         ordering = ['-created']
# 
#     def identifier(self):
#         return "#{}".format(self.name)
# 
#     def type(self):
#         return "tag"
# 
#     def __unicode__(self):
#         return "{}".format(self.name)
# 
# class Comment(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField(db_index=True)
#     content_object = GenericForeignKey()
# 
#     TAG_FIELD = 'description'
#     related_tags = models.ManyToManyField(Tag, blank=True)
# 
#     description = models.TextField()
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="comments", on_delete=models.CASCADE)
# 
#     class Meta:
#         ordering = ['created']
# 
# class Follow(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField(db_index=True)
#     content_object = GenericForeignKey()
# 
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="following", on_delete=models.CASCADE)
# 
#     @property
#     def object_type(self):
#         return self.content_type.name
# 
#     @property
#     def name(self):
#         # object must be registered with FollowableModel
#         return self.content_object.identifier()
# 
#     class Meta:
#         unique_together = (("user", "content_type", "object_id"),)
#         ordering = ['created']
# 
# class Flag(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField()
#     content_object = GenericForeignKey()
# 
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="flags", on_delete=models.CASCADE)
# 
#     class Meta:
#         unique_together = (("user", "content_type", "object_id"),)
# 
# class Share(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField()
#     content_object = GenericForeignKey()
#     shared_with = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='shared_with')
# 
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="shares", on_delete=models.CASCADE)
# 
# class Like(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField(db_index=True)
#     content_object = GenericForeignKey()
# 
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="likes", on_delete=models.CASCADE)
# 
#     class Meta:
#         unique_together = (("user", "content_type", "object_id"),)
# 
# 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)


from django.contrib.auth import get_user_model
from rest_framework import serializers
from yak.rest_social_network.models import Tag, Comment, Follow, Flag, Share, Like
from yak.rest_user.serializers import UserSerializer


User = get_user_model()


class LikedMixin(object):
    def get_liked_id(self, obj):
        request = self.context['request']
        if request.user.is_authenticated:
            try:
                content_type = self.get_content_type(obj)
                return Like.objects.get(content_type=content_type, user=request.user, object_id=obj.pk).pk

# Path: yak/rest_social_network/models.py
# class Tag(CoreModel):
#     name = models.CharField(max_length=75, unique=True)
# 
#     class Meta:
#         ordering = ['-created']
# 
#     def identifier(self):
#         return "#{}".format(self.name)
# 
#     def type(self):
#         return "tag"
# 
#     def __unicode__(self):
#         return "{}".format(self.name)
# 
# class Comment(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField(db_index=True)
#     content_object = GenericForeignKey()
# 
#     TAG_FIELD = 'description'
#     related_tags = models.ManyToManyField(Tag, blank=True)
# 
#     description = models.TextField()
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="comments", on_delete=models.CASCADE)
# 
#     class Meta:
#         ordering = ['created']
# 
# class Follow(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField(db_index=True)
#     content_object = GenericForeignKey()
# 
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="following", on_delete=models.CASCADE)
# 
#     @property
#     def object_type(self):
#         return self.content_type.name
# 
#     @property
#     def name(self):
#         # object must be registered with FollowableModel
#         return self.content_object.identifier()
# 
#     class Meta:
#         unique_together = (("user", "content_type", "object_id"),)
#         ordering = ['created']
# 
# class Flag(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField()
#     content_object = GenericForeignKey()
# 
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="flags", on_delete=models.CASCADE)
# 
#     class Meta:
#         unique_together = (("user", "content_type", "object_id"),)
# 
# class Share(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField()
#     content_object = GenericForeignKey()
#     shared_with = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='shared_with')
# 
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="shares", on_delete=models.CASCADE)
# 
# class Like(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField(db_index=True)
#     content_object = GenericForeignKey()
# 
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="likes", on_delete=models.CASCADE)
# 
#     class Meta:
#         unique_together = (("user", "content_type", "object_id"),)
# 
# 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/rest_social_network/serializers.py
from django.contrib.auth import get_user_model
from rest_framework import serializers
from yak.rest_social_network.models import Tag, Comment, Follow, Flag, Share, Like
from yak.rest_user.serializers import UserSerializer



User = get_user_model()


class LikedMixin(object):
    def get_liked_id(self, obj):
        request = self.context['request']
        if request.user.is_authenticated:
            try:
                content_type = self.get_content_type(obj)
                return Like.objects.get(content_type=content_type, user=request.user, object_id=obj.pk).pk

            except Like.DoesNotExist: