def get_cart(id): 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, sd.name, \ sd.registration_start_date, sd.registration_end_date, sd.payment_end_date, sd.id FROM courses,\ (SELECT sem_id, course_id FROM cart WHERE user_id = %s) as cart, semester_details as sd\ WHERE courses.course_id = cart.course_id AND sd.id = cart.sem_id;" cur.execute(query, (id,)) 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.user_id = id course.image = response[10] sem = SemesterDetails() sem.sem_name = response[11] sem.registration_start_date = response[12] sem.registration_end_date = response[13] sem.payment_end_date = response[14] sem.sem_id = response[15] course.sem = sem course_list.append(course) else: return [] cur.close() conn.close() return course_list except Exception as e: return e
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
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