Example #1
0
def listThreads(request):
    forum = request.GET.get('forum')
    limit = request.GET.get('limit')
    order = request.GET.get('order')
    since = request.GET.get('since')
    related = request.GET.getlist('related')
    relations = list()
    if type(related) is list:
        relations.extend(related)
    threadRelated = False
    forumRelated = False
    userRelated = False
    for related_value in relations:
        if related_value == "thread":
            threadRelated = True
        elif related_value == "forum":
            forumRelated = True
        elif related_value == "user":
            userRelated = True
    thread_list = get_thread_list(forum=forum,
                                  order=order,
                                  limit=limit,
                                  since=since)
    for thread_dict in thread_list:
        if userRelated:
            thread_dict['user'] = get_user_dict(thread_dict['user'])
        if forumRelated:
            thread_dict['forum'] = get_forum_dict(thread_dict['forum'])
        if threadRelated:
            thread_dict['thread'] = get_thread_dict(thread_dict['thread'])
    return JsonResponse({"code": 0, "response": thread_list})
Example #2
0
def details(request):
	email = request.GET.get('user')
	if not email:
		return JsonResponse({"code": 2, "response": "No 'user' key"})
	user_dict = get_user_dict(email)
	user_dict['followers'] = get_followers_list(email)
	user_dict['following'] = get_following_list(email)
	user_dict['subscriptions'] = get_subscribed_threads_list(email)
	return JsonResponse({"code": 0, "response": user_dict, "email": email})
Example #3
0
def updateProfile(request):
	user = json.loads(request.body.decode("utf-8"))
	email = user.get('user')
	name = user.get('name')
	about = user.get('about')
	args = {'about': about, 'name': name, 'email': email}
	execute("""UPDATE User SET about = %(about)s, name = %(name)s WHERE email = %(email)s;""", args, True)
	user_dict = get_user_dict(email)
	return JsonResponse({"code": 0, "response": user_dict})
Example #4
0
def details(request):
    short_name = request.GET.get('forum')
    if not short_name:
        return JsonResponse({"code": 2, "response": "No 'forum' key"})
    forum_dict = get_forum_dict(short_name)
    if not forum_dict:
        return JsonResponse({"code": 1, "response": "Empty set"})
    email = forum_dict.get('user')
    user = get_user_dict(email)
    forum_dict.update({'user': user})
    return JsonResponse({"code": 0, "response": forum_dict})
Example #5
0
def follow(request):
	follow = json.loads(request.body.decode("utf-8"))
	follower = follow.get('follower')
	followee = follow.get('followee')
	execute("""INSERT INTO Follower (follower, followee) VALUES \
		(%(follower)s, %(followee)s);""", {'follower': follower, 'followee': followee})
	user_dict = get_user_dict(follower)
	user_dict['followers'] = get_followers_list(follower)
	user_dict['following'] = get_following_list(follower)
	user_dict['subscriptions'] = get_subscribed_threads_list(follower)
	return JsonResponse({"code": 0, "response": user_dict})
Example #6
0
def unfollow(request):
	follow = json.loads(request.body.decode("utf-8"))
	follower = follow.get('follower')
	followee = follow.get('followee')
	args = {'follower': follower, 'following': followee}
	execute("""DELETE FROM Follower WHERE follower = %(follower)s AND followee = %(following)s;""", args, True)
	user_dict = get_user_dict(follower)
	user_dict['followers'] = get_followers_list(follower)
	user_dict['following'] = get_following_list(follower)
	user_dict['subscriptions'] = get_subscribed_threads_list(follower)
	return JsonResponse({"code": 0, "response": user_dict})
Example #7
0
def listFollowing(request):
	email = request.GET.get('user')
	if not email:
		return JsonResponse({"code": 2, "response": "No 'user' key"})
	followees = get_following_list(email)
	followings_list = list()
	for followee in followees:
		curr_followee = get_user_dict(followee)
		curr_followee['followers'] = get_followers_list(followee)
		curr_followee['following'] = get_following_list(followee)
		curr_followee['subscriptions'] = get_subscribed_threads_list(followee)
		followings_list.append(curr_followee)
	return JsonResponse({"code": 0, "response": followings_list})
Example #8
0
def details(request):
    post = request.GET.get('post')
    if not post:
        return JsonResponse({"code": 2, "response": "No 'post' key"})
    post_dict = get_post_by_id(post)
    if type(post_dict) == type([]):
        return JsonResponse({"code": 1, "response": "Empty set"})
    user = post_dict.get('user')
    forum = post_dict.get('forum')
    thread = post_dict.get('thread')
    post_dict['user'] = get_user_dict(user)
    post_dict['forum'] = get_forum_dict(forum)
    post_dict['thread'] = get_thread_by_id(thread)
    return JsonResponse({"code": 0, "response": post_dict})
Example #9
0
def details(request):
    thread = int(request.GET.get('thread'))
    related = request.GET.getlist('related')
    relations = []
    relations.extend(related)
    threadRelated = False
    forumRelated = False
    userRelated = False
    for related_value in relations:
        if related_value == "forum":
            forumRelated = True
        elif related_value == "user":
            userRelated = True
        else:
            return JsonResponse({"code": 3, "response": "Wrong related value"})
    if not thread:
        return JsonResponse({"code": 2, "response": "No 'thread' key"})
    thread_dict = get_thread_by_id(thread)
    user = thread_dict.get('user')
    forum = thread_dict.get('forum')
    thread_dict['user'] = get_user_dict(user)
    thread_dict['forum'] = get_forum_dict(forum)
    return JsonResponse({"code": 0, "response": thread_dict})