Exemplo n.º 1
0
def details(con, id, related):
	thread = dbConnector.select_query(
		con,
		'SELECT date, forum, id, isClosed, isDeleted, message, slug, title, user, dislikes, likes, points, posts FROM thread  USE INDEX (full_except_about)  WHERE id = %s;',
		(id,)
	)

	if len(thread) == 0:
		raise Exception('Thread not founded')

	thread = thread[0]
	thread = {
		'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],
	}

	if "user" in related:
		thread["user"] = user.details(con, thread["user"])
	if "forum" in related:
		thread["forum"] = forum.details(con=con, short_name=thread["forum"], related=[])

	return thread
Exemplo n.º 2
0
def list(con, required, optional, related):
	query = "SELECT date, dislikes, forum, id, isClosed, isDeleted, likes, message, points, posts, slug, title, user FROM thread WHERE "

	params = []
	if 'forum' in required:
		query += "forum = %s USE INDEX (forum_full) "
		params.append(required["forum"][0])
	# query += "forum = " + "\'" + str(required["forum"][0]) + "\'"
	else:
		query += "user = %s USE INDEX (user_full) "
		params.append(required["user"][0])
	# query += "user = "******"\'" + str(required["user"][0]) + "\'"

	if 'since' in optional:
		params.append(optional["since"][0])
		query += " AND date >= %s "

	if 'order' in optional:
		query += " ORDER BY date " + "".join(optional["order"])

	if 'limit' in optional:
		query += " LIMIT " + "".join(optional["limit"])

	try:
		threads = dbConnector.select_query(con, query, params)
	except Exception as e:
		print (e.message)

	response = []
	if threads != ():
		for k in threads:
			k = {
				'date': str(k[0]),  # .strftime("%Y-%m-%d %H:%M:%S"),
				'dislikes': k[1],
				'forum': k[2],
				'id': k[3],
				'isClosed': bool(k[4]),
				'isDeleted': bool(k[5]),
				'likes': k[6],
				'message': k[7],
				'points': k[8],
				'posts': k[9],
				'slug': k[10],
				'title': k[11],
				'user': k[12]
			}
			if "user" in related:
				k["user"] = user.details(con, k["user"])
			if "forum" in related:
				k["forum"] = forum.details(con=con, short_name=k["forum"], related=[])
			response.append(k)

	return response
Exemplo n.º 3
0
def details(con, short_name, related):
	forum = dbConnector.select_query(
		con, 'SELECT id, name, short_name, user FROM forum WHERE short_name = %s', (short_name,)
	)

	if len(forum) == 0:
		raise Exception("Forum " + short_name + " not found")

	forum = forum_description(forum)

	if "user" in related:
		forum["user"] = user.details(con, forum["user"])
	return forum
Exemplo n.º 4
0
def details(con, details_id, related):
	post = post_query(con, details_id)
	if post is None:
		raise Exception("no post with id = " + details_id)

	if "user" in related:
		post["user"] = user.details(con, post["user"])
	if "forum" in related:
		post["forum"] = forum.details(con, post["forum"], [])
	if "thread" in related:
		post["thread"] = thread.details(con, post["thread"], [])

	return post
Exemplo n.º 5
0
def user_details():

	con = dbConnector.connect()
	params = helpers.json_from_get(request)

	try:
		helpers.check_params(params, ["user"])
		userr = user.details(con, params["user"])
	except Exception as e:
		con.close()
		return json.dumps({"code": 1, "response": (e.message)})
	
	con.close()
	return json.dumps({"code": 0, "response": userr})
Exemplo n.º 6
0
def posts_list(con, entity, params, identifier, related=[]):
	query = "SELECT date, dislikes, forum, id, isApproved, isDeleted, isEdited, isHighlighted, isSpam, likes, message, " \
	        "parent, points, thread, user FROM post WHERE " + entity + " = " + '\'' + str(''.join(identifier)) + '\''

	parameters = tuple()
	if "since" in params:
		query += " AND date >= %s"
		parameters += tuple(params["since"])

	query += " ORDER BY date " + ''.join(params["order"])

	if "limit" in params:
		query += " LIMIT " + ''.join(params["limit"])

	parameters += tuple('')
	post_ids = dbConnector.select_query(con, query, parameters)

	post_list = []
	for post in post_ids:
		pf = {
			'date': str(post[0]),
			'dislikes': post[1],
			'forum': post[2],
			'id': post[3],
			'isApproved': bool(post[4]),
			'isDeleted': bool(post[5]),
			'isEdited': bool(post[6]),
			'isHighlighted': bool(post[7]),
			'isSpam': bool(post[8]),
			'likes': post[9],
			'message': post[10],
			'parent': post[11],
			'points': post[12],
			'thread': post[13],
			'user': post[14],
		}
		if "user" in related:
			pf["user"] = user.details(con, pf["user"])
		if "forum" in related:
			pf["forum"] = forum.details(con, short_name=pf["forum"], related=[])
		if "thread" in related:
			pf["thread"] = thread.details(con, id=pf["thread"], related=[])
		post_list.append(pf)
	return post_list
Exemplo n.º 7
0
def forum_listUsers(con, forum_shortname, optional):
	query = "SELECT user.id, user.name, user.email FROM user " \
	        "INNER JOIN post ON user.email = post.user  WHERE forum = \'" + str(forum_shortname) + "\')"
	if "since_id" in optional:
		query += " AND user.id >= " + str(optional["since_id"][0])
	if "order" in optional:
		query += " ORDER BY user.name " + str(optional["order"][0])
	if "limit" in optional:
		query += " LIMIT " + str(optional["limit"][0])

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

	response = []
	for post in posts:
		res = user.details(con, str(post[2]))
		response.append(res)

	return response