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)
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)
def search(request): """Returns a list of authors. The returned list of authors contains their username, first_name, and last_name. """ context = RequestContext(request) if request.method == 'POST': search_value = request.POST['searchValue'] author_info = [] if search_value == '*' or search_value is None: users = User.objects.all() else: # query all values containing search results users = User.objects.filter( Q(username__contains=search_value) & ~Q(username=request.user)) results = 0 # setting each author search information for user in users: results += 1 try: friend = False sent = False received = False sent = False follow = False sentList = [] receivedList = [] rUser = Author.objects.get(user=request.user) author = Author.objects.get(user=user) friend = FriendRequest.is_friend(rUser, author) follow = FriendRequest.is_following(rUser, author) sentList = FriendRequest.sent_requests(rUser) if sentList: if author in sentList: sent = True receivedList = FriendRequest.received_requests(rUser) if receivedList: if author in receivedList: received = True user_info = { "displayname": author.get_username(), "userName": author.user.username, "userID": author.get_uuid(), "host": author.get_host(), "friend": friend, "sent": sent, "received": received, "follow": follow } author_info.append(user_info) except: pass print("context") context = RequestContext( request, { 'searchValue': search_value, 'authorInfo': author_info, 'results': results }) return render_to_response('searchResults.html', context)
def search(request): """Returns a list of authors. The returned list of authors contains their username, first_name, and last_name. """ context = RequestContext(request) if request.method == 'POST': search_value = request.POST['searchValue'] author_info = [] if search_value == '*' or search_value is None: users = User.objects.all() else: # query all values containing search results users = User.objects.filter(Q(username__contains=search_value) & ~Q(username=request.user)) results = 0 # setting each author search information for user in users: results += 1 try: friend = False sent = False received = False sent = False follow = False sentList = [] receivedList = [] rUser = Author.objects.get(user = request.user) author = Author.objects.get(user=user) friend = FriendRequest.is_friend(rUser, author) follow = FriendRequest.is_following(rUser, author) sentList = FriendRequest.sent_requests(rUser) if sentList: if author in sentList: sent = True receivedList = FriendRequest.received_requests(rUser) if receivedList: if author in receivedList: received = True user_info = {"displayname": author.get_username(), "userName": author.user.username, "userID": author.get_uuid(), "host": author.get_host(), "friend": friend, "sent": sent, "received": received, "follow": follow} author_info.append(user_info) except: pass print("context") context = RequestContext(request, {'searchValue': search_value, 'authorInfo': author_info, 'results': results}) return render_to_response('searchResults.html', context)