def test_Children_number_add(self): sch = School(school_name="_name1", classes_number=100) sch.save() twz = Classes(class_name="WeizhongTu", children_number=100,schoolkey=sch) twz.save() c = Classes.objects.get(pk=1) old_number = c.children_number children = Children() children.Classeskey = c children.Parents_id = 1 children.nicename = "1" children.save() self.assertEqual(children.Classeskey.children_number, 101) children.delete() self.assertEqual(children.Classeskey.children_number, 100) #编辑 children = Children.objects.get(pk=1) children.Classeskey = c children.Parents_id = 1 children.nicename = "2" children.save() self.assertEqual(children.Classeskey.children_number, 100)
def Ntest_add_Children_10000(self): sch = School(school_name="_name1", classes_number=100) sch.save() for i in range(0,9999): twz = Classes(class_name="WeizhongTu", children_number=i,schoolkey=sch) twz.save()
def Ntest_apply(TransactionTestCase): sch = School(school_name="_name1", classes_number=100,mobile="13321663321") sch.save() twz = Classes(class_name="WeizhongTu", children_number=i,schoolkey=sch) twz.save() twz = Children(nicename="nicenamech", children_number=i,schoolkey=sch) twz.save()
def test_school_should_not_be_visible_if_logged_out(self): school = School() school.name = 'hogwarts' db.session.add(school) db.session.commit() response = self.client.get(url_for('main.school', id=school.id), follow_redirects=True) self.assertTrue(re.search(b'Login', response.data))
def schools(school_creat): sch_number = [ int(sch_number) for sch_number in school_creat.col_values(0) ] sch_name = [sch_name for sch_name in school_creat.col_values(1)] sch_principal = [ sch_principal for sch_principal in school_creat.col_values(2) ] school_list = zip(sch_number, sch_name, sch_principal) for school in school_list: School.create_sch(*school)
def deploy(): """部署服务器 初始化数据库""" from flask_migrate import upgrade from app.models import Role # migrate database to latest revision upgrade() # create user roles Role.insert_roles() School.insert_school_structure()
def deploy(): """应用程序的初始化配置,主要是数据库基础数据配置""" from flask_migrate import upgrade from app.models import School, Permission, Role, User # db.drop_all() # db.create_all() upgrade() School.insert_basic_schools() Permission.insert_basic_permission() Role.insert_basic_roles() User.insert_admin_user() return '配置成功'
def fake_school(self): """ 获得一个伪造的学校 :return: 伪造的学校 """ school_name = "逗比中学" school_address = "逗比路" try: school = School.objects.get(name=school_name) except School.DoesNotExist: school = School(name=school_name, address=school_address, region=Region.objects.get(name="其他"), center=True, longitude=0, latitude=0, opened=False) school.save() return school
def get_dtl(self): result = super(Exam, self).to_dict() result = Region.bind_auto(result, 'name', 'city_id', 'id', 'city') result = Region.bind_auto(result, 'name', 'province_id', 'id', 'province') result = Region.bind_auto(result, 'name', 'area_id', 'id', 'area') result = School.bind_auto(result, 'name', 'school_id', 'id', 'school') return result
def get_fast(): exam_query = Exam.query.filter(Exam.state == EXAM_STATUS['未审核'], Exam.is_fast==1).\ order_by(Exam.order.desc()).\ order_by(Exam.created_at.desc()) if request.args.get('name'): exam_query = exam_query.filter( Exam.name.like('%{}%'.format(request.args.get('name')))) if request.args.get('subject'): exam_query = exam_query.filter( Exam.subject == request.args.get('subject')) if request.args.get('paper_types'): exam_query = exam_query.filter( Exam.paper_types == request.args.get('paper_types')) if request.args.get('province_id'): exam_query = exam_query.filter( Exam.province_id == request.args.get('province_id')) if request.args.get('city_id'): exam_query = exam_query.filter( Exam.city_id == request.args.get('city_id')) if request.args.get('area_id'): exam_query = exam_query.filter( Exam.area_id == request.args.get('area_id')) if request.args.get('school_id'): exam_query = exam_query.filter( Exam.school_id == request.args.get('school_id')) if request.args.get('year'): exam_query = exam_query.filter(Exam.year == request.args.get('year')) if request.args.get('grade'): exam_query = exam_query.filter(Exam.grade == request.args.get('grade')) res = pagination(exam_query) items = res.get('items', []) items = School.bind_auto(items, 'name') res['items'] = items return render_api(res)
def school(): ctid = request.args.get('ctid') title = request.args.get('title', '') if not ctid: raise JsonOutputException('need ctid') schools = School.get_schools_by_ctid(ctid, title) return {'code': 0, 'data': schools}
def testSchool(self): db.create_all() school = School(name="Duquesne University", location="Pittsburgh, Pennsylvania", gpa=3.24, act=24, sat=1350, grad_rate=78, avg_salary=50000, grad_time=4, school_size=10000) db.session.add(school) db.session.commit()
def SchoolFactory(data): # if the school is not secondary, skip it if 'mainlevel_code' in data and data[ 'mainlevel_code'] != 'SECONDARY' and data[ 'mainlevel_code'] != 'MIXED LEVEL': return OtherSchool(**data) else: return School(**data)
def initialize_table(): if School.query.first() is None: with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), "app\static\schools.json"), "r") as read_file: school_data = json.load(read_file) for s in school_data: if type(s['scale']) is not list: school = School(name=s['name'], scale=s['scale']) db.session.add(school) db.session.commit() else: scale = s['scale'][0] * 10 + s['scale'][1] school = School(name=s['name'], scale=scale) db.session.add(school) db.session.commit() Grade.query.delete() db.session.commit()
def test_department_in_school(self): s = School(name='tsxy') db.session.add(s) db.session.commit() d = Department(name='cs') d.school = s db.session.add(d) db.session.commit() self.assertTrue(d in s.departments)
def test_teacher_is_employ_and_dissmiss(self): t = Teacher(telephone='13700000000') s = School(name='aschool') t.schools.append(s) db.session.add_all([t, s]) db.session.commit() self.assertTrue(t.is_employ(s.id)) t.dismiss_school(s.id) self.assertFalse(t.is_employ(s.id))
def test_teacher_is_school_admin(self): t = Teacher(telephone='13700000001') s = School(name='aschool', admin='13700000001') db.session.add_all([t, s]) db.session.commit() self.assertFalse(t.is_teacher_admin(s.id)) t.schools.append(s) db.session.commit() self.assertTrue(t.is_teacher_admin(s.id))
def add_school(): form = SchoolForm() if form.validate_on_submit(): db.session.add(School(name=form.name.data)) flash('школа {} создана'.format(form.name.data)) return redirect(url_for('.schools_list')) return render_template('structure/form_add_edit.html', form=form, class_name='школы', creating=True)
def make_schools(): schools = [ "University of California, Los Angeles", "University of Maryland, College Park", "University of Pennsylvania" ] for school in schools: s = School(name=school) db.session.add(s) db.session.commit()
def test_student_join_school(self): sc = School(name='aschool') st = Student(nickname='astudent') db.session.add_all([sc, st]) db.session.commit() co = Course(course_name='acourse', school_id=sc.id) db.session.add(co) db.session.commit() st.join_school(sc.id) self.assertTrue(st.is_school_joined(sc.id))
def test_teacher_bind_school(self): t = Teacher(telephone='13700000000') s = School(name='aschool') db.session.add_all([t, s]) db.session.commit() Tcode.generate_code(10, s.id) tcode = Tcode.query.all()[0].code t.bind_school(tcode) self.assertTrue(t.schools[0].id == s.id) self.assertTrue(Tcode.query.filter_by(code=tcode).first() is None)
def test_generate_tcode(self): s = School(name='aschool') db.session.add(s) db.session.commit() Tcode.generate_code(10, s.id) self.assertTrue(s.tcodes.count() == 10) try: Tcode.generate_code(10, s.id) except Exception as e: print("是的,拒绝生成新邀请码") self.assertTrue(s.tcodes.count() == 10)
def test_stats(self, client, db): ni_schools = [School(id=f"NI-{i}") for i in range(10)] be_schools = [School(id="BE-1")] for school in ni_schools + be_schools: db.add(school) db.commit() response = client.get("/stats") assert response.status_code == 200 assert response.json() == [ { "state": "BE", "count": 1 }, { "state": "NI", "count": 10 }, ]
def school_create(): form = SchoolFormCreate() if form.validate_on_submit(): school = School( name=form.name.data, description=form.description.data ) db.session.add(school) db.session.commit() flash('Created and Saved Successfully.', 'alert-success') return redirect(url_for('school_view', id=school.id)) return render_template('basic-forms/school/create.html', title='School Create', form=form)
def get_exam(id): result = Exam.query.get(int(id)) if result is not None: result = result.to_dict() else: return None result = Region.bind_auto(result, 'name', 'city_id', 'id', 'city') result = Region.bind_auto(result, 'name', 'province_id', 'id', 'province') result = Region.bind_auto(result, 'name', 'area_id', 'id', 'area') result = School.bind_auto(result, 'name', 'school_id', 'id', 'school') return result
def schoolreg_step1(request): error = [] logging.debug(error) if request.method == 'POST': # 如果表单被提交 form = SchoolRegForm(request.POST) # 获取Post表单数据 if form.is_valid(): # 验证表单 school = School() school.mobile = form.cleaned_data['mobile'] school.school_name = form.cleaned_data['school_name'] school.password = form.cleaned_data['password'] school.save() classes = Classes() classes.class_name = school.school_name + u'1班' classes.schoolkey_id = school.pk classes.save() request.session["school"] = school.id return HttpResponseRedirect('/schoolreg_step2') # 跳转 else: form = SchoolRegForm() #获得表单对象 return render_to_response('reg/schoolreg_step1.html', { 'form': form,'error':error },context_instance=RequestContext(request))
def schools(): ''' GET: Returns all schools. POST: Creates an school. ''' if request.method == 'POST': json = request.get_json() school = School.create_or_get(json) return jsonify(school.json), status.HTTP_201_CREATED schools = School.query.all() return jsonify({'schools': unpack_json(schools)}), status.HTTP_200_OK
def test_add_teacher(self): s = School(name="Test") u = User(username="******") with self.assertRaises(ValidationError): s.add_teacher(u) u.role = Role.get('Teacher') s.add_teacher(u) db.session.add(s) db.session.commit() self.assertEquals([u], s.teachers.all())
def register(): # get the post data payload = request.get_json() email = payload.get('email').lower().strip() # check if user already exists user = User.query.filter_by(email=email).first() if not user: try: with open('resources/email_blacklist.txt') as f: # TODO: should we just keep this in memory continuously rather than reading it every time? email_blacklist = f.read().split('\n') if email in email_blacklist: return fail( 'Sorry, a student email address is required to register.', 401) school = School.from_email(email) if school is None: # TODO: use non-Yale-specific message. return fail( 'You must use a valid .edu email address from a supported school.', 401) user = User( name=payload['name'].strip(), email=email, year=payload['year'], password=payload['password'], confirmed=False, school_id=school.id, ) # Insert the user db.session.add(user) db.session.commit() send_confirmation_email(user) return succ( 'Check your inbox at ' + email + ' to confirm! (The email may take a few moments to deliver.)', 201) except Exception as e: return fail( 'Some error occurred. Please try again. Contact the developers if this continues to happen.', 500) else: return fail('User already exists. Please log in.', 202)
def test_students_only_returns_students(self): s = School(name="Test") u1 = User(username="******", email='*****@*****.**') u2 = User(username="******", email='*****@*****.**') u3 = User(username="******", email='*****@*****.**') u3.role = Role.get('Teacher') u4 = User(username="******", email='*****@*****.**') u4.role = Role.get('Teacher') s.add_student(u1) s.add_student(u2) s.add_teacher(u3) s.add_teacher(u4) db.session.add(s) db.session.commit() self.assertListEqual([u1, u2], s.students.all())
def add_or_get(db, name): if name in Schools: x = School.query.filter_by(name=name) else: x = Course.query.filter_by(name=name) if len(list(x)) == 0: if name in Schools: temp = School(name=name) else: temp = Course(name=name) db.session.add(temp) x = temp else: try: assert (len(list(x)) == 1) except Exception: raise Exception( 'Something has gone horribly wrong with the database, an admin has been emailed' ) x = x[0] return x
def list_quest_review_log(): query = Preprocess.query.\ filter_by(operator_id=g.user.id).\ order_by(Preprocess.created_at.desc()).\ join(Exam, Exam.id==Preprocess.exam_id) if request.args.get('name'): query = query.filter( Exam.name.like('%{}%'.format(request.args.get('name')))) if request.args.get('subject'): query = query.filter(Exam.subject == request.args.get('subject')) if request.args.get('paper_types'): query = query.filter( Exam.paper_types == request.args.get('paper_types')) if request.args.get('province_id'): query = query.filter( Exam.province_id == request.args.get('province_id')) if request.args.get('city_id'): query = query.filter(Exam.city_id == request.args.get('city_id')) if request.args.get('area_id'): query = query.filter(Exam.area_id == request.args.get('area_id')) if request.args.get('school_id'): query = query.filter(Exam.school_id == request.args.get('school_id')) if request.args.get('year'): query = query.filter(Exam.year == request.args.get('year')) if request.args.get('grade'): query = query.filter(Exam.grade == request.args.get('grade')) res = pagination(query) items = res.get('items', []) items = Exam.bind_auto(items, [ 'name', 'section', 'school_id', 'subject', 'grade', 'paper_types', 'province_id', 'city_id', 'area_id' ]) items = School.bind_auto(items, 'name', 'exam_school_id', 'id', 'school') items = Region.bind_auto(items, 'name', 'exam_province_id', 'id', 'province') items = Region.bind_auto(items, 'name', 'exam_city_id', 'id', 'city') items = Region.bind_auto(items, 'name', 'exam_area_id', 'id', 'area') res['items'] = items return render_api(res)
def get_full_school(): return School( id="NW-112586", name="Städt. Gem. Grundschule - Primarstufe -", address="Pfälzer Str. 30-34", city="Köln", email="*****@*****.**", fax="0221355007718", legal_status="in öffentlicher Trägerschaft", phone="022135500770", provider="Stadt Köln", school_type="Grundschule", website="http://www.ggs-pfaelzer-strasse-koeln.de", zip="50677", raw={ "Schulnummer": "112586", "Schulform": "02", "Schulbezeichnung_1": "Städt. Gem. Grundschule", "Schulbezeichnung_2": "- Primarstufe -", "Schulbezeichnung_3": "", "Kurzbezeichnung": "Köln, GG Pfälzer Str.", "PLZ": "50677", "Ort": "Köln", "Strasse": "Pfälzer Str. 30-34", "Telefonvorwahl": "0221", "Telefon": "35500770", "Faxvorwahl": "0221", "Fax": "355007718", "E-Mail": "*****@*****.**", "Homepage": "http://www.ggs-pfaelzer-strasse-koeln.de", "Rechtsform": "1", "Traegernummer": "10182", "Gemeindeschluessel": "05315000", "Schulbetriebsschluessel": "1", "Schulbetriebsdatum": "01.08.1973", "EPSG": "EPSG:25832", "UTMRechtswert": "355389", "UTMHochwert": "5643630", }, )
def get_deal_list(deal_obj): query = db.session.query(distinct(deal_obj.exam_id)).\ filter_by(operator_id=g.user.id) exam_ids = query.all() exam_ids = [id[0] for id in exam_ids] exam_query = Exam.query.filter(Exam.id.in_(exam_ids)).order_by(Exam.created_at.desc()) if request.args.get('name'): exam_query = exam_query.filter(Exam.name.like('%{}%'.format(request.args.get('name')))) if request.args.get('subject'): exam_query = exam_query.filter(Exam.subject==request.args.get('subject')) if request.args.get('paper_types'): exam_query = exam_query.filter(Exam.paper_types==request.args.get('paper_types')) if request.args.get('province_id'): exam_query = exam_query.filter(Exam.province_id==request.args.get('province_id')) if request.args.get('city_id'): exam_query = exam_query.filter(Exam.city_id==request.args.get('city_id')) if request.args.get('area_id'): exam_query = exam_query.filter(Exam.area_id==request.args.get('area_id')) if request.args.get('school_id'): exam_query = exam_query.filter(Exam.school_id==request.args.get('school_id')) if request.args.get('year'): exam_query = exam_query.filter(Exam.year==request.args.get('year')) if request.args.get('grade'): exam_query = exam_query.filter(Exam.grade==request.args.get('grade')) exams = pagination(exam_query) items = [] for item in exams['items']: questions = deal_obj.query.\ filter_by(operator_id=g.user.id).\ filter_by(exam_id=item['id']).\ order_by(deal_obj.quest_no.asc()).\ all() questions = [q.get_question_dtl() for q in questions] item['open'] = False item['questions'] = questions items.append(item) exams['items'] = School.bind_auto(items, 'name') return exams
def Ntest_add_School_1000(self): for i in range(0,10000): sch = School(school_name="_name1%d" % i, classes_number=100) sch.save()