def create_classes(): try: print('创建班级'.center(60, '-')) course_list = Course.get_all_obj_list() for k, obj in enumerate(course_list): print(k, obj, obj.name) sid = int(input('请选择课程:')) course_obj = course_list[sid] name = input('请输入班级名:').strip() tuition = input('请输入学费:').strip() classes_name_list = [obj.name for obj in Classes.get_all_obj_list()] if name in classes_name_list: raise Exception('\033[43;1m班级[%s] 已存在,不可重复创建\033[0m' % name) obj = Classes(name, tuition, course_obj.nid) obj.save() status = True error = '' data = '\033[33;1m班级[%s] 学费[%s] 创建成功\033[0m' % (obj.name, obj.tuition) except Exception as e: status = False error = str(e) data = '' return {'status': status, 'error': error, 'data': data}
def addclass(studentcount,techniquecount): sarray = [] tarray = [] for i in range(1,studentcount+1): sarray.append(i) for i in range(1, techniquecount+1): tarray.append(i) techs = Techniques.query.all() membs = Members.query.all() if request.method == 'POST': classdate = request.form['classdate'] newclass = Classes(date=classdate) db.session.add(newclass) db.session.commit() for i in range(1, studentcount + 1): membername = request.form[str(i)] newinteresct = ClassesMember(class_id = newclass.id, member_id = Members.query. filter_by(name=membername).first().id) db.session.add(newinteresct) db.session.commit() for i in range(1, techniquecount + 1): techniquename = request.form[str(i)+"a"] newinteresct = ClassesTechnique(class_id = newclass.id, technique_id = Techniques.query. filter_by(name=techniquename).first().id) db.session.add(newinteresct) db.session.commit() return redirect('/viewclass/0/0') return render_template('addclass.html', studentcount=sarray,techniquecount=tarray,techniques=techs, students=membs)
def teacher_dashboard(): class_obj = Classes.query.filter_by( professor_id=current_user.user_id) class_list = [] for c in class_obj: class_info = (c.get_id(), c.get_name(), c.get_section()) class_list.append(class_info) if request.method == 'POST': # if add_class is clicked # get class name and section, generate registration code, and add a new class to database, redirect if 'add_class' in request.form: # generate random registration code registration_code = get_code() # add class to database new_class = Classes( name=request.form['class_name'], section=request.form['class_section'], enrollment_code=registration_code, professor_id=current_user.user_id ) db.session.add(new_class) db.session.commit() class_added = Classes.query.filter_by( professor_id=current_user.user_id, name=new_class.name, section=new_class.section).first() class_id = class_added.get_id() return redirect(url_for('auth.teacher_class_page', id=class_id)) else: class_id = request.form[class_id] return redirect(url_for('auth.teacher_class_page', id=class_id)) return render_template('teacher_dashboard.html', title='Teacher Dashboard', class_list=class_list)
def create_class(): """ Create a class """ data = request.get_json() new_id = uuid4() new_class = Classes(id=new_id, name=data['name']) db.session.add(new_class) db.session.commit() return jsonify({ 'message': 'New Class created!', 'id': new_id })
def post_class(payload): try: data = request.get_json() name = data['class_name'] address = data['address'] inst = data['instructor'] new_class = Classes(class_name=name, address=address, instructor=inst) new_class.insert() except Exception: abort(400) return jsonify({'success': True, 'classes': new_class.format()})
def test_get_timetable_class_id_and_accepted(self): """ Test for get Timetable with class id and accepted""" resp_register = self.register_user(self, '*****@*****.**', '123456') a_class = Classes(name="Default test class", ) a_class.insert() some_class = Classes.query.filter( Classes.name == "Default test class").first() user = User.query.filter(User.email == '*****@*****.**').first() response1 = self.client().post('/login', json={ "email": '*****@*****.**', "password": '******' }, content_type='application/json') response3 = self.client().post( '/timetable', headers=dict( Authorization='Bearer' + json.loads(resp_register.data.decode())['auth_token']), json={ "name": 'Mathematics Trigonometry', "time": '2020-06-17 15:00', "teacher_id": user.id, "class_id": some_class.id, "link": 'somezoomlink.com' }, content_type='application/json') print(json.loads(response3.data.decode())) response4 = self.client().put( '/timetable/accept', headers=dict( Authorization='Bearer' + json.loads(resp_register.data.decode())['auth_token']), json={ "teacher_id": user.id, "id": json.loads(response3.data.decode())['id'], }, ) response = self.client().get( '/timetable?class_id={}&accepted={}'.format(some_class.id, True), headers=dict( Authorization='Bearer' + json.loads(resp_register.data.decode())['auth_token']), content_type='application/json') data = json.loads(response.data.decode()) self.assertTrue(data['status'] == 'success') self.assertTrue(len(data['data']) >= 1) self.assertEqual(response.status_code, 200)
def create_class(payload): name = request.get_json()['name'] start_time = request.get_json()['start_time'] teacher_id = request.get_json()['teacher_id'] course_id = request.get_json()['course_id'] try: claass = Classes(name=name, start_time=start_time, teacher_id=teacher_id, course_id=course_id) claass.insert() return jsonify({"success": True, "Courses": claass.format()}) except BaseException: abort(422)
def add_class(): data = request.json education_id = data.get('education_id', None) sub_category_id = data.get('sub_category_id', None) if ((data.get('name', '') == '')): abort(422) try: classes = Classes(name=data.get('name')) classes.rank = data.get('rank') if education_id or sub_category_id: if education_id: classes.education_id = int(data.get('education_id')) if sub_category_id: classes.sub_category_id = int(data.get('sub_category_id')) else: abort(422) except Exception: abort(422) classes.insert() return jsonify({'message': 'success', 'id': classes.id})
def test_add_timetable(self): """ Test for Add Timetable""" resp_register = self.register_user(self, '*****@*****.**', '123456') a_class = Classes(name="Default test class", ) a_class.insert() user = User.query.filter(User.email == '*****@*****.**').first() response = self.client().post( '/timetable', headers=dict( Authorization='Bearer' + json.loads(resp_register.data.decode())['auth_token']), json={ "name": 'Mathematics Trigonometry', "time": '2020-06-17 15:00', "teacher_id": user.id, "class_id": a_class.id, "link": 'somezoomlink.com' }, content_type='application/json') data = json.loads(response.data.decode()) print(data) self.assertTrue(data['status'] == 'success') self.assertEqual(response.status_code, 200)
def create_classes(): school_list = School.get_obj_list() # 所有学校列表 for k, obj in enumerate(school_list): print(k, '学校:[%s] 地址:[%s]' % (obj.name, obj.addr)) choose = input('选择学校 >> ').strip() if choose.isdigit(): choose = int(choose) if choose < len(School.get_obj_list()): choose_school = school_list[choose] # 选择的学校 name = input('请输入班级名字 >> ') classes_list = [obj.name for obj in Classes.get_obj_list()] if name in classes_list: print('\033[31;1m班级[%s] 已存在\033[0m' % name) else: course_teacher_list = Course_teacher.get_obj_list() for j, ct in enumerate(course_teacher_list): print(j, ct.course_id.get_obj_uuid().name, ct.teacher_id.get_obj_uuid().name) choose_course_teacher = input('选择关联的课程讲师 >> ').strip() choose_ct_id = course_teacher_list[int(choose_course_teacher)] classes = Classes(name, choose_school.nid, choose_ct_id.nid) classes.save() print('\033[32;1m班级[%s] 创建成功\033[0m' % name)