コード例 #1
0
ファイル: user.py プロジェクト: MysterySuperhero/subd_tp
def unfollow(con, follower_email, followee_email):
	query = "DELETE FROM follower WHERE follower = \'" + str(follower_email) + "\' AND " + "followee = \'" + str(
		followee_email) + "\'"

	dbConnector.update_query(con, query, ())

	return details(con, follower_email)
コード例 #2
0
ファイル: user.py プロジェクト: MysterySuperhero/subd_tp
def follow(con, follower_email, followee_email):
	query = "INSERT INTO follower (follower, followee) VALUES (\'" + str(follower_email) + "\', \'" + str(
		followee_email) + "\')"

	dbConnector.update_query(con, query, ())

	return details(con, follower_email)
コード例 #3
0
def restore_remove(connection, post, isDeleted):

    query = "UPDATE post SET isDeleted = " + str(isDeleted) + " WHERE id = " + str(post)

    dbConnector.update_query(connection, query, ())

    response = {"post": post}
    return response
コード例 #4
0
ファイル: thread.py プロジェクト: MysterySuperhero/subd_tp
def update(con, message, slug, thread):
	query = "UPDATE thread SET slug = " + "\'" + str(slug) + "\'" + ", message = " + "\'" + str(
		message) + "\'" + " WHERE id = " + str(thread);
	try:
		dbConnector.update_query(con, query, ())
	except Exception as e:
		print(e.message)
	return details(con, id=thread, related=[])
コード例 #5
0
def vote(connection, vote, post):
    if vote == 1:
        query = "UPDATE post SET likes = likes + 1, points = points + 1 WHERE id = " + str(post)
    else:
        query = "UPDATE post SET dislikes = dislikes + 1, points = points - 1 WHERE id = " + str(post)

    dbConnector.update_query(connection, query, ())

    return
コード例 #6
0
ファイル: user.py プロジェクト: MysterySuperhero/subd_tp
def updateProfile(con, about, user, name):
	query = "UPDATE user SET about = \'" + str(about) + "\', email = \'" + str(user) + "\', name = \'" + str(
		name) + "\' WHERE email = \'" + str(user) + "\'"
	try:
		dbConnector.update_query(con, query, ())
	except Exception as e:
		print (e.message)
	print details(con, user)
	return details(con, user)
コード例 #7
0
def unsubscribe(connection, user, thread):
    query = "DELETE FROM subscription WHERE thread = \'" + \
        str(thread) + "\' AND user = \'" + str(user) + "\'"

    try:
        dbConnector.update_query(connection, query, ())
    except Exception as e:
        print (e.message)

    result = {"thread": str(thread), "user": str(user)}
    return result
コード例 #8
0
ファイル: thread.py プロジェクト: MysterySuperhero/subd_tp
def vote(con, vote, thread):
	if vote == -1:
		query = "UPDATE thread SET dislikes = dislikes + 1, points = points - 1 WHERE id = " + str(thread)
	else:
		query = "UPDATE thread SET likes = likes + 1, points = points + 1 WHERE id = " + str(thread)

	try:
		dbConnector.update_query(con, query, ())
	except Exception as e:
		print (e.message)

	return details(con, thread=id, related=[])
コード例 #9
0
ファイル: thread.py プロジェクト: MysterySuperhero/subd_tp
def open_close(con, thread, isClosed):
	query = "UPDATE thread SET isClosed = " + str(isClosed) + " WHERE id = " + str(thread);

	try:
		dbConnector.update_query(con, query, ())
	except Exception as e:
		print (e.message)

	response = {
		"thread": thread}

	return response
コード例 #10
0
ファイル: forum.py プロジェクト: MysterySuperhero/subd_tp
def create(con, name, short_name, user):
	dbConnector.update_query(
		con,
		'INSERT INTO forum (name, short_name, user) VALUES (%s, %s, %s)', (name, short_name, user)
	);

	# check result of update query:
	forum = dbConnector.select_query(
		con,
		'SELECT id, name, short_name, user FROM forum WHERE short_name = %s', (short_name,)
	)

	return forum_description(forum);
コード例 #11
0
def create(connection, name, short_name, user):
    dbConnector.update_query(
        connection,
        'INSERT INTO forum (name, short_name, user) VALUES (%s, %s, %s)', (name,
                                                                           short_name, user)
    )

    forum = dbConnector.select_query(
        connection,
        'SELECT id, name, short_name, user FROM forum WHERE short_name = %s', (
            short_name,)
    )

    return serialise_f(forum)
コード例 #12
0
ファイル: thread.py プロジェクト: MysterySuperhero/subd_tp
def create(con, forum, title, isClosed, user, date, message, slug, optional):
	isDeleted = 0
	if "isDeleted" in optional:
		isDeleted = optional["isDeleted"]

	thread = dbConnector.update_query(con,
	                                  '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,))

	if thread == "Error":
		raise Exception("Thread already exists")

	thread = dbConnector.select_query(con,
	                                  '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
コード例 #13
0
def subscribe(connection, user, thread):
    query = "INSERT INTO subscription (thread, user) VALUES (\'" + \
        str(thread) + "\',\'" + str(user) + "\')"

    try:
        dbConnector.update_query(connection, query, ())
    except Exception as e:
        print (e.message)

    query = "SELECT thread, user FROM subscription WHERE thread = \'" + \
        str(thread) + "\', " + "user = \'" + str(user) + "\'"

    try:
        sub = dbConnector.select_query(connection, query, ())
    except Exception as e:
        print (e.message)

    result = {"thread": sub[0][0], "user": sub[0][1]}

    return result
コード例 #14
0
ファイル: thread.py プロジェクト: MysterySuperhero/subd_tp
def restore_remove(con, thread, isDeleted):
	posts = 0
	if isDeleted == 0:
		query = "SELECT COUNT(id) FROM post WHERE thread = " + str(thread)
		print query
		posts = dbConnector.select_query(con, query, ())[0][0]

	query_thread = "UPDATE thread SET isDeleted = " + str(isDeleted) + ", posts = " + str(posts) + " WHERE id = " + str(
		thread)
	query_post = "UPDATE post SET isDeleted = " + str(isDeleted) + " WHERE thread = " + str(thread)

	try:
		dbConnector.update_query(con, query_thread, ())
		dbConnector.update_query(con, query_post, ())
	except Exception as e:
		print (e.message)

	response = {
		"thread": thread}

	return response
コード例 #15
0
ファイル: user.py プロジェクト: MysterySuperhero/subd_tp
def create(con, username, about, name, email, optional):
	isAnonymous = 0;
	if "isAnonymous" in optional:
		isAnonymous = optional["isAnonymous"]

	user = dbConnector.update_query(
		con,
		'INSERT INTO user (username, about, name, email, isAnonymous) VALUES (%s, %s, %s, %s, %s)',
		(username, about, name, email, isAnonymous,)
	)

	if user == "Error":
		raise Exception("5")

	# check insertion
	user = dbConnector.select_query(
		con,
		'SELECT id, email, about, isAnonymous, name, username FROM user WHERE email = %s',
		(email,)
	)

	return user_description(user)
コード例 #16
0
def update(connection, post, message):
    query = "UPDATE post SET message = " + str(message) + " WHERE id = " + str(post)
    dbConnector.update_query(connection, query, ())
    return details(connection, details_id=post, related=[])
コード例 #17
0
ファイル: thread.py プロジェクト: MysterySuperhero/subd_tp
def dec_posts(con, post):
	query = "SELECT thread FROM post WHERE id = " + str(post)
	thread = dbConnector.select_query(con, query, ())[0][0]
	query = "UPDATE thread SET posts = posts - 1 WHERE id = " + str(thread)
	dbConnector.update_query(con, query, ())
	return