def adder(): if 'username' in session: if auth.authSuper(session['username']): deps=database.get_all_dependencies() courses=database.get_courses() print 'TESTCODE' in courses return render_template('adder.html', deps=deps, courses=courses, user=session['username']) else: return render_template('master.html', error='You do not have the permission for this.') else: return redirect(url_for('login'))
def courses_page(): if request.method == "GET": courses = database.get_courses() return render_template("courses.html", year=year_dec, courses=courses) elif request.method == "POST": if session.get('logged_in') is None: flash("You are not logged in", "danger") return redirect(url_for("login_page")) keys = request.form.getlist("course_keys") for key in keys: database.delete_course(key) return redirect(url_for("courses_page"))
def refresh_courses_list(self): ''' get courses instances from database and add them the scrolling list ''' # clear the parent widget self.ids.main_screen.ids.courses_list.clear_widgets() courses = get_courses() for course in courses: item = CustomTwoLineAvatarListItem( item_id=course[0], app=self.parent, model='course', text=course[1], secondary_text=course[2], ) icon = IconLeftWidget(icon='school') item.add_widget(icon) self.ids.main_screen.ids.courses_list.add_widget(item)
def admin_display(): # requires session to be set for it to work if session['successful_load'] == 'true': # obtain all necessary information for the admin page and # render the admin template #will have all info from db passed into it courses = database.get_courses() languages = database.get_languages() projects = database.get_projects() work = database.get_work_experience() colors = database.get_colors() # Remove session session['successful_load'] = 'false' return render_template('admin.html', course_list=courses, language_list=languages, \ project_list=projects, work_list=work) else: return 'You are not authorized to access this page'
def on_start(self): self.lesson_dialog = None create_tables() courses = get_courses() for course in courses: self.add_item(item_id=course[0], model='course', text=course[1], secondary_text=course[2]) tutors = get_tutors() for tutor in tutors: self.add_item(item_id=tutor[0], model='tutors', text=tutor[1], secondary_text=tutor[2]) item = CustomTwoLineAvatarListItem( item_id=tutor[0], app=self, model='tutor', text=tutor[1], secondary_text=tutor[2], ) icon = IconLeftWidget(icon='book-account-outline') item.add_widget(icon) self.root.main_screen.ids.tutors_list.add_widget(item) lessons = get_lessons() for lesson in lessons: item = CustomThreeLineAvatarListItem(item_id=lesson[0], app=self, model='lesson', text=lesson[1], secondary_text=lesson[2], tertiary_text=lesson[3], course_id=lesson[4]) icon = IconLeftWidget(icon='book-open-blank-variant') item.add_widget(icon) self.root.main_screen.ids.lessons_list.add_widget(item)
def show_education(): colors = database.get_colors() courses = database.get_courses() return render_template('education.html', course_list=courses, color_list=colors)
def get_courses(): if request.args.get('instructor_id') is not None: instructor_id = request.args.get('instructor_id') return database.get_courses_taught_by_instructor(instructor_id) else: return database.get_courses()
def home(): form = AddUserForm() if form.validate_on_submit(): results = request.form global courses course_name = results['subject'] course_number = results['course_no'] course_section = results['course_section'] new_course = Course(course_name, course_number, course_section) course_status = is_course_available( new_course ) # checks if course is already available or if it is on SSC if course_status != False: if course_status == True: return render_template('error.html', message='Course is already available!') elif course_status == 'Course does not exist!': return render_template('error.html', message=course_status) student_name = results['name'] student_surname = results['surname'] student_email = results['email'] student = Student(student_name, student_surname, student_email) # gets the course from courses if the course exists, otherwise returns None existing_course = next( (course for course in courses if course == new_course), None) try: if existing_course is not None: add_student_to_course(existing_course, student) else: num_courses_in_db = get_number_of_courses() # Checks if the db and list is synchronized if len(courses) == num_courses_in_db: courses.append(new_course) add_student_to_course(new_course, student) else: courses = get_courses() existing_course = next( (course for course in courses if course == new_course), None) if existing_course is not None: add_student_to_course(existing_course, student) else: courses.append(new_course) add_student_to_course(new_course, student) except StudentExistsException: return render_template( 'error.html', message='A student with this email address exists.') except Exception as e: logging.error('Registration error', exc_info=True) return render_template( 'error.html', message= 'An error occurred during registration. Please try again.') return render_template('result.html') return render_template('seat_checker.html', form=form)
def class_edit_page(crn, semester): if session.get('logged_in') is None: flash("You are not logged in", "danger") return redirect(url_for("login_page")) if request.method == "GET": instructorIDs = [] for instructor_info in database.get_class_instructors(crn, semester): instructorIDs.append(instructor_info[0]) aclass = database.get_whole_class(crn, semester) instructors = database.get_instructors() courses = database.get_courses() mapped_values = { 'crn': crn, 'semester': semester, 'courseCode': aclass[2], 'instructors': instructorIDs, 'vfGrade': aclass[5], 'passGrade': aclass[4], 'quota': aclass[6], 'enrolled': aclass[7], 'syllabus': "" } for key in mapped_values.keys(): if mapped_values[key] is None: mapped_values[key] = "" return render_template("class_edit.html", year=year_dec, courses=courses, instructors=instructors, zip=zip, values=mapped_values) elif request.method == "POST": form_crn = request.form["crn"] form_semester = request.form["year"] print(form_semester) form_semester += request.form["season"] print(form_semester) form_courseCode = request.form["courseCode"] form_instructorIDs = request.form.getlist("instructors[]") form_passGrade = request.form["passGrade"] form_vfGrade = request.form["vfGrade"] form_quota = request.form["quota"] form_enrolled = request.form["enrolled"] form_syllabus = request.files['syllabus'] if form_passGrade == "": form_passGrade = None if form_vfGrade == "": form_vfGrade = None if form_quota == "": form_quota = None if form_enrolled == "": form_enrolled = None instructorIDs = [] for instructor_info in database.get_class_instructors(crn, semester): instructorIDs.append(instructor_info[0]) filename = form_syllabus.filename file_ext = os.path.splitext(filename)[1] aclass = database.get_whole_class(crn, semester) blob_data = aclass[8] if (filename != ""): if file_ext not in current_app.config['UPLOAD_EXTENSIONS']: flash("Syllabus file type can only be pdf", "danger") return redirect( url_for("class_edit_page", crn=crn, semester=semester)) else: blob_data = form_syllabus.read() if database.update_class(crn, semester, form_crn, form_semester, form_courseCode, form_passGrade, form_vfGrade, form_quota, form_enrolled, blob_data) is True: for form_instructorID in form_instructorIDs: removed = False for instructorID in instructorIDs: if form_instructorID == str(instructorID): instructorIDs.remove(instructorID) removed = True break if removed is False: if database.add_instructs(form_crn, form_semester, form_instructorID) is False: flash( "Instructor " + str(form_instructorID) + " is already assigned to this class.", "danger") for instructorID in instructorIDs: database.remove_instructs(form_crn, form_semester, instructorID) flash("Class with CRN " + form_crn + " has been updated.", "success") return redirect( url_for("class_page", crn=form_crn, semester=form_semester)) else: flash("Class with CRN " + str(crn) + " could not be updated.", "danger") return redirect( url_for("class_edit_page", crn=crn, semester=semester))
def class_addition_page(): if session.get('logged_in') is None: flash("You are not logged in", "danger") return redirect(url_for("login_page")) if request.method == "GET": values = { 'crn': "", 'semester': "", 'courseCode': "", 'instructors': [], 'vfGrade': "", 'passGrade': "", 'quota': "", 'enrolled': "", 'syllabus': "" } instructors = database.get_instructors() courses = database.get_courses() return render_template("class_edit.html", year=year_dec, courses=courses, instructors=instructors, zip=zip, values=values) elif request.method == "POST": form_crn = request.form["crn"] form_semester = request.form["year"] form_semester += request.form["season"] form_courseCode = request.form["courseCode"] form_instructorIDs = request.form.getlist("instructors[]") form_passGrade = request.form["passGrade"] form_vfGrade = request.form["vfGrade"] form_quota = request.form["quota"] form_enrolled = request.form["enrolled"] form_syllabus = request.files['syllabus'] if form_passGrade == "": form_passGrade = None if form_vfGrade == "": form_vfGrade = None if form_quota == "": form_quota = None if form_enrolled == "": form_enrolled = None filename = form_syllabus.filename file_ext = os.path.splitext(filename)[1] blob_data = None if (filename != ""): if file_ext not in current_app.config['UPLOAD_EXTENSIONS']: flash("Syllabus file type can only be pdf", "danger") return redirect(url_for("class_addition_page")) else: blob_data = form_syllabus.read() if database.add_class(form_crn, form_semester, form_courseCode, form_passGrade, form_vfGrade, form_quota, form_enrolled, blob_data) is True: for form_instructorID in form_instructorIDs: if database.add_instructs(form_crn, form_semester, form_instructorID) is False: flash( "Instructor " + str(form_instructorID) + " is already assigned to this class.", "danger") flash("Class with CRN " + form_crn + " has been added.", "success") return redirect(url_for("classes_page", semester=form_semester)) else: flash("Class already exists.", "danger") return redirect(url_for("class_addition_page"))