Ejemplo n.º 1
0
	def get_student_schedule(id):
		conn = None
		cur = None
		try:
			conn = PgConfig.db()
			if(conn):
				cur = conn.cursor()
				query = "SELECT courses.course_name, courses.start_time, courses.end_time, courses.location, courses.course_id, \
				courses.prof_id, courses.days, courses.course_code, courses.department, courses.description, courses.image, sem_id FROM courses, \
				(SELECT course_id, sem_id FROM enrolled_courses WHERE user_id = %s) as enrolled_courses \
				WHERE enrolled_courses.course_id = courses.course_id"
				cur.execute(query, (id,))
				schedules = cur.fetchall()
				courses_list = []
				if(len(schedules)):
					for schedule in schedules:
						course = Course()
						course.user_id = id
						course.course_name = schedule[0]
						course.start_time = schedule[1]
						course.end_time = schedule[2]
						course.location = schedule[3]
						course.course_id = schedule[4]
						course.prof_id = schedule[5]
						course.days = schedule[6]
						course.course_code = schedule[7]
						course.comment = Service.get_comment_by(schedule[4])
						course.professor = Service.get_user_by(schedule[5])
						course.start_dates =Service.get_start_dates(schedule[6])
						course.department = schedule[8]
						course.description = schedule[9]
						course.image = schedule[10]
						course.sem = Service.get_sem_by(schedule[11])
						courses_list.append(course)
						cur.close()
						conn.close()
					return courses_list
				else:
					cur.close()
					conn.close()
					return []
		except Exception as e:
			return e
Ejemplo n.º 2
0
	def get_course_by(name, start, end):
		conn = None
		cur = None
		try:
			conn = PgConfig.db()
			if(conn):
				cur = conn.cursor()
				query = "SELECT course_id, course_name, description, prof_id, location, start_time, end_time, days, department,\
				course_code, image FROM courses WHERE course_name ILIKE %s ORDER BY course_name LIMIT %s OFFSET %s"
				cur.execute(query, (name+'%', end, start,))
				courses = cur.fetchall()
				courses_list = []
				if(len(courses)):
					for obj in courses:
						course = Course()
						course.course_id=obj[0]
						course.course_name=obj[1]
						course.description=obj[2]
						course.location = obj[4]
						course.start_time = obj[5]
						course.end_time = obj[6]
						course.days = obj[7]
						course.department = obj[8]
						course.professor = Service.get_user_by(obj[3])
						course.comment = Service.get_comment_by(obj[0])
						course.course_code = obj[9]
						course.image = obj[10]
						courses_list.append(course)
					cur.close()
					conn.close()
					return courses_list
				else:
					cur.close()
					conn.close()
					return []

		except Exception as e:
			return e
Ejemplo n.º 3
0
	def get_course_by_id(course_id, sem_id):
		conn = None
		cur = None
		try:
			conn = PgConfig.db()
			if(conn):
				cur = conn.cursor()
				query = "SELECT course_id, course_name, description, prof_id, location, start_time, end_time, days, department,\
				course_code, image FROM courses WHERE course_id = %s"
				cur.execute(query, (course_id,))
				obj = cur.fetchone()
				if(obj):
					course = Course()
					course.course_id=obj[0]
					course.course_name=obj[1]
					course.description=obj[2]
					course.location = obj[4]
					course.start_time = obj[5]
					course.end_time = obj[6]
					course.days = obj[7]
					course.department = obj[8]
					course.professor = Service.get_user_by(obj[3])
					course.comment = Service.get_comment_by(obj[0])
					course.course_code = obj[9]
					course.start_dates =Service.get_start_dates(obj[7])
					course.image = obj[10]
					if(sem_id):
						course.sem = Service.get_sem_by(sem_id)
					cur.close()
					conn.close()
					return course
				else:
					cur.close()
					conn.close()
					return []

		except Exception as e:
			return e
Ejemplo n.º 4
0
	def get_all_courses(start, end):
		conn = None
		cur = None
		try:
			conn = PgConfig.db()
			if(conn):
				cur = conn.cursor()
				query = "SELECT courses.course_id,courses.course_name, courses.description, \
				courses.prof_id, courses.location, courses.start_time, courses.end_time, \
				courses.days, courses.department, courses.course_code, courses.image FROM courses ORDER BY courses.course_name ASC LIMIT %s OFFSET %s"
				cur.execute(query, (end, start,))
				courses = cur.fetchall()
				course_list = []
				if(len(courses)):
					for response in courses:
						course = Course()
						course.course_id = response[0]
						course.course_name = response[1]
						course.description = response[2]
						course.professor = Service.get_user_by(response[3])
						course.location = response[4]
						course.start_time = response[5]
						course.end_time = response[6]
						course.days = response[7]
						course.department = response[8]
						course.course_code = response[9]
						course.image = response[10]
						course.comment = Service.get_comment_by(response[0])
						course_list.append(course)
				else:
					return []

				cur.close()
				conn.close()
				return course_list
		except Exception as e:
			return e