示例#1
0
文件: User.py 项目: kirill-m/tp_subd
def create():
	requestBody = request.json

	username = try_encode(requestBody.get('username'))
	about = requestBody.get('about')
	name = try_encode(requestBody.get('name'))
	email = requestBody.get('email')
	isAnonymousKey = requestBody.get('isAnonymous', False)
	if isAnonymousKey:
		isAnonymous = 1
	else:
		isAnonymous = 0

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

	try:
		db.execute(sql, args, True)
	except MySQLdb.IntegrityError, message:
		if message[0] == MYSQL_DUPLICATE_ENTITY_ERROR:
			return json.dumps({"code": 5,
							   "response": "This user already exists"}, indent=4)
		return json.dumps({"code": 4,
						   "response": "Oh, we have some really bad error"}, indent=4)
示例#2
0
文件: User.py 项目: kirill-m/tp_subd
def update_profile():
	requestBody = request.json

	about = try_encode(requestBody.get('about'))
	email = try_encode(requestBody.get('user'))
	name = try_encode(requestBody.get('name'))

	args = {'about': about, 'name': name, 'email': email}
	db.execute("""UPDATE User SET about = %(about)s, name = %(name)s WHERE email = %(email)s;""", args, True)
	return json.dumps({"code": 0, "response": get_user_dict(email)}, indent=4)   
示例#3
0
文件: User.py 项目: kirill-m/tp_subd
def update_profile():
    requestBody = request.json

    about = try_encode(requestBody.get('about'))
    email = try_encode(requestBody.get('user'))
    name = try_encode(requestBody.get('name'))

    args = {'about': about, 'name': name, 'email': email}
    db.execute(
        """UPDATE User SET about = %(about)s, name = %(name)s WHERE email = %(email)s;""",
        args, True)
    return json.dumps({"code": 0, "response": get_user_dict(email)}, indent=4)
示例#4
0
def create():
	requestBody = request.json
	
	# Required
	forum = requestBody.get('forum')
	title = try_encode(requestBody.get('title'))
	if requestBody.get('isClosed'):
		is_closed = 1
	else:
		is_closed = 0
	user = requestBody.get('user')
	date = requestBody.get('date')
	message = requestBody.get('message')
	slug = requestBody.get('slug')

	# Optional
	if requestBody.get('isDeleted', False):
		isDeleted = 1
	else:
		isDeleted = 0

	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);"""
	args = {'forum': forum, 'title': title, 'isClosed': is_closed, 'user': user, 'date': date, 'message': message,
			'slug': slug, 'isDeleted': isDeleted}

	try:
		db.execute(sql, args, True)
	except MySQLdb.IntegrityError, message:
		print message[0]
示例#5
0
文件: Post.py 项目: kirill-m/tp_subd
def update():
	requestBody = request.json
	postID = requestBody.get('post')
	message = try_encode(requestBody.get('message'))

	args = {'message': message, 'post': postID}
	db.execute("""UPDATE Post SET message = %(message)s WHERE post = %(post)s;""", args, True)

	post = get_post_by_id(postID)
	if not post:
		return json.dumps({"code": 1, "response": "Empty set"}, indent=4)

	return json.dumps({"code": 0, "response": post}, indent=4)
示例#6
0
文件: User.py 项目: kirill-m/tp_subd
def create():
    requestBody = request.json

    username = try_encode(requestBody.get('username'))
    about = requestBody.get('about')
    name = try_encode(requestBody.get('name'))
    email = requestBody.get('email')
    isAnonymousKey = requestBody.get('isAnonymous', False)
    if isAnonymousKey:
        isAnonymous = 1
    else:
        isAnonymous = 0

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

    try:
        db.execute(sql, args, True)
    except MySQLdb.IntegrityError, message:
        if message[0] == MYSQL_DUPLICATE_ENTITY_ERROR:
            return json.dumps(
                {
                    "code": 5,
                    "response": "This user already exists"
                }, indent=4)
        return json.dumps(
            {
                "code": 4,
                "response": "Oh, we have some really bad error"
            },
            indent=4)
示例#7
0
文件: Post.py 项目: kirill-m/tp_subd
def update():
    requestBody = request.json
    postID = requestBody.get('post')
    message = try_encode(requestBody.get('message'))

    args = {'message': message, 'post': postID}
    db.execute(
        """UPDATE Post SET message = %(message)s WHERE post = %(post)s;""",
        args, True)

    post = get_post_by_id(postID)
    if not post:
        return json.dumps({"code": 1, "response": "Empty set"}, indent=4)

    return json.dumps({"code": 0, "response": post}, indent=4)