コード例 #1
0
def friend_request_list(request):
    """Displays a list of users that the author sent a friend requst to."""
    context = RequestContext(request)

    if request.method == 'GET':
        if request.user.is_authenticated():
            request_list = []
            sent_list = []
            friend_list = []
            rlShow = True
            slShow = True
            flShow = True
            rUser = Author.objects.get(user=request.user)
            #friendJ = get_is_friend('2356e331-ef78-402f-b880-240269f7a93f', '52e7ace8-3723-4a7d-8abc-d4228ff5dced')
            for author in FriendRequest.received_requests(rUser):
                # check if it is a remote author
                info = {
                    "displayname": author.get_username(),
                    "username": author.user.username,
                    "userID": author.get_uuid(),
                    "host": author.get_host()
                }
                request_list.append(info)
            for author in FriendRequest.sent_requests(rUser):
                if '__' in author.user.username:
                    isFriend = get_is_friend(rUser, author)
                info = {
                    "displayname": author.get_username(),
                    "username": author.user.username,
                    "userID": author.get_uuid(),
                    "host": author.get_host()
                }
                sent_list.append(info)
            for author in FriendRequest.get_friends(rUser):
                info = {
                    "displayname": author.user.username,
                    "username": author.user.username,
                    "userID": author.get_uuid(),
                    "host": author.get_host()
                }
                friend_list.append(info)
            if not request_list:
                rlShow = False
            if not sent_list:
                slShow = False
            if not friend_list:
                flShow = False
            context = RequestContext(
                request, {
                    'requestList': request_list,
                    'sentList': sent_list,
                    'friendList': friend_list,
                    'rlShow': rlShow,
                    'slShow': slShow,
                    'flShow': flShow
                })
        else:
            _render_error('login.html', 'Please log in.', context)

    return render_to_response('friendRequests.html', context)
コード例 #2
0
def friend_request_list(request):
    """Displays a list of users that the author sent a friend requst to."""
    context = RequestContext(request)

    if request.method == 'GET':
        if request.user.is_authenticated():
            request_list = []
            sent_list = []
            friend_list = []
            rlShow = True
            slShow = True
            flShow = True
            rUser = Author.objects.get(user = request.user)
            #friendJ = get_is_friend('2356e331-ef78-402f-b880-240269f7a93f', '52e7ace8-3723-4a7d-8abc-d4228ff5dced')
            for author in FriendRequest.received_requests(rUser):
                # check if it is a remote author
                info = {"displayname": author.get_username(),
                        "username": author.user.username,
                        "userID": author.get_uuid(),
                        "host": author.get_host()}
                request_list.append(info)
            for author in FriendRequest.sent_requests(rUser):
                if '__' in author.user.username:
                    isFriend = get_is_friend(rUser, author)
                info = {"displayname": author.get_username(),
                        "username": author.user.username,
                        "userID": author.get_uuid(),
                        "host": author.get_host()}
                sent_list.append(info)
            for author in FriendRequest.get_friends(rUser):
                info = {"displayname": author.user.username,
                        "username": author.user.username,
                        "userID": author.get_uuid(),
                        "host": author.get_host()}
                friend_list.append(info)
            if not request_list:
                rlShow = False
            if not sent_list:
                slShow = False
            if not friend_list:
                flShow = False
            context = RequestContext(request, {'requestList': request_list,
                                               'sentList': sent_list,
                                               'friendList':friend_list,
                                               'rlShow': rlShow,
                                               'slShow':slShow,
                                               'flShow':flShow})
        else:
            _render_error('login.html', 'Please log in.', context)

    return render_to_response('friendRequests.html', context)
コード例 #3
0
    def isViewable(self, viewer, author):

        visibility = self.visibility

        if visibility == Post.PRIVATE:
            return viewer == author
        elif visibility == Post.ANOTHER_AUTHOR:
            post_entry = VisibleToAuthor.objects.filter(
                visibleAuthor=viewer, post=self)
            return post_entry.exists() or viewer == author
        elif visibility == Post.FRIENDS:
            return FriendRequest.is_friend(viewer, author) or viewer == author
        elif visibility == Post.FOAF:
            friendOfFriends = []
            friends = FriendRequest.get_friends(author)
            for friend in friends:
                friendOfFriends += FriendRequest.get_friends(friend)
            return viewer in friendOfFriends or viewer == author or FriendRequest.is_friend(viewer, author)
        elif visibility == Post.SERVERONLY:
            return viewer.host == author.host or viewer == author
        else:
            # Assuming that the visibility type is public
            return True
コード例 #4
0
    def isViewable(self, viewer, author):

        visibility = self.visibility

        if visibility == Post.PRIVATE:
            return viewer == author
        elif visibility == Post.ANOTHER_AUTHOR:
            post_entry = VisibleToAuthor.objects.filter(visibleAuthor=viewer,
                                                        post=self)
            return post_entry.exists() or viewer == author
        elif visibility == Post.FRIENDS:
            return FriendRequest.is_friend(viewer, author) or viewer == author
        elif visibility == Post.FOAF:
            friendOfFriends = []
            friends = FriendRequest.get_friends(author)
            for friend in friends:
                friendOfFriends += FriendRequest.get_friends(friend)
            return viewer in friendOfFriends or viewer == author or FriendRequest.is_friend(
                viewer, author)
        elif visibility == Post.SERVERONLY:
            return viewer.host == author.host or viewer == author
        else:
            # Assuming that the visibility type is public
            return True
コード例 #5
0
def friend_list(request, author):
    """Gets the user's friends."""
    context = RequestContext(request)
    print("here")
    a = []
    # get_friends_in_list(author, a)
    print("here2")
    if request.method == 'GET':
        if request.user.is_authenticated():
            friend_usernames = []
            author = Author.objects.get(user=request.user)
            friend_list = FriendRequest.get_friends(author)

            for friend in friend_list:
                friend_usernames.append(friend.user)

            context = RequestContext(request, {'friendList': friend_usernames})
        else:
            _render_error('login.html', 'Please log in.', context)
    return render_to_response('friends.html', context)
コード例 #6
0
def friend_list(request, author):
    """Gets the user's friends."""
    context = RequestContext(request)
    print("here")
    a = []
   # get_friends_in_list(author, a)
    print("here2")
    if request.method == 'GET':
        if request.user.is_authenticated():
            friend_usernames = []
            author = Author.objects.get(user=request.user)
            friend_list = FriendRequest.get_friends(author)

            for friend in friend_list:
                friend_usernames.append(friend.user)

            context = RequestContext(request, {'friendList': friend_usernames})
        else:
            _render_error('login.html', 'Please log in.', context)
    return render_to_response('friends.html', context)
コード例 #7
0
def friends(request, user_id):
    """Return whether anyone in the list is a friend

    This expects a POST request with the following content:

    {
        "query": "friends",
        "author": "9de17f29c12e8f97bcbbd34cc908f1baba40658e",
        "authors": [
            "7deee0684811f22b384ccb5991b2ca7e78abacde",
            "31cc28a8fbc05787d0470cdbd62ea0474764b0ae",
            "1af17e947f387a2d8c09a807271bd094e8eff077",
            "77cb4f546b280ea905a6fdd99977cd090613994a",
            "11c3783f15f7ade03430303573098f0d4d20797b",
            "bd9ef9619c7241112d2a2b79505f736fc8d7f43e",
            "0169a8ebf3cb3bd7f092603564873e12cce9d4c5",
            "2130905fd0de94c3379e04839cd9f6889ba2b52c",
            "b32c9e0b5fcf85f46b9ce2ba89b2068b57d4641b",
            "fe45075b93d06c833bb25d5a6dfe669cfde3f99d",
            "e28e59a9612c369717f66f53f3e014b341857601",
            "b36e52d6aaee9285220f94fc321407a44e4dc622",
            "584a9739ea459ce4aae5a88827d970196fb27769",
            "96b3b5a70cd9591c73760bd8669aa5bd7cc689c5",
            "6465678d0a409b96829fd64d0894132966e97eee",
            "695c780ea2815bc94c54782f5046dfa4e325f875",
            "8743f7511a1a569e4e9dacbb25e27395629ba5c0",
            "539b65f2d76d0327dc45bf6354cda535d6f8ed02",
            "c55670261253c5ce25e22b47a34629dd15e819d4"
        ]
    }

    This responds with the following JSON:
    {
        "query": "friends",
        "author": "9de17f29c12e8f97bcbbd34cc908f1baba40658e",
        "friends": [
            "7deee0684811f22b384ccb5991b2ca7e78abacde",
            "11c3783f15f7ade03430303573098f0d4d20797b",
        ]
    }
    """
    if request.method == 'POST':
        try:
            request_data = json.loads(request.body)

            uuid = request_data['author']
            author = Author.objects.filter(uuid=uuid)

            if len(author) > 0:
                # We're only expecting one author
                author = author[0]

                friends = FriendRequest.get_friends(author)
                uuids = [friend.uuid for friend in friends]
                friends = list(set(uuids) & set(request_data['authors']))

                response = {
                    'query': 'friends',
                    'author': author.uuid,
                    'friends': friends
                }

                return HttpResponse(json.dumps(response),
                                    content_type='application/json',
                                    status=200)
            else:
                return HttpResponse(status=404)
        except Exception as e:
            return HttpResponse(e.message,
                                content_type='text/plain',
                                status=500)
    else:
        return HttpResponse(status=405)
コード例 #8
0
def friends(request, user_id):
    """Return whether anyone in the list is a friend

    This expects a POST request with the following content:

    {
        "query": "friends",
        "author": "9de17f29c12e8f97bcbbd34cc908f1baba40658e",
        "authors": [
            "7deee0684811f22b384ccb5991b2ca7e78abacde",
            "31cc28a8fbc05787d0470cdbd62ea0474764b0ae",
            "1af17e947f387a2d8c09a807271bd094e8eff077",
            "77cb4f546b280ea905a6fdd99977cd090613994a",
            "11c3783f15f7ade03430303573098f0d4d20797b",
            "bd9ef9619c7241112d2a2b79505f736fc8d7f43e",
            "0169a8ebf3cb3bd7f092603564873e12cce9d4c5",
            "2130905fd0de94c3379e04839cd9f6889ba2b52c",
            "b32c9e0b5fcf85f46b9ce2ba89b2068b57d4641b",
            "fe45075b93d06c833bb25d5a6dfe669cfde3f99d",
            "e28e59a9612c369717f66f53f3e014b341857601",
            "b36e52d6aaee9285220f94fc321407a44e4dc622",
            "584a9739ea459ce4aae5a88827d970196fb27769",
            "96b3b5a70cd9591c73760bd8669aa5bd7cc689c5",
            "6465678d0a409b96829fd64d0894132966e97eee",
            "695c780ea2815bc94c54782f5046dfa4e325f875",
            "8743f7511a1a569e4e9dacbb25e27395629ba5c0",
            "539b65f2d76d0327dc45bf6354cda535d6f8ed02",
            "c55670261253c5ce25e22b47a34629dd15e819d4"
        ]
    }

    This responds with the following JSON:
    {
        "query": "friends",
        "author": "9de17f29c12e8f97bcbbd34cc908f1baba40658e",
        "friends": [
            "7deee0684811f22b384ccb5991b2ca7e78abacde",
            "11c3783f15f7ade03430303573098f0d4d20797b",
        ]
    }
    """
    if request.method == 'POST':
        try:
            request_data = json.loads(request.body)

            uuid = request_data['author']
            author = Author.objects.filter(uuid=uuid)

            if len(author) > 0:
                # We're only expecting one author
                author = author[0]

                friends = FriendRequest.get_friends(author)
                uuids = [friend.uuid for friend in friends]
                friends = list(set(uuids) & set(request_data['authors']))

                response = {
                    'query': 'friends',
                    'author': author.uuid,
                    'friends': friends
                }

                return HttpResponse(json.dumps(response),
                                    content_type='application/json',
                                    status=200)
            else:
                return HttpResponse(status=404)
        except Exception as e:
            return HttpResponse(e.message,
                                content_type='text/plain',
                                status=500)
    else:
        return HttpResponse(status=405)