Пример #1
0
	def get_comment_by(course_id):
		conn = None
		cur = None
		try:
			conn = PgConfig.db()
			if(conn):
				cur = conn.cursor()
				query = "SELECT comment, user_id, course_ratings,sem_id, comment_id FROM course_comments WHERE course_id = %s"
				cur.execute(query, (course_id, ))
				comments = cur.fetchall()
				comment_list =[]
				for comment in comments:
					user = User()
					query = "SELECT first_name, last_name, email, user_id, color_theme, image FROM users WHERE user_id = %s"
					cur.execute(query, (comment[1], ))
					response = cur.fetchone()
					user = User()
					user.comment_id = comment[4]
					user.first_name = response[0]
					user.last_name = response[1]
					user.email = response[2]
					user.user_id = response[3]
					user.comment= comment[0]
					user.rating = comment[2]
					user.color_theme = response[4]
					user.image = response[5]
					user.sem_id = comment[3]
					comment_list.append(user)

				cur.close()
				conn.close()
				return comment_list
			else:
				cur.close()
				conn.close()
				return []

		except Exception as e:
			return e