def add_course(): number = request.form.get("number") name = request.form.get("name") time = request.form.get("time") semester = request.form.get("semester") credit = request.form.get("credit") location = request.form.get("location") teacher = request.form.get("teacher") #Add the course to the database #first check if the course isn't already in the system #If teacher id is specified, check if the teacher is registered in the system if number and name and time and semester and credit and location: course = Course.query.filter_by(coursenumber = number).first() if course: flash('The course is already in the system', 'danger') return redirect(url_for('add_course')) if teacher is not '': instructor = User.query.filter_by(user_id = teacher).first() instructor_role = 'teacher' if instructor and instructor.role == instructor_role: course = Course(coursenumber=number, coursename=name, time=time, semester=semester, credit=credit, location=location, teacher_id=teacher) # take care if there is a course with same time at same location c_with_sl_at_st = Course.query.filter(and_(Course.location == location, Course.time == time)).first() if c_with_sl_at_st: flash('There is a course with same time and location registered before!', 'danger') return redirect(url_for('add_course')) else: db.session.add(course) db.session.commit() flash('The course has been successfully added', 'success') else: flash('The Teacher is not registered in the system', 'danger') return redirect(url_for('add_course')) else: course = Course(coursenumber=number, coursename=name, time=time, semester=semester, credit=credit, location=location, teacher_id=None) # take care if there is a course with same time at same location c_with_sl_at_st = Course.query.filter(and_(Course.location == location, Course.time == time)).first() if c_with_sl_at_st: flash('There is a course with same time and location registered before!', 'danger') return redirect(url_for('add_course')) else: db.session.add(course) db.session.commit() flash('The course has been successfully added', 'success') return render_template('/admin/add_course.html')
def signup(): form = SignupForm() if form.validate_on_submit(): user = User.create(form.username.data, form.password.data, 'student') student = Student(user=user.key, name=form.name.data, email_address=form.email_address.data, dob=datetime.datetime.strptime( form.dob.data, '%Y-%m-%d'), status=form.status.data, gender=form.gender.data, year=int(form.year.data)) student_courses = models.StudentCourse.query().filter( models.StudentCourse.email_address == form.email_address.data).get() if student_courses is not None: for course in student_courses.courses: thing = Course.query().filter(Course.code == course).get().key student.courses.append( Class.query().filter(Class.course == thing).get().key) student.put() return redirect(url_for('login')) return render_template('signup.haml', form=form, email_address=request.args.get('email_address'))
def _fixtures_courses(): for i in _courseData: Course( courseID=i["courseID"], title=i["title"], description=i["description"], credits=i["credits"], term=i["term"], ).save()
def courses(term=None): if not term: term = 'Spring 2019' classes = Course.objects().order_by('courseID') return render_template("courses.html", course_data=classes, courses=True, term=term)
def assign_lecturer(): if request.method == 'POST': lecturer_key = ndb.Key(urlsafe=request.form['lecturer_key']) course_key = ndb.Key(urlsafe=request.form['course_key']) class_ = Class(course=course_key, lecturer=lecturer_key) class_.put() return redirect(url_for('assign_lecturer')) return render_template('assign_lecturer.haml', lecturers=Lecturer.query(), courses=Course.query())
def get(self, page=1): """ Lists all courses. Must be logged in. """ per_page = api.app.config['COURSE_PAGE_SIZE'] if g.user is None: model_fields = public_course_page_fields paginated_courses = Course.objects(published=True).paginate( page, per_page) pages = mongo_paginate_to_dict(paginated_courses, 'courses') else: model_fields = course_page_fields courses = g.user.all_accessible_courses() paginated_courses = paginate_iterable(courses, page, per_page) pages = custom_paginate_to_dict(paginated_courses, "courses", page, len(courses), per_page, True) return marshal(pages, model_fields)
def post(self, page=1): """ Creates a new course, current user is set as supervisor. aborts with code 403 if current user is a Student. """ arguments = course_parser.parse_args() name = arguments['name'] description = arguments.get('description', '') course = Course(name=name, description=description, supervisor=g.user) course.teachers.append(g.user) if arguments['published'] == 'True': course.published = True elif arguments['published'] == 'False': course.published = False else: abort(400, message="published field must be True or False as a string.") try: course.save() return marshal(course.to_dict(), course_fields), 201 except db.NotUniqueError: abort(422, message='Course name already in use.')
def populate(): import datetime admin = User.create('admin', 'password', 'admin') admin.put() principal_user = User.create('principal', 'password', 'lecturer') principal = Lecturer(name='Principal', title='Dr', user=principal_user.key) principal.put() school = School(name='University of The West Indies - Mona', principal=principal.key) school.put() hof_user1 = User.create('hof1', 'password', 'lecturer') hof_user2 = User.create('hof2', 'password', 'lecturer') hof1 = Lecturer(name='Head Of Pure and Applied', title='Dr', user=hof_user1.key) hof2 = Lecturer(name='Head Of Medical Sciences', title='Dr', user=hof_user2.key) hof1.put() hof2.put() faculty1 = Faculty(name='Pure and Applied Science', school=school.key, head_of_faculty=hof1.key) faculty2 = Faculty(name='Medical Sciences', school=school.key, head_of_faculty=hof2.key) faculty1.put() faculty2.put() hod_user1 = User.create('hod1', 'password', 'lecturer') hod_user2 = User.create('hod2', 'password', 'lecturer') hod_user3 = User.create('hod3', 'password', 'lecturer') hod_user4 = User.create('hod4', 'password', 'lecturer') hod1 = Lecturer(name='Head Of Computing', title='Dr', user=hod_user1.key) hod2 = Lecturer(name='Head Of Mathematics', title='Dr', user=hod_user2.key) hod3 = Lecturer(name='Head Of Medicine', title='Dr', user=hod_user3.key) hod4 = Lecturer(name='Head Of Microbiology', title='Dr', user=hod_user4.key) hod1.put() hod2.put() hod3.put() hod4.put() department1 = Department(name='Computing', faculty=faculty1.key, head_of_department=hod1.key) department2 = Department(name='Mathematics', faculty=faculty1.key, head_of_department=hod2.key) department3 = Department(name='Medicine', faculty=faculty2.key, head_of_department=hod3.key) department4 = Department(name='Microbiology', faculty=faculty2.key, head_of_department=hod4.key) department1.put() department2.put() department3.put() department4.put() principal.department = department4.key hof1.department = department2.key hof2.department = department3.key hod1.department = department1.key hod2.department = department2.key hod3.department = department3.key hod4.department = department4.key principal.put() hof1.put() hof2.put() hod1.put() hod2.put() hod3.put() hod4.put() student_user = User.create('student', 'password', 'student') student = Student(name='Kevin Leyow', email_address='*****@*****.**', user=student_user.key, dob=datetime.date(year=1992, month=4, day=12), year=3, status='FT', gender='M') lecturer_user = User.create('lecturer', 'password', 'lecturer') lecturer = Lecturer(name='Jimmy', title='Dr', user=lecturer_user.key, department=department1.key) course = Course(name='Database Management Systems', code='COMP3161', total_students=90, department=department1.key, faculty=faculty1.key) course2 = Course(name='Theory Of Computation', code='COMP3702', total_students=20, department=department1.key, faculty=faculty1.key) ndb.put_multi([lecturer, course]) ndb.put_multi([lecturer, course2]) class_ = Class(course=course.key, lecturer=lecturer.key) class2_ = Class(course=course2.key, lecturer=lecturer.key) class_.put() class2_.put() student.courses = [class_.key, class2_.key] lecturer.courses = [class_.key, class2_.key] ndb.put_multi([student, lecturer]) survey = Survey(title='General survey', description='A general survey') survey_key = survey.put() with open('application/questions.txt') as f: questions = [] for number, line in enumerate(f.readlines()): question_type, dimension, question = line.split('|') questions.append( Question(question_type=question_type, dimension=dimension, question=question, is_active=True, number=number + 1, parent=survey_key)) ndb.put_multi(questions) return 'Done.'
if data['student']: new_student = Student(user_id=data['id']) student_insert = db.session.add(new_student) student_update = student_insert.on_conflict_do_nothing( index_elements=['user_id']) # Creates a new mentor object if the user is a mentor if data['mentor']: new_mentor = Mentor(user_id=data['id'], is_admin=False) # Defaults to admin False mentor_insert = db.session.add(new_student) mentor_update = mentor_insert.on_conflict_do_nothing( index_elements=['user_id']) # Loops through all courses for the user for course_id, course in data['courses'].items(): # Checks whether it exists in courses and creates a new row if it doesn't if course_id not in courses: new_course = Course(id=course_id, course_name=course) db.session.add(new_course) # Creates a row for the association between users and courses user_course = UserCourse(user_id=id, course_id=course) user_course_insert = db.session.add(user_course) user_course_update = user_course_insert.on_conflict_do_nothing( index_elements=['user_id', 'course_id']) # Commits all the changes db.session.commit()
def api(idx=None): if idx is None: jdata = Course.objects.order_by('course_id') else: jdata = Course.objects(course_id=idx) return Response(json.dumps(jdata), mimetype='application/json')
def get(self): if isinstance(g.user, Student): courses = Course.objects(students=g.user) else: courses = Course.objects(teachers=g.user) return [course.to_dict() for course in courses]
def handle(self, *args, **options): course_data = [ [1, 'MATH', '1190', 'Calculus I', 'Summer', '2018', 'A'], [ 2, 'CSE', '1322', 'Programming and Problem Solving', 'Fall', '2018', 'B' ], [ 3, 'CSE', '1322L', 'Programming and Problem Solving Lab', 'Fall', '2018', 'C' ], [4, 'CS', '3305', 'Data Structures', 'Spring', '2019', 'A'], [ 5, 'CS', '3503', 'Computer Organization and Architecture', 'Spring', '2019', 'B' ], [6, 'MATH', '2202', 'Calculus II', 'Spring', '2019', 'C'], [7, 'MATH', '2345', 'Discrete Mathematics', 'Fall', '2018', 'A'], [ 8, 'CS', '3410', 'Introduction to Database Systems', 'Spring', '2020', 'B' ], [ 9, 'SWE', '3313', 'Introduction to Software Engineering', 'Spring', '2020', 'C' ], [ 10, 'CSE', '3801', 'Professional Practices and Ethics', 'Spring', '2020', 'A' ], [11, 'CS', '3502', 'Operating Systems', 'Fall', '2020', 'B'], [12, 'CS', '4720', 'Internet Programming', 'Fall', '2020', 'C'], ] for ad in course_data: a = Course(course_id=ad[0], department=ad[1], course_number=ad[2], course_name=ad[3], semester=ad[4], year=ad[5], grade=ad[6]) a.save() prereq_data = [ [1, 0, 0], [2, 0, 0], [3, 0, 0], [4, 2, 3], [5, 2, 3], [6, 1, 0], [7, 0, 0], [8, 2, 3], [9, 2, 3], [10, 2, 3], [11, 4, 5], [12, 4, 8], ] for pr in prereq_data: loc = PreRequisite(course_id=pr[0], prereq1=pr[1], prereq2=pr[2]) loc.save()
from application import db from application.models import Course c1 = Course(course_id = 1111, title = 'Learn Python', description = 'Basic understading of Python programming', credits=8, term='programming',link="https://www.python.org/doc/") c2 = Course(course_id = 5697, title = 'Learn Go', description = 'Basic understading of go programming', credits=8, term='programming',link="https://golang.org/doc/") c3 = Course(course_id = 1542, title = 'Learn Flask', description = 'Basic understading of go framework', credits=8, term='framework',link="https://flask.palletsprojects.com/en/1.1.x/quickstart/") c4 = Course(course_id = 8963, title = 'Learn Posgresql', description = 'Basic Queres of psql database', credits=8, term='database',link="https://www.tutorialspoint.com/postgresql/index.htm") db.session.add(c1) db.session.add(c2) db.session.add(c3) db.session.add(c4) db.session.commit()