Beispiel #1
0
def post_vote():

    data = request.get_json()

    post_id = data['post']
    vote_value = data['vote']

    if vote_value == 1:
    	params = {}

        db.execute_post("UPDATE Post SET likes = likes + 1, points = points + 1 WHERE post = '%s'" % (post_id), params)
    
    elif vote_value == -1:
    	params = {}

        db.execute_post("UPDATE Post SET dislikes = dislikes + 1, points = points - 1 WHERE post = '%s'" % (post_id), params)
    else:

        return_data = {"code": 3, "response": RESPONSE_CODE_3}

        return jsonify(return_data)

    post = get_id_post(post_id)
    if not post:

        return_data = {"code": 1, "response": RESPONSE_CODE_1}

        return jsonify(return_data)

    return_data = {"code": 0, "response": post}

    return jsonify(return_data)
Beispiel #2
0
def close():
	data = request.get_json()

	thread = data['thread']

	params = {}
    
	db.execute_post("UPDATE Thread SET isClosed = 1 WHERE thread = '%s'" % (thread), params)

	return_data = {"code": 0, "response": thread}

	return jsonify(return_data)
Beispiel #3
0
def post_create():
	data = request.get_json()

	# Required
	date = data['date']
	thread = data['thread']
	message = data['message']
	user = data['user']
	forum = data['forum']

	# Optional
	parent = data.get('parent', None)
	is_approved = data.get('isApproved', False)
	is_highlighted = data.get('isHighlighted', False)
	is_edited = data.get('isEdited', False)
	is_spam = data.get('isSpam', False)
	is_deleted = data.get('isDeleted', False)

	try:
		sql = """INSERT INTO Post (user, thread, forum, message, parent, date, \
			isSpam, isEdited, isDeleted, isHighlighted, isApproved) VALUES \
			(%(user)s, %(thread)s, %(forum)s, %(message)s, %(parent)s, %(date)s, \
			%(isSpam)s, %(isEdited)s, %(isDeleted)s, %(isHighlighted)s, %(isApproved)s);"""

		params = {'user': user, 'thread': thread, 'forum': forum, 'message': message, 'parent': parent, 'date': date,
				'isSpam': is_spam, 'isEdited': is_edited, 'isDeleted': is_deleted, 'isHighlighted': is_highlighted,
				'isApproved': is_approved}

		post_id = db.execute_post(sql, params)
		
		post = get_id_post(post_id)

        # returnData = {"code": 0, "response": {"date": date, "forum": forum,
        #                                       "id": cursor.lastrowid, "isApproved": isApproved,
        #                                       "isEdited": isEdit, "isHighlited": isHighlighted, "isSpam": isSpam,
        #                                       "message": message, "parent": parent, "thread": thread, "user": user}}		

		response_data = {"date": date, "forum": forum,"id": post_id, "isApproved": is_approved,"isEdited": is_edited, "isHighlited": is_highlighted, "isSpam": is_spam,"message": message, "parent": parent, "thread": thread, "user": user}

		params = {}

		db.execute_post("UPDATE Thread SET posts = posts + 1 WHERE thread = '%s'" % (thread), params)
	except Exception as e:

		return_data = {"code": 1, "response": RESPONSE_CODE_1}

		return jsonify(return_data)

	#return_data = {"code": 0, "response": post}

	return_data = {"code": 0, "response": response_data}

	return jsonify(return_data)
Beispiel #4
0
def subscribe():
	data = request.get_json()

	user = data['user']
	thread = data['thread']

	try:
		params = {}

		db.execute_post("INSERT INTO Subscription (subscriber, thread) VALUES ('%s', '%s')" % (user, thread), params)

	except MySQLdb.IntegrityError, message:
		if message[0] == 1062:
			print "Already subscribed"
Beispiel #5
0
def thread_update():
    data = request.get_json()

    message = data['message']
    slug = data['slug']
    thread_id = data['thread']

    params = {}

    db.execute_post("UPDATE Thread SET message = '%s', slug = '%s' WHERE thread = '%s'" % (message, slug, thread_id), params)

    return_data = {"code": 0, "response": get_id_thread(thread_id)}

    return jsonify (return_data)
Beispiel #6
0
def unfollow():

	data = request.get_json()

	follower = data['follower']
	followee = data['followee']

	params = {}

	db.execute_post("DELETE FROM Follower WHERE follower = '%s' AND following = '%s'" % (follower, followee), params)

	return_data = {"code": 0, "response": dictionary_of_user(follower)}

	return jsonify(return_data)
Beispiel #7
0
def follow():

	data = request.get_json()

	follower = data['follower']
	followee = data['followee']

	params = {}

	db.execute_post("INSERT INTO Follower (follower, following) VALUES ('%s','%s')" % (follower, followee), params)

	return_data = {"code": 0, "response": dictionary_of_user(follower)}

	return jsonify(return_data)
Beispiel #8
0
def update_profile():

	data = request.get_json()
	about = data['about']
	email = data['user']
	name = data['name']

	params = {}

	sql = "UPDATE User SET about = '%s', name = '%s' WHERE email = '%s'" % (about, name, email)

	db.execute_post(sql, params)

	return_data = {"code": 0, "response": dictionary_of_user(email)}

	return jsonify(return_data)
Beispiel #9
0
def user_create():

	data = request.get_json()

	username = data['username']
	about = data['about']
	name = data['name']
	email = data['email']
	is_anonymous = data.get('isAnonymous', False)


	sql = """INSERT INTO User (username, about, name, email, isAnonymous) VALUES \
		(%(username)s, %(about)s, %(name)s, %(email)s, %(isAnonymous)s);"""
	params = {'username': username, 'about': about, 'name': name, 'email': email, 'isAnonymous': is_anonymous}

	try:
		my_last = db.execute_post(sql, params)

	except MySQLdb.IntegrityError, message:
		if message[0] == 1062:

			return_data = {"code": 5,"response": RESPONSE_CODE_5}

			return jsonify(return_data)

		return_data = {"code": 4,"response": RESPONSE_CODE_4}

		return jsonify(return_data)
Beispiel #10
0
def thread_create():

	data = request.get_json()

	forum = data['forum']

	title = (data.get('title').encode('utf-8'))

	is_closed  = data['isClosed']
	user = data['user']
	date = data['date']
	message = data['message']
	slug = data['slug']
	is_deleted = data.get('isDeleted', False)

	sql = """INSERT INTO Thread (forum, title, isClosed, user, date, message, slug, isDeleted) \
		VALUES (%(forum)s, %(title)s, %(isClosed)s, %(user)s, %(date)s, %(message)s, %(slug)s, %(isDeleted)s);"""
	params = {'forum': forum, 'title': title, 'isClosed': is_closed, 'user': user, 'date': date, 'message': message,
			'slug': slug, 'isDeleted': is_deleted}

	try:
		my_last = db.execute_post(sql, params)

	except MySQLdb.IntegrityError, message:
		print message[0]
Beispiel #11
0
def unsubscribe():

	data = request.get_json()

	user = data['user']
	thread = data['thread']

	params = {}

	db.execute_post("DELETE FROM Subscription WHERE subscriber = '%s' AND thread = '%s'" % (user, thread), params)

	result_dict = {'thread': thread, 'user': str_to_json(user)}

	return_data = {"code": 0, "response": result_dict}

	return jsonify(return_data)
Beispiel #12
0
def post_restore():
	data = request.get_json()

	post_id = data['post']

	post = get_id_post(post_id)
	thread_id = post['thread']

	params = {}

	db.execute_post("UPDATE Post SET isDeleted = 0 WHERE post = '%s'" % (post_id), params)
	db.execute_post("UPDATE Thread SET posts = posts + 1 WHERE thread = '%s'" % (thread_id), params)

	return_data = {"code": 0, "response": {"post": post_id}}

	return jsonify(return_data)
Beispiel #13
0
def thread_restore():
	data = request.get_json()

	thread = data['thread']

	post_list = get_post_list(thread=thread)
	for post in post_list:
		params = {}

		db.execute_post("UPDATE Post SET isDeleted = 0 WHERE post = '%s'" % (post['id']), params)

	params = {}

	db.execute_post("UPDATE Thread SET isDeleted = 0, posts = '%s' WHERE thread = '%s'" % (len(post_list), thread))

	return_data = {"code": 0, "response": thread}

	return jsonify(return_data)
Beispiel #14
0
def thread_vote():
    data = request.get_json()

    vote_value = data['vote']
    thread_id = data['thread']

    if vote_value == 1:
    	params = {}

        db.execute_post("UPDATE Thread SET likes = likes + 1, points = points + 1 WHERE thread = '%s'" % (thread_id), params)

    else:
    	params = {}

        db.execute_post("UPDATE Thread SET dislikes = dislikes + 1, points = points - 1 WHERE thread = '%s'" % (thread_id), params)

    return_data = {"code": 0, "response": get_id_thread(thread_id)}

    return jsonify(return_data)
Beispiel #15
0
def post_update():
	data = request.get_json()

	post_id = data['post']

	message = data['message']

	params = {}

	db.execute_post("UPDATE Post SET message = '%s' WHERE post = '%s'" % (message, post_id),params)

	post = get_id_post(post_id)
	if not post:

		return_data = {"code": 1, "response": RESPONSE_CODE_1}

		return jsonify(return_data)

	return_data = {"code": 0, "response": post}

	return jsonify(return_data)
Beispiel #16
0
def forum_create_forum():


    data = request.get_json()

    name = data['name']
    short_name = data['short_name']
    user = data['user']

    params = {}

    sql = "INSERT INTO Forum (name, short_name, user) VALUES ('%s','%s','%s')" % (name, short_name, user)


    try:
        my_last = db.execute_post(sql,params)

    except MySQLdb.IntegrityError, message:
        print message[0]
Beispiel #17
0
def clear():

	params = {}

	db.execute_post("DELETE Forum.* FROM Forum", params)
	db.execute_post("DELETE User.* FROM User", params)
	db.execute_post("DELETE Post.* FROM  Post", params)
	db.execute_post("DELETE Thread.* FROM  Thread", params)
	db.execute_post("DELETE Subscription.* FROM Subscription", params)
	db.execute_post("DELETE Follower.* FROM Follower", params)

	return_data  = {"code": 0, "response": "OK"}

	return jsonify (return_data)