コード例 #1
0
ファイル: db_forums_funcs.py プロジェクト: Janyell/DBForum
def forum_details(short_name, related):
    forum = forum_get(short_name)
    if not len(forum):
        raise ("forum: forum with short_name=" + short_name + " not found")
    forum_response = forum_describe(forum[0])
    if "user" in related:
        forum_response["user"] = db_users_func.user_details(forum_response["user"])
    return forum_response
コード例 #2
0
ファイル: db_posts_funcs.py プロジェクト: Janyell/DBForum
def post_details(post_id, related):
    post_response = post_select(post_id)
    if post_response is None:
        raise Exception("post: post with id = " + post_id + " not found")
    if "user" in related:
        post_response["user"] = db_users_func.user_details(post_response["user"])
    if "thread" in related:
        post_response["thread"] = db_threads_funcs.thread_details(thread_id=post_response["thread"], related=[])
    if "forum" in related:
        post_response["forum"] = db_forums_funcs.forum_details(short_name=post_response["forum"], related=[])
    return post_response
コード例 #3
0
ファイル: db_followers_funcs.py プロジェクト: Janyell/DBForum
def user_follow(follower_email, followee_email):
    if follower_email == followee_email:
        raise Exception("followers: follower_email=followee_email=" + follower_email)
    db_funcs.db_exist(entity="Users", entity_attr="email", attr_value=follower_email)
    db_funcs.db_exist(entity="Users", entity_attr="email", attr_value=followee_email)
    follows = follower_select(follower_email, followee_email)
    if not len(follows):
        db_funcs.db_insert_or_delete_or_update(
            'INSERT INTO Followers (follower, followee)'
            ' VALUES (%s, %s)',
            (follower_email, followee_email, )
        )
    return db_users_func.user_details(follower_email)
コード例 #4
0
ファイル: views.py プロジェクト: Janyell/DBForum
def details(request):
    if request.method == "GET":
        request_data = return_GET_params(request)
        required_data = ["user"]
        try:
            params_are_right(request=request_data,
                             required=required_data)
            user_details = db_users_func.user_details(email=request_data["user"])
        except Exception as e:
            return return_error(e.message)
        return return_response(user_details)
    else:
        return HttpResponse(status=400)
コード例 #5
0
ファイル: db_threads_funcs.py プロジェクト: Janyell/DBForum
def thread_details(thread_id, related):
    thread = db_funcs.db_select(
        'SELECT date, forum, id, isClosed, isDeleted, message, slug, title, user, dislikes, likes, points, posts'
        ' FROM Threads'
        ' WHERE id = %s',
        (thread_id, )
    )
    if not len(thread):
        raise Exception('thread: thread with id=' + str(thread_id) + " not found")
    thread_response = thread_describe(thread[0])
    if "user" in related:
        thread_response["user"] = db_users_func.user_details(thread_response["user"])
    if "forum" in related:
        thread_response["forum"] = db_forums_funcs.forum_details(short_name=thread_response["forum"], related=[])
    return thread_response
コード例 #6
0
ファイル: db_followers_funcs.py プロジェクト: Janyell/DBForum
def user_unfollow(follower_email, followee_email):
    if follower_email == followee_email:
        raise Exception("followers: follower_email=followee_email=" + follower_email)
    db_funcs.db_exist(entity="Users", entity_attr="email", attr_value=follower_email)
    db_funcs.db_exist(entity="Users", entity_attr="email", attr_value=followee_email)
    follows = follower_select(follower_email, followee_email)
    if len(follows):
        db_funcs.db_insert_or_delete_or_update(
            'DELETE'
            ' FROM Followers'
            ' WHERE id= %s',
            (follows[0][0], )
        )
    else:
        raise Exception("followers: following not found")
    return db_users_func.user_details(follower_email)
コード例 #7
0
ファイル: db_forums_funcs.py プロジェクト: Janyell/DBForum
def forum_list_users(short_name, optional):
    db_funcs.db_exist(entity="Forums", entity_attr="short_name", attr_value=short_name)
    select = "SELECT DISTINCT email" \
             " FROM Users u, Posts p, Forums f" \
             " WHERE p.user = u.email" \
             " AND f.short_name = p.forum" \
             " AND p.forum = %s"
    if "since_id" in optional:
        select += " AND u.id >= " + str(optional["since_id"])
    if "order" in optional:
        select += " ORDER BY u.id " + optional["order"]
    else:
        select += " ORDER BY u.id DESC"
    if "limit" in optional:
        select += " LIMIT " + str(optional["limit"])

    result = db_funcs.db_select(select, (short_name, ))
    list_u = []
    for record in result:
        list_u.append(db_users_func.user_details(record[0]))
    return list_u
コード例 #8
0
ファイル: db_followers_funcs.py プロジェクト: Janyell/DBForum
def user_list_followers_or_following(type_email, type, params):
    db_funcs.db_exist(entity="Users", entity_attr="email", attr_value=type_email)
    if type == "follower":
        where_condition = "followee"
    else:
    # if type == "followee":
        where_condition = "follower"
    select = "SELECT " + type + \
             " FROM Followers f, Users u" \
             " WHERE u.email = f." + type +\
             " AND " + where_condition + " = %s "
    if "since_id" in params:
        select += " AND u.id >= " + str(params["since_id"])
    if "order" in params:
        select += " ORDER BY u.name " + params["order"]
    else:
        select += " ORDER BY u.name DESC"
    if "limit" in params:
        select += " LIMIT " + str(params["limit"])
    followers_ees = db_funcs.db_select(query=select, query_params=(type_email, ))
    list_f = []
    for follower_ee in followers_ees:
        list_f.append(db_users_func.user_details(email=follower_ee[0]))
    return list_f