示例#1
0
def get_my_home():
	requested_user = g.user
	current_location = g.user_location

	user_dict = requested_user.to_json_dict(private=True)

	# Build additional user info
	notifications = notification_service.get_notifications_by_user_id(requested_user.user_id)

	notification_json_dict = []
	for notification in notifications:
		notification_json_dict.append(notification.to_json_dict())

	pending_friend_requests = user_service.get_friend_requests_pending(requested_user.user_id)

	pending_requests_json_dict = []
	for pending_request in pending_friend_requests:
		pending_requests_json_dict.append(pending_request.to_json_dict())

	followers = user_service.get_followers(requested_user.user_id, True)

	user_dict["relations"] = {
		"friend_requests_pending" : pending_requests_json_dict,
		"followers_count" : len(followers)
	}
	user_dict["notifications"] = notification_json_dict
	user_dict["current_location"] = current_location.to_json_dict()

	return user_dict
示例#2
0
def get_user_profile(queried_user_identifier):
	requested_user = g.queried_user
	requested_user_id = g.queried_user_id
	current_user = g.user
	current_location = g.user_location

	friendship_status = user_service.get_friendship_status(current_user.user_id, requested_user_id)
	are_friends = friendship_status == Friendship.FRIENDS

	posts = post_service.get_posts_by_user(current_user.user_id, requested_user, are_friends)
	friend_objs = user_service.get_friends(requested_user_id)
	followers = user_service.get_followers(requested_user_id, True)

	friend_json_dicts = []
	for friend in friend_objs:
		friend_json_dicts.append(friend.to_json_dict())

	post_json_dicts = []
	for post in posts:
		post_json_dict = post.to_json_dict()
		post_json_dicts.append(post_json_dict)

	# Build the result
	result_json_dict = requested_user.to_json_dict()
	result_json_dict['friends'] = friend_json_dicts
	result_json_dict['posts'] = post_json_dicts
	result_json_dict['follower_count'] = len(followers)
	result_json_dict['current_user_info'] = {
		"location" : current_location.to_json_dict(),
		"following" : current_user.user_id in followers,
		"friendship_status" : friendship_status
	}
	if current_user.user_id == requested_user_id:
		result_json_dict["self"] = current_user.user_id == requested_user_id

	return result_json_dict
示例#3
0
def get_followers(queried_user_identifier):
	queried_user_id = g.queried_user_id

	return user_service.get_followers(queried_user_id)