コード例 #1
0
def dec_posts_count(connect,post):
    thread = DB_connect.select_query(connect,"SELECT thread FROM Post WHERE id = %s", (post, ))
    try:
        DB_connect.update_query(connect,"UPDATE Thread SET posts = posts - 1 WHERE id = %s", (thread[0][0], ))
    except Exception as e:
        print(e.message)
    return
コード例 #2
0
def subscribe_user(connect, thread, user):
    isDeleted = 0;

    DB_connect.update_query(connect, "INSERT INTO Subscription (user, thread_id, isDeleted) VALUES (%s, %s, %s)", (user, thread, isDeleted))
    return {
        "thread": thread,
        "user":   user
    }
コード例 #3
0
def vote_for_thread(connect, thread, vote):    
    if (vote == 1):        
        DB_connect.update_query(connect,'UPDATE Thread SET likes = likes + 1  WHERE id = %s', (thread, ))
    else: 
        if (vote == -1):            
            DB_connect.update_query(connect,'UPDATE Thread SET dislikes = dislikes + 1  WHERE id = %s',(thread, ))
        else:
            raise Exception("VallueError")
    return show_thread(connect, thread, [])
コード例 #4
0
def vote_for_post(connect, post, vote):
    if vote == 1:
        DB_connect.update_query(connect, "UPDATE Post SET likes = likes + 1  WHERE id = %s", (post,))
    else:
        if vote == -1:
            DB_connect.update_query(connect, "UPDATE Post SET dislikes = dislikes + 1  WHERE id = %s", (post,))
        else:
            raise Exception("VallueError")
    return show_post(connect, post, [])
コード例 #5
0
def save_forum(connect, name, short_name, user):
    print('save_forum:')
    #str = DB_connect.select_query(connect, 'SELECT id FROM Forum WHERE short_name = %s', (short_name, ))
    #if len(str) > 0:
    #    raise Exception("Exist")
    DB_connect.update_query(connect, "INSERT INTO Forum (name, short_name, user) VALUES (%s, %s, %s)", (name, short_name, user, ))
    forum = DB_connect.select_query(connect, 'SELECT id, name, short_name, user FROM Forum WHERE short_name = %s', (short_name, ))

    return forum_description(forum)
コード例 #6
0
def remove_restore(connect,thread, isDeleted):
    if isDeleted == 1:
        posts = 0
    else:
        posts = DB_connect.select_query(connect,"SELECT COUNT(id) FROM Post WHERE thread = %s", (thread, ))[0][0]
    DB_connect.update_query(connect,"UPDATE Thread SET isDeleted = %s, posts = %s WHERE id = %s", (isDeleted,posts, thread ))
    DB_connect.update_query(connect,"UPDATE Post SET isDeleted = %s WHERE thread = %s", (isDeleted,thread, ))
    return {
        "thread": thread    
    }
コード例 #7
0
def unsubscribe_user(connect, thread, user):
    isDeleted = 1;
    try:   
        DB_connect.update_query(connect, "UPDATE Subscription SET isDeleted = %s WHERE user = %s AND thread_id = %s ",(isDeleted, user, thread,))
    except Exception as e:
        raise Exception("user " + user + " does not subscribe thread #" + str(thread))
    return {
        "thread": thread,
        "user":   user
    }
コード例 #8
0
def unfollow_user(connect, follower, followee):    
    str = DB_connect.update_query(connect, 
        'DELETE FROM Follow  WHERE user =  %s AND follow = %s', (follower, followee, ) )
    if str == "Exist":
        raise Exception("Such row in db does not exist");
    user = show_user(connect, follower)
    return user
コード例 #9
0
def follow_user(connect, follower, followee):    
    user1 = DB_connect.select_query(connect, 'SELECT email FROM User WHERE email = %s', (follower, ))
    user2 = DB_connect.select_query(connect, 'SELECT email FROM User WHERE email = %s', (follower, ))    
    if user1 and user2:                
        str = DB_connect.update_query(connect, 
                'INSERT INTO Follow (user, follow) VALUES (%s, %s)', (follower, followee, ) )
    else:
        raise Exception("Error. Such users don't exist");
    user = show_user(connect, follower)
    return user
コード例 #10
0
def save_user(connect, username, about, name, email, optional):
    isAnonim = 0
    if "isAnonymous" in optional:
        isAnonim = optional["isAnonymous"]
        if isAnonim:
            name = username = about = ''
    str = DB_connect.update_query(connect,
                'INSERT INTO User (email, about, name, username, isAnonymous) VALUES (%s, %s, %s, %s, %s)', 
                (email, about, name, username, isAnonim, ))
    user = DB_connect.select_query(connect, 'Select  email, about, id, isAnonymous, name, username FROM User WHERE email = %s', (email, ) )
    return user_description(user)
コード例 #11
0
def save_thread(connect, forum, title, isClosed, user, date, message, slug, optional):
    isDeleted = 0;
    if "isDeleted" in optional:
        isDeleted= optional["isDeleted"]
    str = DB_connect.update_query(connect,
                'INSERT INTO Thread (forum, title, isClosed, user, date, message, slug, isDeleted) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)', 
                (forum, title, isClosed, user, date, message, slug, isDeleted, ))
    max_id = DB_connect.select_query(connect, 'SELECT max(id) FROM Thread', ())    
    thread = DB_connect.select_query(connect, 
                'SELECT  date, forum, id,  isClosed,  isDeleted, message, slug,  title,  user FROM Thread  WHERE id = %s', (max_id[0][0], ) )    
    return thread_description(thread)
コード例 #12
0
def update_post(connect, post, message):
    DB_connect.update_query(connect, "UPDATE Post SET message = %s WHERE id = %s", (message, post))
    return show_post(connect, post, [])
コード例 #13
0
def restore_post(connect, post):
    is_deleted = 0
    str = DB_connect.update_query(connect, "UPDATE Post SET  isDeleted = %s WHERE id =  %s", (is_deleted, post))
    threads.inc_posts_count(connect, post)
    return {"post": post}
コード例 #14
0
def update_user(connect,email, about, name):
    DB_connect.update_query(connect,'UPDATE User SET email = %s, about = %s, name = %s WHERE email = %s',
                           (email, about, name, email, ))
    return show_user(connect,email)
コード例 #15
0
def inc_posts_count(connect,post):
    thread = DB_connect.select_query(connect,"SELECT thread FROM Post WHERE id = %s", (post, ))
    DB_connect.update_query(connect,"UPDATE Thread SET posts = posts + 1 WHERE id = %s", (thread[0][0], ))
    return
コード例 #16
0
def update_thread(connect, message, slug, thread):
    DB_connect.update_query(connect,'UPDATE Thread SET message = %s, slug = %s WHERE id = %s',
                           (message, slug, thread, ))
    return show_thread(connect,thread, [])
コード例 #17
0
def open_close_thread(connect, thread, isClosed):
    DB_connect.update_query(connect,'UPDATE Thread SET isClosed = %s WHERE id = %s', (isClosed, thread,))
    return {
        "thread": thread 
    }