def get_course(): if session.get("id") is None: return redirect("/user/login") name2 = session.get("name") if request.method=="GET": return render_template('teacher_templates/importcourse.html',name=name2) else: name=request.form.get("name") if name=="" or name is None: return render_template('teacher_templates/importcourse.html', message="title不能为空") course =Course.query.filter_by(courseName=name).filter_by(teacherId=session.get("id")).first() if course: return render_template('teacher_templates/importcourse.html', message="该课程已经存在") with db.auto_commit(): course = Course() course.courseName = name course.teacherId=session.get("id") db.session.add(course) return redirect("/course")
def import_course(filename='', replace=False): print("Filename: {}".format(filename)) print(" Replace: {}".format(replace)) with open(filename) as csvfile: courses = csv.DictReader(csvfile) for row in courses: cid = row['課程編號'].decode("UTF-8") name = row['課程名稱'].decode("UTF-8") description = row['課程敘述'].decode("UTF-8") classroom = row['教室'].decode("UTF-8") price = row['收費價格'].decode("UTF-8") teacher = row['教師'].decode("UTF-8") teacher_tag = row['教師說明'].decode("UTF-8") teacher_phone = row['教師聯絡電話'].decode("UTF-8") grades = row['開課年級'].decode("UTF-8") lowbound = row['下限人數'].decode("UTF-8") upbound = row['上限人數'].decode("UTF-8") datetime = row['上課日期時間'].decode("UTF-8") # lookup first # unique => grade, class, number c = Course.query.filter_by(cid=cid).first() # not exist then add a course if c is None: c = Course( cid=cid, name=name, description=description, classroom=classroom, price=price, teacher=teacher, teacher_tag=teacher_tag, teacher_phone=teacher_phone, grades=grades, lowbound=lowbound, upbound=upbound, datetime=datetime, ) db.session.add(c) else: # exist then update a ticket if replace: c.name = name c.description = description c.classroom = classroom c.price = price c.teacher = teacher c.teacher_tag = teacher_tag c.teacher_phone = teacher_phone c.grades = grades c.lowbound = lowbound c.upbound = upbound c.datetime = datetime c.count = 0 db.session.commit()
def create_course(): form = CourseCreateForm().validate_for_api() with db.auto_commit(): course = Course() form.populate_obj(course) db.session.add(course) Enroll.add_user(course, form.teachers_gid.data, form.students_gid.data, form.TAs_gid.data, db) return Success()
def teacher_create(): form = CourseCreateForm() if form.validate_on_submit(): course = Course() course.name = form.name.data course.grade_level = form.grade_level.data course.price = form.price.data course.teacher = current_user db.session.add(course) db.session.commit() return redirect(url_for('course.teacher_show', id=course.id)) return render_template('views/course/teacher_create.html', title='Create Course', form=form)
def add_course(category_id): try: category = session.query(Category).filter_by(id=category_id).one() except: return error_message( 404, "Cannot add new course to this category: Category not found.") name = request.form.get('name') if name: course = Course(name=name, description=request.form.get('description'), img_url=request.form.get('img-url'), intro_video_url=request.form.get('intro-video-url'), category_id=category.id) session.add(course) session.commit() else: return error_message(400, "Course name is required.") return data_message(200, {"Course": course.serialize}, "Successfully added a course.")
def post(self): """ Creating an Course ad """ course_schema = CourseSchema() course_data = request.get_json() validated_course_data, errors = course_schema.load(course_data) if errors: return dict(status='fail', message=errors), 400 course = Course(**validated_course_data) saved_course = course.save() if not saved_course: return dict(status='fail', message='Internal Server Error'), 500 new_course_data, errors = course_schema.dumps(course) return dict(status='success', data=dict(course=json.loads(new_course_data))), 201
teacher = Teacher() teacher.name = 'Ömer Çulha' teacher.email = '*****@*****.**' teacher.phone = '0000 000 00 00' teacher.generate_password_hash('123456') db.session.add(teacher) student = Student() student.name = 'Yunus Emre' student.email = '*****@*****.**' student.phone = '0000 000 00 00' student.grade_level = 1 student.parent_code = "11111111111" student.generate_password_hash('123456') db.session.add(student) course = Course() course.name = 'Fen Bilgisi' course.grade_level = 1 course.teacher = teacher course.price = "25" db.session.add(course) exam = Exam() exam.name = 'Fen Sınavı' exam.date = date.today() exam.course = course db.session.add(exam) db.session.commit()
# session.rollback() session = DBSession() # CATEGORY: Web Development category1 = Category(name='Web Development') session.add(category1) session.commit() course1 = Course( name='JavaScript: Understanding the Weird Parts', description= 'In this course you will gain a deep understanding of Javascript, ' 'learn how Javascript works under the hood, and how that knowledge ' 'helps you avoid common pitfalls and drastically improve your ability ' 'to debug problems. You will find clarity in the parts that others, ' 'even experienced coders, may find weird, odd, and at times incomprehensible. ' 'You\'ll learn the beauty and deceptive power of this language that is at the ' 'forefront of modern software development today.', img_url='https://udemy-images.udemy.com/course/750x422/364426_2991_5.jpg', intro_video_url='', category_id=category1.id) session.add(course1) session.commit() course2 = Course( name='The Web Developer Bootcamp', description= 'The only course you need to learn web development - HTML, CSS, JS, Node, and More!', img_url='https://udemy-images.udemy.com/course/750x422/625204_436a_2.jpg',