def register_student_list(organization, course, liste): token = get_jwt_identity() if not check_auth(token, organization, "lecturer"): return jsonify("Unauthorized access!") if check_lecture_permission(organization, token, course): if liste == "True": rtn = jsonify( Course(db, organization, course).register_student_csv(request.files["liste"], token["fullname"])) else: rtn = jsonify( Course(db, organization, course).register_student( pickle.loads(request.form["liste"]))) log_activity(request.remote_addr, token["username"], request.endpoint) return rtn return jsonify("Unauthorized access!")
def get_course(organization, course): token = get_jwt_identity() if not check_auth(token, organization, "student"): return jsonify("Unauthorized Access.") if check_lecture_permission(organization, token, course): rtn = jsonify(Course(db, organization, course).get_course()) log_activity(request.remote_addr, token["username"], request.endpoint) return rtn return jsonify("Unauthorized access!")
def add_course(organization, course): token = get_jwt_identity() if not check_auth(token, organization, "admin"): return jsonify("Unauthorized access!") else: name = request.form["name"] code = request.form["code"] lecturers = request.form["lecturers"] rtn = jsonify( Course(db, organization, code).add_course(name, lecturers)) log_activity(request.remote_addr, token["username"], request.endpoint) return rtn
def groupcourse_seed(): groupcourse = GroupCourse() groupcourse.group_number = 1 groupcourse.semester = 1 groupcourse.guest_semester = 3 groupcourse.date_exam = '1396-03-1' groupcourse.time_exam = '08:00' groupcourse.term = 1 groupcourse.capacity = 45 groupcourse.min_capacity = 15 groupcourse.Course_id = Course.select().limit(1)[0].id groupcourse.professor_id = Professor.select().limit(1)[0].id groupcourse.Time_Course_id = TimeCourse.select().limit(1)[0].id groupcourse.save() groupcourse = GroupCourse() groupcourse.group_number = 1 groupcourse.semester = 1 groupcourse.guest_semester = 3 groupcourse.date_exam = '1396-03-2' groupcourse.time_exam = '11:00' groupcourse.term = 1 groupcourse.capacity = 45 groupcourse.min_capacity = 15 groupcourse.Course_id = Course.select().offset(1)[0].id groupcourse.professor_id = Professor.select().offset(1)[0].id groupcourse.Time_Course_id = TimeCourse.select().offset(2)[0].id groupcourse.save() groupcourse = GroupCourse() groupcourse.group_number = 1 groupcourse.semester = 1 groupcourse.guest_semester = 3 groupcourse.date_exam = '1396-03-3' groupcourse.time_exam = '11:00' groupcourse.term = 1 groupcourse.capacity = 45 groupcourse.min_capacity = 15 groupcourse.Course_id = Course.select().offset(3)[0].id groupcourse.professor_id = Professor.select().limit(1)[0].id groupcourse.Time_Course_id = TimeCourse.select().offset(2)[0].id groupcourse.save() groupcourse = GroupCourse() groupcourse.group_number = 1 groupcourse.semester = 1 groupcourse.guest_semester = 3 groupcourse.date_exam = '1396-03-5' groupcourse.time_exam = '11:00' groupcourse.term = 1 groupcourse.capacity = 45 groupcourse.min_capacity = 15 groupcourse.Course_id = Course.select().offset(4)[0].id groupcourse.professor_id = Professor.select().limit(1)[0].id groupcourse.Time_Course_id = TimeCourse.select().offset(3)[0].id groupcourse.save() groupcourse = GroupCourse() groupcourse.group_number = 1 groupcourse.semester = 1 groupcourse.guest_semester = 3 groupcourse.date_exam = '1396-03-2' groupcourse.time_exam = '11:00' groupcourse.term = 1 groupcourse.capacity = 45 groupcourse.min_capacity = 15 groupcourse.Course_id = Course.select().offset(2)[0].id groupcourse.professor_id = Professor.select().offset(0)[0].id groupcourse.Time_Course_id = TimeCourse.select().offset(3)[0].id groupcourse.save() groupcourse = GroupCourse() groupcourse.group_number = 1 groupcourse.semester = 1 groupcourse.guest_semester = 3 groupcourse.date_exam = '1396-03-8' groupcourse.time_exam = '11:00' groupcourse.term = 1 groupcourse.capacity = 45 groupcourse.min_capacity = 15 groupcourse.Course_id = Course.select().offset(1)[0].id groupcourse.professor_id = Professor.select().offset(1)[0].id groupcourse.Time_Course_id = TimeCourse.select().offset(1)[0].id groupcourse.save() print('create all GroupCourses successfully')
from Models.Student import Student from Models.Professor import Professor from Models.Course import Course ml = Course(40441, 'Machine Learning', 'ce') deep = Course(40123, 'Deep Learning', 'ce') parham = Student(94109562, 'Parham Hessabi', 'ce') soleimani = Professor(4112412, 'Mahdie Soleimani', 123, 132) soleimani.present_course(ml) soleimani.present_course(deep) parham.enroll(ml, soleimani) parham.enroll(deep, soleimani) parham.finish("Machine Learning", 9) parham.finish("Deep Learning", 15) print(parham.grade("Machine Learning")) print(parham.grade("Deep Learning")) print(soleimani.salary) print(parham.average)
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_professor_schedule(id): conn = None cur = None try: conn = PgConfig.db() if(conn): cur = conn.cursor() query = "SELECT course_name, start_time, end_time, location, course_id,\ prof_id, days, course_code, department, description, image FROM courses WHERE prof_id = %s" cur.execute(query, (id,)) schedules = cur.fetchall() courses_list = [] if(len(schedules)): for schedule in schedules: course = Course() 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] 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(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
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
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
def course_seed(): course = Course() course.name = "پیاده سازی پایگاه داده" course.presentation = "practical" course.type = "public" course.status_prerequisite = "yes" course.price = 6000 course.list_prerequisite = "" course.unit_number = 2 course.save() course = Course() course.name = "مهندسی نرم افزار 2" course.presentation = "practical" course.type = "public" course.status_prerequisite = "yes" course.price = 8000 course.list_prerequisite = "" course.unit_number = 2 course.save() course = Course() course.name = "ریاضیات مهندسی" course.presentation = "practical" course.type = "public" course.status_prerequisite = "yes" course.price = 30000 course.list_prerequisite = "" course.unit_number = 2 course.save() course = Course() course.name = "سیگنال ها و سیستم ها" course.presentation = "practical" course.type = "public" course.status_prerequisite = "yes" course.price = 6000 course.list_prerequisite = "" course.unit_number = 2 course.save() course = Course() course.name = "آمار واحتمالات مهندسی" course.presentation = "practical" course.type = "public" course.status_prerequisite = "yes" course.price = 6000 course.list_prerequisite = "" course.unit_number = 2 course.save() print('create successfully all Courses')