def main(): semester_choices = sorted((semester.code for semester in Semester.all()), reverse=True) arg_parser = ArgumentParser() arg_parser.add_argument('semester', nargs='?', default=Semester.current_semester().code) arg_parser.add_argument('--raw', default=False, action='store_true') args = arg_parser.parse_args() response = update_db(Semester.from_code(args.semester)) if args.raw: with open('response', 'w') as fd: fd.write(response)
def main(): semester_choices = ('any', *sorted((semester.code for semester in Semester.all()), reverse=True)) arg_parser = ArgumentParser() arg_parser.add_argument('terms', metavar='TERM', nargs='*') arg_parser.add_argument('--semester', default=Semester.current_semester().code, choices=semester_choices) arg_parser.add_argument('--sort', choices=('semester', 'number', 'title', 'instructors', 'meetings')) args = arg_parser.parse_args() if args.semester == 'any': offerings = OFFERINGS else: semester = Semester.from_code(args.semester) offerings = filter_by_semester(OFFERINGS, semester.code) search(offerings, ' '.join(args.terms), sort=args.sort)
def day_time_selection(): if request.method == "POST": final_selected = request.form.getlist("selected_course") session_user = session.get("user_id") for item in final_selected: new_record = SelectedCourseInfo.create(faculty_id=session_user, course_id=item) try: with db.atomic(): new_record.save() print(new_record) except Exception as e: flash("Something went wrong.") return redirect(url_for("day_time_selection")) flash("Your selected course has been sent to Moderator for review") return redirect(url_for("faculty_selection")) if request.method == "GET": selected_courses = [] for item in request.args.getlist("selected_courses"): selected_courses.append(Courses.get(id=item)) selected_term = Semester.get(id=request.args['selected_term']) return render_template( "select_days_and_time.html", selected_term=selected_term, selected_courses=selected_courses )
def add_semester_submission(): try: grade_id=request.form['grade_id'] new_semester = Semester( num=request.form['num'], grade_id=grade_id ) Semester.insert(new_semester) flash('Semester ' + request.form['num'] + ' was successfully listed!') except: db.session.rollback() print(sys.exc_info()) flash('An error occurred. Semester ' + request.form['num'] + ' could not be listed.') finally: db.session.close() query = Semester.query.filter_by(grade_id=grade_id).all() return render_template('pages/semesters.html', data=query, userinfo=session['profile'])
def faculty_selection(): if request.method == "POST": form_term = request.form.get("term_id") form_courses = request.form.getlist("course_ids") return redirect(url_for("day_time_selection", selected_term=form_term, selected_courses=form_courses)) courses = Courses.select() semester = Semester.select() return render_template("selection.html", courses=courses, semester=semester)
def get_current_semester(self): query: str = f"SELECT SEMESTER, YEAR FROM SEMESTER WHERE " \ f"SEMESTER = "\ f"(SELECT SEMESTER FROM SEMESTER ORDER BY YEAR DESC, SEMESTER DESC LIMIT 1)" \ f"AND YEAR = (SELECT YEAR FROM SEMESTER ORDER BY YEAR DESC LIMIT 1)" response = self.db_manager.execute_query(query) [semester] = response current_semester = Semester(semester=semester[0], year=semester[1]) if type(response) == Exception: return None else: return current_semester
def semesters(): if request.method == 'POST': data = request.get_json() year = data.get('year') semester = data.get('semester') new_semester = Semester(semester=semester, year=year) is_successful = query_factory.add_semester(new_semester) if is_successful: msg = 'Semester created successfully.' else: msg = 'Semester could not be created.' response = {'is_successful': is_successful, 'message': msg} return jsonify(response) if request.method == 'GET': current_semester = query_factory.get_current_semester() semester = { 'semester': current_semester.semester, 'year': current_semester.year } return jsonify(semester)
def create_semester(nm, y, sm, sd, em, ed): s = Semester(tag = '%s%02d' % (nm[0].lower(), y%100), name = '%s %d' % (nm, y), start_date = date(year=y, month=sm, day=sd), end_date = date(year=y, month=em, day=ed)) s.save()