# Path: replayswithfriends/profiles/models.py
# class Profile(models.Model):
# 
#     SHARE = Choices(
#         (0, 'PUBLIC', _("Public")),
#         (1, 'FRIENDS', _("Public")),
#         (2, 'FOLLOWERS', _("Followers")),
#         (3, 'PRIVATE', _("Public")),
#     )
# 
#     user = models.OneToOneField(User, null=True)
#     default_match_share = models.PositiveSmallIntegerField(choices=SHARE, default=SHARE.FRIENDS)
#     profile_share = models.PositiveSmallIntegerField(choices=SHARE, default=SHARE.FRIENDS)
#     can_friend_req = models.BooleanField(default=True)
#     can_follow_req = models.BooleanField(default=True)
#     follow_code = models.CharField(blank=True, default='', max_length=16)
#     friend_code = models.CharField(blank=True, default='', max_length=16)


from django.contrib.auth.models import User
from tastypie.authentication import BasicAuthentication
from tastypie.authorization import DjangoAuthorization
from tastypie.resources import ModelResource
from friendship.models import Friend, Follow
from .models import Profile


class UserResource(ModelResource):
    """
    An iPhone (right now, tests the user-agent) should be able to create a 'User'

    send the password, email, and username to us.
    """
    def obj_get_list(self, request, *args, **kwargs):
        if request.user.is_authenticated():
            return User.objects.filter(
                id__in=[set(
                    Follow.objects.followers(request.user).values_list('id', flat=True),
                    Friend.objects.friends(request.user).values_list('id', flat=True),

# Path: replayswithfriends/profiles/models.py
# class Profile(models.Model):
# 
#     SHARE = Choices(
#         (0, 'PUBLIC', _("Public")),
#         (1, 'FRIENDS', _("Public")),
#         (2, 'FOLLOWERS', _("Followers")),
#         (3, 'PRIVATE', _("Public")),
#     )
# 
#     user = models.OneToOneField(User, null=True)
#     default_match_share = models.PositiveSmallIntegerField(choices=SHARE, default=SHARE.FRIENDS)
#     profile_share = models.PositiveSmallIntegerField(choices=SHARE, default=SHARE.FRIENDS)
#     can_friend_req = models.BooleanField(default=True)
#     can_follow_req = models.BooleanField(default=True)
#     follow_code = models.CharField(blank=True, default='', max_length=16)
#     friend_code = models.CharField(blank=True, default='', max_length=16)


# Path: replayswithfriends/profiles/api.py
from django.contrib.auth.models import User
from tastypie.authentication import BasicAuthentication
from tastypie.authorization import DjangoAuthorization
from tastypie.resources import ModelResource
from friendship.models import Friend, Follow
from .models import Profile



class UserResource(ModelResource):
    """
    An iPhone (right now, tests the user-agent) should be able to create a 'User'

    send the password, email, and username to us.
    """
    def obj_get_list(self, request, *args, **kwargs):
        if request.user.is_authenticated():
            return User.objects.filter(
                id__in=[set(
                    Follow.objects.followers(request.user).values_list('id', flat=True),
                    Friend.objects.friends(request.user).values_list('id', flat=True),

                    profile__profile_share=Profile.SHARE.PUBLIC