示例#1
0
def save_thread(connect, forum, title, isClosed, user, date, message, slug, optional):
    
    isDeleted = 0
    if "isDeleted" in optional:
        isDeleted = optional["isDeleted"]
    DBconnect.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, ))
    thread = DBconnect.select_query(connect,
            'select date, forum, id, isClosed, isDeleted, message, slug, title, user, dislikes, likes, points, posts '
            'FROM thread WHERE slug = %s', (slug, )
        )
    thread = thread[0]
    response = {
        'date': str(thread[0]),
        'forum': thread[1],
        'id': thread[2],
        'isClosed': bool(thread[3]),
        'isDeleted': bool(thread[4]),
        'message': thread[5],
        'slug': thread[6],
        'title': thread[7],
        'user': thread[8],
    }
    return response
示例#2
0
def dec_posts_count(connect,post):
    thread = DBconnect.select_query(connect,"SELECT thread FROM post WHERE id = %s", (post, ))
    try:
        DBconnect.update_query(connect,"UPDATE thread SET posts = posts - 1 WHERE id = %s", (thread[0][0], ))
    except Exception as e:
        print(e.message)
    return
示例#3
0
def save_forum(connect,name, short_name, user):
    DBconnect.update_query(connect,'INSERT INTO forum (name, short_name, user) VALUES (%s, %s, %s)',
                               (name, short_name, user, ))
    forum = DBconnect.select_query(connect,
            'select id, name, short_name, user FROM forum WHERE short_name = %s', (short_name, )
        )
    return forum_description(forum)
示例#4
0
def vote(vote_id, vote_type):
    # DBconnect.exist(entity="post", identifier="id", value=vote_id)
    if vote_type == -1:
        DBconnect.update_query("UPDATE post SET dislikes=dislikes+1, points=points-1 where id = %s", (vote_id, ))
    else:
        DBconnect.update_query("UPDATE post SET likes=likes+1, points=points+1  where id = %s", (vote_id, ))
    return details(details_id=vote_id, related=[])
示例#5
0
def open_close_thread(connect,id, isClosed):
    DBconnect.update_query(connect,"UPDATE thread SET isClosed = %s WHERE id = %s", (isClosed, id, ))

    response = {
        "thread": id
    }

    return response
示例#6
0
文件: threads.py 项目: niggor/DB_TP
def remove_restore(thread_id, status):
    DBconnect.exist(entity="thread", identifier="id", value=thread_id)
    DBconnect.update_query("UPDATE thread SET isDeleted = %s WHERE id = %s", (status, thread_id, ))
    DBconnect.update_query("UPDATE post SET isDeleted = %s WHERE thread = %s", (status, thread_id, ))
    response = {
        "thread": thread_id
    }
    return response
示例#7
0
def vote(connect,id, vote):
    try:
        if vote == -1:
            DBconnect.update_query(connect,"UPDATE thread SET dislikes=dislikes+1, points=points-1 where id = %s", (id, ))
        else:
            DBconnect.update_query(connect,"UPDATE thread SET likes=likes+1, points=points+1  where id = %s", (id, ))
    except Exception as e:
        print(e.message)
    return details(connect,id=id, related=[])
示例#8
0
文件: threads.py 项目: niggor/DB_TP
def open_close_thread(id, isClosed):
    DBconnect.exist(entity="thread", identifier="id", value=id)
    DBconnect.update_query("UPDATE thread SET isClosed = %s WHERE id = %s", (isClosed, id, ))

    response = {
        "thread": id
    }

    return response
示例#9
0
def remove_subscription(connect,email, thread_id):
    try:    
        DBconnect.update_query(connect,'DELETE FROM subscription WHERE user = %s AND thread = %s', (email, thread_id, ))
    except Exception as e:
        raise Exception("user " + email + " does not subscribe thread #" + str(thread_id))
    response = {
        "thread": subscription[0][0],
        "user": subscription[0][1]
    }
    return response
示例#10
0
def remove_restore(connect,thread_id, status):
    if status == 1:
        posts = 0
    else:
        posts = DBconnect.select_query(connect,"SELECT COUNT(id) FROM post WHERE thread = %s", str(thread_id))[0][0]
    DBconnect.update_query(connect,"UPDATE thread SET isDeleted = %s, posts = %s WHERE id = %s", (status,posts,thread_id))
    DBconnect.update_query(connect,"UPDATE post SET isDeleted = %s WHERE thread = %s", (status,thread_id))
    response = {
        "thread": thread_id
    }
    return response
示例#11
0
def save_subscription(connect,email, thread_id):
   
    DBconnect.update_query(connect,'INSERT INTO subscription (thread, user) VALUES (%s, %s)', (thread_id, email, ))
    subscription = DBconnect.select_query(connect,
        'select thread, user FROM subscription WHERE user = %s AND thread = %s', (email, thread_id, )
    )
    response = {
        "thread": subscription[0][0],
        "user": subscription[0][1]
    }
    return response
示例#12
0
def remove_follow(email1, email2):
    follows = DBconnect.select_query(
        'SELECT id FROM follower WHERE follower = %s AND followee = %s', (email1, email2, )
    )

    if len(follows) != 0:
        DBconnect.update_query('DELETE FROM follower WHERE follower = %s AND followee = %s', (email1, email2, ))
    else:
        raise Exception("No such following")

    return users.details(email1)
示例#13
0
def save_forum(name, short_name, user):
    DBconnect.exist(entity="user", identifier="email", value=user)
    forum = DBconnect.select_query(
        'select id, name, short_name, user FROM forum WHERE short_name = %s', (short_name, )
    )
    if len(forum) == 0:
        DBconnect.update_query('INSERT INTO forum (name, short_name, user) VALUES (%s, %s, %s)',
                               (name, short_name, user, ))
        forum = DBconnect.select_query(
            'select id, name, short_name, user FROM forum WHERE short_name = %s', (short_name, )
        )
    return forum_description(forum)
示例#14
0
文件: threads.py 项目: niggor/DB_TP
def vote(id, vote):
    print("entered")
    try:
        # DBconnect.exist(entity="thread", identifier="id", value=id)
        if vote == -1:
            DBconnect.update_query("UPDATE thread SET dislikes=dislikes+1, points=points-1 where id = %s", (id, ))
        else:
            DBconnect.update_query("UPDATE thread SET likes=likes+1, points=points+1  where id = %s", (id, ))
    except Exception as e:
        print(e.message)

    return details(id=id, related=[])
示例#15
0
def remove_restore(thread_id, status):
    DBconnect.exist(entity="thread", identifier="id", value=thread_id)
    if status == 1:
        posts = 0
    else:
        posts = DBconnect.select_query("SELECT COUNT(id) FROM post WHERE thread = %s", (thread_id, ))[0]

    DBconnect.update_query("UPDATE thread SET isDeleted = %s, posts = %s WHERE id = %s", (status, posts, thread_id, ))
    DBconnect.update_query("UPDATE post SET isDeleted = %s WHERE thread = %s", (status, thread_id, ))
    response = {
        "thread": thread_id
    }
    return response
示例#16
0
def remove_subscription(email, thread_id):
    DBconnect.exist(entity="thread", identifier="id", value=thread_id)
    DBconnect.exist(entity="user", identifier="email", value=email)
    subscription = DBconnect.select_query(
        'select thread, user FROM subscription WHERE user = %s AND thread = %s', (email, thread_id, )
    )
    if len(subscription) == 0:
        raise Exception("user " + email + " does not subscribe thread #" + str(thread_id))
    DBconnect.update_query('DELETE FROM subscription WHERE user = %s AND thread = %s', (email, thread_id, ))

    response = {
        "thread": subscription[0][0],
        "user": subscription[0][1]
    }
    return response
示例#17
0
def add_follow(email1, email2):
    DBconnect.exist(entity="user", identifier="email", value=email1)
    DBconnect.exist(entity="user", identifier="email", value=email2)

    if email1 == email2:
        raise Exception("User with email=" + email1 + " can't follow himself")

    follows = DBconnect.select_query(
        'SELECT id FROM follower WHERE follower = %s AND followee = %s', (email1, email2, )
    )

    if len(follows) == 0:
        DBconnect.update_query('INSERT INTO follower (follower, followee) VALUES (%s, %s)', (email1, email2, ))

    user = users.details(email1)
    return user
示例#18
0
def save_subscription(email, thread_id):
    DBconnect.exist(entity="thread", identifier="id", value=thread_id)
    DBconnect.exist(entity="user", identifier="email", value=email)
    subscription = DBconnect.select_query(
        'select thread, user FROM subscription WHERE user = %s AND thread = %s', (email, thread_id, )
    )
    if len(subscription) == 0:
        DBconnect.update_query('INSERT INTO subscription (thread, user) VALUES (%s, %s)', (thread_id, email, ))
        subscription = DBconnect.select_query(
            'select thread, user FROM subscription WHERE user = %s AND thread = %s', (email, thread_id, )
        )

    response = {
        "thread": subscription[0][0],
        "user": subscription[0][1]
    }
    return response
示例#19
0
def save_user(email, username, about, name, optional):
    isAnonymous = 0
    if "isAnonymous" in optional:
        isAnonymous = optional["isAnonymous"]
    try:
        user = DBconnect.select_query('SELECT email, about, isAnonymous, id, name, username FROM user WHERE email = %s', (email, ))
        if len(user) == 0:
            DBconnect.update_query(
                'INSERT INTO user (email, about, name, username, isAnonymous) VALUES (%s, %s, %s, %s, %s)',
                (email, about, name, username, isAnonymous, ))
        else:
            raise Exception("5")
        user = DBconnect.select_query('select email, about, isAnonymous, id, name, username FROM user WHERE email = %s',
                           (email, ))
    except Exception as e:
        raise Exception(e.message)

    return user_format(user)
示例#20
0
文件: threads.py 项目: niggor/DB_TP
def save_thread(forum, title, isClosed, user, date, message, slug, optional):
    DBconnect.exist(entity="user", identifier="email", value=user)
    DBconnect.exist(entity="forum", identifier="short_name", value=forum)

    isDeleted = 0
    if "isDeleted" in optional:
        isDeleted = optional["isDeleted"]
    thread = DBconnect.select_query(
        'select date, forum, id, isClosed, isDeleted, message, slug, title, user, dislikes, likes, points, posts '
        'FROM thread WHERE slug = %s', (slug, )
    )
    if len(thread) == 0:
        DBconnect.update_query('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, ))
        thread = DBconnect.select_query(
            'select date, forum, id, isClosed, isDeleted, message, slug, title, user, dislikes, likes, points, posts '
            'FROM thread WHERE slug = %s', (slug, )
        )
    thread = thread[0]
    response = {
        'date': str(thread[0]),
        'forum': thread[1],
        'id': thread[2],
        'isClosed': bool(thread[3]),
        'isDeleted': bool(thread[4]),
        'message': thread[5],
        'slug': thread[6],
        'title': thread[7],
        'user': thread[8],
        'dislikes': thread[9],
        'likes': thread[10],
        'points': thread[11],
        'posts': thread[12],
    }

    # Delete few extra elements
    del response["dislikes"]
    del response["likes"]
    del response["points"]
    del response["posts"]

    return response
示例#21
0
def save_user(connect,email, username, about, name, optional):
    isAnonymous = 0
    if "isAnonymous" in optional:
        isAnonymous = optional["isAnonymous"]
    
    str = DBconnect.update_query(connect,
                'INSERT INTO user (email, about, name, username, isAnonymous) VALUES (%s, %s, %s, %s, %s)',
                (email, about, name, username, isAnonymous, ))
    if str == "Ituser":
        raise Exception("5")
    user = DBconnect.select_query(connect,'select email, about, isAnonymous, id, name, username FROM user WHERE email = %s',
                           (email, ))

    return user_format(user)
示例#22
0
def update_thread(connect,id, slug, message):
    DBconnect.update_query(connect,'UPDATE thread SET slug = %s, message = %s WHERE id = %s', (slug, message, id, ))

    return details(connect,id=id, related=[])
示例#23
0
文件: users.py 项目: niggor/DB_TP
def update_user(email, about, name):
    DBconnect.exist(entity="user", identifier="email", value=email)
    DBconnect.update_query('UPDATE user SET email = %s, about = %s, name = %s WHERE email = %s',
                           (email, about, name, email, ))
    return details(email)
示例#24
0
def vote(connect,vote_id, vote_type):
    if vote_type == -1:
        DBconnect.update_query(connect,"UPDATE post SET dislikes=dislikes+1, points=points-1 where id = %s", (vote_id, ))
    else:
        DBconnect.update_query(connect,"UPDATE post SET likes=likes+1, points=points+1  where id = %s", (vote_id, ))
    return details(connect,details_id=vote_id, related=[])
示例#25
0
def update(connect,update_id, message):
    DBconnect.update_query(connect,'UPDATE post SET message = %s WHERE id = %s', (message, update_id, ))
    return details(connect,details_id=update_id, related=[])
示例#26
0
def remove_restore(connect,post_id, status):
    DBconnect.update_query(connect,"UPDATE post SET isDeleted = %s WHERE post.id = %s", (status, post_id, ))
    return {
        "post": post_id
    }
示例#27
0
def remove_follow(connect,email1, email2):
    DBconnect.update_query(connect,'DELETE FROM follower WHERE follower = %s AND followee = %s', (email1, email2, ))
    return users.details(connect,email1)
示例#28
0
def update(update_id, message):
    # DBconnect.exist(entity="post", identifier="id", value=update_id)
    DBconnect.update_query('UPDATE post SET message = %s WHERE id = %s', (message, update_id, ))
    return details(details_id=update_id, related=[])
示例#29
0
def remove_restore(post_id, status):
    DBconnect.exist(entity="post", identifier="id", value=post_id)
    DBconnect.update_query("UPDATE post SET isDeleted = %s WHERE post.id = %s", (status, post_id, ))
    return {
        "post": post_id
    }
示例#30
0
def inc_posts_count(connect,post):
    thread = DBconnect.select_query(connect,"SELECT thread FROM post WHERE id = %s", (post, ))
    DBconnect.update_query(connect,"UPDATE thread SET posts = posts + 1 WHERE id = %s", (thread[0][0], ))
    return