def retrieve(self, request, pk): try: author = Author.objects.get(pk=pk) except: print("DID WE GET HERE?", pk) return Response("Invalid author ID specified", status=404) url = get_author_url(pk) data = { "id": url, "host": get_host_url(), "displayName": author.displayName or author.user.username, "url": url, "friends": get_author_summaries(get_friends(url)) } if (author.github): data["github"] = author.github if (author.user.first_name): data["firstName"] = author.user.first_name if (author.user.last_name): data["lastName"] = author.user.last_name if (author.user.email): data["email"] = author.user.email if (author.bio): data["bio"] = author.bio return Response(data)
def list_followed_users(self, request, pk): author = get_object_or_404(Author, pk=pk) author_url = author.get_url() follows = Follow.objects.filter(follower=author_url) followed_urls = [] for follow in follows: followed_urls.append(follow.followed) info = get_author_summaries(followed_urls) return Response({ "query": "listFollowed", "followed": info }, status=200)
def get_friend_requests(self, request, pk): try: author = Author.objects.get(pk=pk) except: return Response("Invalid author ID specified", status=404) requests = FriendRequest.objects.filter(friend=get_author_url(pk)) print("requests found", len(requests)) urls = [] for pending_request in requests: urls.append(pending_request.requester) formatted_requests = get_author_summaries(urls) return Response(formatted_requests, status=200)