def setUp(self): School.query.delete() Teacher.query.delete() self.client = app.test_client() self.school = School(name='Minnesota') db.session.add(self.school) db.session.commit() self.teacher = Teacher(first_name='Maria', last_name='Aldapa', title='Teacher', school_id=self.school.id, username='******', password='******') self.data = { 'first_name': self.teacher.first_name, 'last_name': self.teacher.last_name, 'title': self.teacher.title, 'school_id': self.teacher.school_id, 'username': self.teacher.username, 'password': self.teacher.password, 'confirm': self.teacher.password }
def get_or_create_school(db, id): school = db.query(School).get(id) if school is None: school = School(id=id) db.add(school) db.commit() return school
def setUp(self): self.school = School(name='Minnesota') db.session.add(self.school) db.session.commit() self.tch = Teacher(first_name='Jess', last_name='Christensen', title='K4-2nd Sped', school_id=self.school.id, username='******', password='******') db.session.add(self.tch) db.session.commit() self.stu = Student(first_name='Fake', last_name='Kid', dob=date(2012, 1, 24), grade=1, teacher_id=self.tch.id, dis_area='OHI') db.session.add(self.stu) db.session.commit() self.iep = IEP(student_id=self.stu.id, teacher_id=self.tch.id) db.session.add(self.iep) db.session.commit()
def read_data(self): with open(SCHOOLS_FILE, encoding='ISO-8859-1') as csvfile: rows_reader = csv.reader(csvfile, delimiter=',') next(rows_reader) schools = [] for row in rows_reader: state = 'DC' if row[5] == 'C' else row[5] school = School(row[0], row[3], row[2], row[4], state, row[8], row[9]) schools.append(school) return schools
def create_school(): name = input('学校名字: ').strip() addr = input('学校地址: ').strip() school_list = [(obj.name, obj.addr) for obj in School.get_obj_list()] # 学校列表 if (name, addr) in school_list: print('\033[31;1m学校名 [%s], 学校地址[%s] 已存在\033[0m' % (name, addr)) else: school = School(name, addr) school.save() print('\033[33;1m学校[%s], 地址[%s] 创建成功\033[0m' % (name, addr))
def school2db(response): reader = csv.DictReader(StringIO(response.read().decode())) for row in reader: if row['LGA']: lga_name = ''.join(x.lower() for x in row['LGA'] if x.isalpha()) school_name = row['School_name'] post_code = str(row['Postcode']) latitude = str(row['Latitude']) longitude = str(row['Longitude']) school_type = str(row['Level_of_schooling']) school = School(lga_name, school_name, post_code, latitude, longitude, school_type) school.save()
def post(self, request): """ Create school record in database :param request: Key value pair data :return: status & respective message """ data = request.data try: school = School(**data) school.save() LOGGER.info("School created successfully") except Exception, error: LOGGER.error("Error:%s", str(error)) return Response({"status": "FAILED", "message": str(error)})
def submit(): d = request.json for (k, v) in d.items(): print(f'{k} : {v}') # s = Student(email=d['email'],childName=d['childName'], atVenue = d['atVenue'], accommodation_other = d['accommodation_other'], twin = d['twin'],rankings=d['rankings'],schoolId=d['schoolId'],hebSchoolId=d['hebSchoolId'],school=d['school'],hebSchool=d['hebSchool'],DOB=d['DOB']) s = Student(**d) db.session.add(s) # db.session.flush() # db.session.refresh(s) db.session.commit() # db.session.add(s) nonDates = d['nonDates'] for nonDate in nonDates: greg = nonDate['greg'] gdate = date(greg['year'], greg['month'], greg['day']) nd = NonDate(greg=gdate) nd.hdate_str = nonDate['hdate_str'] nd.hdate_str_heb = nonDate['hdate_str_heb'] nd.student_id = s.id s.nonDates.append(nd) nd.student = s print("APPENDING non-DATE") print(f"student_id is: {s.id}") db.session.add(nd) sch = School.query.filter_by(id=d['schoolId']).first() if sch is None: sch = School() sch.name = d['school'] db.session.add(sch) db.session.commit() sch.students.append(s) else: sch.students.append(s) hSch = HebSchool.query.filter_by(id=d['hebSchoolId']).first() if hSch is None: hSch = HebSchool() hSch.name = d['hebSchool'] db.session.add(hSch) hSch.students.append(s) else: hSch.students.append(s) db.session.commit() q.enqueue_call(func=send_submission_email, kwargs={'student_id': s.id}, result_ttl=5000) return jsonify({"resp": "good!"}), 200
def populate(): # from models import School,HebSchool names = ['Lainer School'] for name in names: school = School.query.filter_by(name=name).first() if school is None: school = School(name=name) db.session.add(school) db.session.commit() hNames = ["Temple Isaiah"] for name in hNames: school = HebSchool.query.filter_by(name=name).first() if school is None: school = HebSchool(name=name) db.session.add(school) db.session.commit()
def popupdateschools(): schools = {} with app.app_context(): typeformdata = requests.get( 'https://api.typeform.com/v1/form/rak9AE?key=***************************************&completed=true&order_by=date_submit&limit=3000' ).json() responses = typeformdata['responses'] for user in responses: school = user['answers']['dropdown_20497446'] if school == 'Other': if 'textfield_20513659' in user['answers']: school = user['answers']['textfield_20513659'] else: continue if school is not None: if school in schools: schools[school] += 1 else: schools[school] = 1 try: schools['Illinois Institute of Technology'] += 7 schools['Case Western Reserve University'] += 4 schools['University of Illinois at Chicago'] += 2 except KeyError: pass for school in schools: try: db_school = School.query.filter_by(name=school).first() if db_school is not None: db_school.app_count = schools[school] db_school.dimension = int( min( 70, 70 * pow(float(float(schools[school]) / 50), 0.333333333333))) db.session.commit() else: dimension = int( min( 70, 70 * pow(float(float(schools[school]) / 50), 0.333333333333))) db_school = School(name=school, app_count=schools[school], dimension=dimension) db.session.add(db_school) db.session.commit() except IntegrityError: continue
def create(): auth_header = request.headers.get('Authorization') if auth_header: user_id = uc.decode_auth_token(auth_header) if not isinstance(user_id, int): return jsonify({"Error": "Failed to authenticate"}) else: return jsonify({"Error": "Failed to authenticate"}) school_data = request.json school_name = school_data['school_name'] about = school_data['about'] location = school_data['location'] admission = school_data['admission'] image_url = school_data['image_url'] # try: # image_data = request.files.getlist('files') # except Exception: # return jsonify({'Error': 'Failed to get files'}) # image_location = '' # try: # # for image in image_data: # filename = secure_filename(image_url[0].filename) # image_url[0].save(filename) # s3.upload_file( # Bucket=S3_BUCKET_NAME, # Filename=filename, # Key=filename # ) # image_location = '{}{}'.format(S3_LOCATION, filename) # except Exception as e: # return jsonify({'Error': str(request.files.getlist('image_url'))}) school = School(school_name=school_name, about=about, location=location, admission=admission, image_url=image_url, user_id=user_id) db.session.add(school) try: db.session.commit() except Exception as e: db.session.rollback() db.session.flush() return jsonify({'Error': str(e)}) return jsonify({'Success': 'New school entry created'})
def setUp(self): self.school = School(name='Minnesota') db.session.add(self.school) db.session.commit() self.tch = Teacher(first_name='Jess', last_name='Christensen', title='K4-2nd Sped', school_id=self.school.id, username='******', password='******') db.session.add(self.tch) db.session.commit() self.stu = Student(first_name='Fake', last_name='Kid', dob=date(2012, 1, 24), grade=1, teacher_id=self.tch.id, dis_area='OHI') db.session.add(self.stu) db.session.commit() self.guardian = Guardian(first_name='Fake', last_name='Dad', relation='Dad', username='******', password='******') self.guardian2 = Guardian(first_name='Fake', last_name='Mom', relation='Mom', username='******', password='******') db.session.add(self.guardian) db.session.add(self.guardian2) db.session.commit() self.family = Family(guardian_id=self.guardian.id, student_id=self.stu.id) self.family2 = Family(guardian_id=self.guardian2.id, student_id=self.stu.id) db.session.add(self.family) db.session.add(self.family2) db.session.commit()
def setUp(self): self.school = School(name='Coultrap') db.session.add(self.school) db.session.commit() self.tch = Teacher(first_name='Jess', last_name='Christensen', title='K4-2nd Sped', school_id=self.school.id, username='******', password='******') self.reg_obj = Teacher.register(first_name=self.tch.first_name, last_name=self.tch.last_name, title=self.tch.title, school_id=self.tch.school_id, username=self.tch.username, password=self.tch.password)
def pop_schools(): schools = School.all() try: first_school = schools[0].name return None except IndexError: s1 = School(name="University of Rhode Island", state="RI", classes=[]) s1.put() s2 = School(name="University of Massachusetts", state="MA", classes=[]) s2.put() s3 = School(name="CCRI", state="RI", classes=[]) s3.put() s4 = School(name="Penn State University", state="PA", classes=[]) s4.put() s5 = School(name="New York University", state="NY", classes=[]) s5.put() s6 = School(name="Johnson and Wales", state="RI", classes=[]) s6.put() s7 = School(name="Roger William University", state="RI", classes=[]) s7.put() s8 = School(name="Brown University", state="RI", classes=[]) s8.put() s9 = School(name="Bryant University", state="RI", classes=[]) s9.put()
def setUp(self): self.school = School(name='Minnesota') db.session.add(self.school) db.session.commit() self.tch = Teacher(first_name='Jess', last_name='Christensen', title='K4-2nd Sped', school_id=self.school.id, username='******', password='******') db.session.add(self.tch) db.session.commit() self.stu = Student(first_name='Fake', last_name='Kid', dob=date(2012, 1, 24), grade=1, teacher_id=self.tch.id, dis_area='OHI') db.session.add(self.stu) db.session.commit() self.iep = IEP(student_id=self.stu.id, teacher_id=self.tch.id) db.session.add(self.iep) db.session.commit() self.goal = Goal(iep_id=self.iep.id, goal="Increase CWPM to 23", standard="Read with fluency") db.session.add(self.goal) db.session.commit() self.cw_data = ClassworkData(goal_id=self.goal.id, baseline="12 CWPM", current="15 CWPM", attainment="23 CWPM") db.session.add(self.cw_data) db.session.commit()
def create_school(): try: name = input('请输入学校名字:').strip() addr = input('请输入学校地址:').strip() school_name_list = [(obj.name, obj.addr) for obj in School.get_all_obj_list()] if (name, addr) in school_name_list: raise Exception( '\033[43;1m[%s] [%s]校区已经存在,不可重复创建,你有那么多学生吗?\033[0m' % (name, addr)) obj = School(name, addr) obj.save() status = True error = '' data = '\033[33;1m[%s] [%s]校区创建成功\033[0m' % (obj.name, obj.addr) except Exception as e: status = False error = str(e) data = '' return {'status': status, 'error': error, 'data': data}
def add_school(): form = AddSchool() user = current_user msg = "" if request.method == "POST": #The district_id is supposed to be an integer #try: #district = District.query.filter_by(id=int(form.district_id)) # .all() #if len(district) == 1: #Add School to db db.session.add( School(int(form.district_id.data), form.name.data, form.shortname.data, form.domain.data.form.license.data)) db.session.commit() #else: # error_msg= "A district with that id doesn't exist!" #except: # error_msg= "The entered district_id was not an integer!" return render_template('add_school.html', form=form, msg=msg, user=user)
def create_inst(): if request.method == "GET": return render_template('register.html') if request.method == "POST": print(request.form) name = request.form["name"] email = request.form["email"] password = request.form["password"] # confirm_password = request.form["confirm_password"] option = {1: 'school', 2: 'college'}[int(request.form['option'])] # if not confirm_password == password: # return redirect(url_for('.home_page')) if option == 'school': new_school = School(name, email, password) db_session.add(new_school) db_session.commit() log('School created') elif option == 'college': new_college = College(name, email, password) db_session.add(new_college) db_session.commit() log('College Created') return redirect(url_for('.home_page'))
for tup in coachsite.salaries[0]: tup2 = int(tup[2].replace('$', '').replace(',', '')) c_instance = Coach(name = tup[0] , years = tup[1] , salary = tup2,\ sal_school = tup[3]) coach_instances.append(c_instance) session.add(c_instance) #######Instansiate school model########## team_instances = [] for school_name in keys: years_ = teamsite[school_name].years winloss_ = teamsite[school_name].winloss team_points_ = teamsite[school_name].team_points opp_points_ = teamsite[school_name].opp_points for i in range(0, len(years_)): if years_[i] != '' and winloss_[i] != '' and team_points_[ i] != '' and opp_points_[i] != '': team_instance = School(name = school_name, years = years_[i], winloss = winloss_[i],\ team_points = team_points_[i], opp_points = opp_points_[i]) for coach in coach_instances: if coach.sal_school.replace( ' ', '-').lower() == team_instance.name and coach.years == ( team_instance.years)[:-3]: team_instance.coaches.append(coach) team_instances.append(team_instance) session.add(team_instance) session.commit()
from flask import Flask from models import db, School, Class, Student, Teacher from routes import classesApi, schoolsApi, teachersApi, studentsApi, index app = Flask(__name__) app.register_blueprint(classesApi) app.register_blueprint(schoolsApi) app.register_blueprint(teachersApi) app.register_blueprint(studentsApi) app.register_blueprint(index) db.init_app(app) with app.app_context(): db.create_all() school = School(name='middle50', address='address') db.session.add(school) db.session.commit() group = Class(name='1A', school_id=school.id) db.session.add(group) db.session.commit() db.session.add(Student(name='Vasya', class_id=group.id)) db.session.add(Teacher(name='Irina', class_id=group.id, subject='Math')) db.session.commit() if __name__ == "__main__": app.run()
def createSchool(s_info): newSchool = School(s_info["s_id"]) db.session.add(newSchool) db.session.commit() return jsonify({"s_id": newSchool.s_id})
# add computers to DB from file with open(data_dir + 'computers.csv', 'r') as fp: for line in fp: line = line.strip().split(',')[:1][0] if line[0] != '#': computer = Computer(guid=line) session.add(computer) session.flush() # add schools to DB from file with open(data_dir + 'schools.csv', 'r') as fp: for line in fp: line = line.strip().split(',')[:2] if line[0] != '#': school = School(id=line[0], name=line[1]) session.add(school) session.flush() # add units to DB from file with open(data_dir + 'units.csv', 'r') as fp: for line in fp: line = line.strip().split(',')[:1][0] if line[0] != '#': unit = Unit(name=line) session.add(unit) session.flush() # add teachers to DB from file with open(data_dir + 'teachers.csv', 'r') as fp: for line in fp:
from flask import Flask from models import db, Person, School, Sport_section from routes import index from person import personApi from school import schoolApi app = Flask(__name__) app.register_blueprint(personApi) app.register_blueprint(schoolApi) app.register_blueprint(index) db.init_app(app) with app.app_context(): db.create_all() school = School(name='Gimnazia1', adress='Lenina 10') school2 = School(name='Gimnazia2', adress='Lenina 55') school3 = School(name='Gimnazia3', adress='Lenina 20') school4 = School(name='Gimnazia10', adress='Lenina 40') db.session.add(school) db.session.add(school2) db.session.add(school3) db.session.add(school4) db.session.commit() person = Person(name='Lev', age=15, school_id=school2.id) person1 = Person(name='Ivan', age=9, school_id=school4.id) person2 = Person(name='Petr', age=18, school_id=school.id) db.session.add(person) db.session.add(person1) db.session.add(person2) db.session.commit()
def setUp(self): self.school1 = School(name='Coultrap') self.school2 = School(name="Chicago")
from app import db from datetime import date from models import School, Teacher, Student, Guardian, Family, IEP, Goal, ClassworkData, GoalStandard, GoalStandardSet, MsgToGuardian db.drop_all() db.create_all() sch1 = School(name='Chicago', state='Illinois', state_code='549159D28465455FB144F5B67F3ACDFF') sch2 = School(name='Minneapolis', state='Minnesota', state_code="B632FB4B1B83445AA8DB46DC3F079D19") sch3 = School(name='Milwaukee', state='Wisconsin', state_code='745124D969E9491C9FC33D3235259386') db.session.add(sch1) db.session.add(sch2) db.session.add(sch3) db.session.commit() Teacher.register(first_name='James', last_name='Reid', title='K4-2nd Sped', school_id=1, username='******', password='******') Teacher.register(first_name='Maria', last_name='Aldapa', title='3rd-5th Sped',
def gather_siteinfo(self): user = app.config['SITEINFO_DATABASE_USER'] password = app.config['SITEINFO_DATABASE_PASS'] address = app.config['SITEINFO_DATABASE_HOST'] DEBUG = True # Connect to gather the db list con = connect(host=address, user=user, passwd=password) curs = con.cursor() # find all the databases with a siteinfo table find = ("SELECT table_schema, table_name " "FROM information_schema.tables " "WHERE table_name = 'siteinfo' " "OR table_name = 'mdl_siteinfo';") curs.execute(find) check = curs.fetchall() con.close() # store the db names and table name in an array to sift through db_sites = [] if len(check): for pair in check: db_sites.append(pair) # for each relevent database, pull the siteinfo data for database in db_sites: cherry = connect(user=user, passwd=password, host=address, db=database[0]) # use DictCursor here to get column names as well pie = cherry.cursor(DictCursor) # Grab the site info data pie.execute("select * from `%s`;" % database[1]) data = pie.fetchall() cherry.close() # For all the data, shove it into the central db for d in data: # what version of moodle is this from? version = d['siterelease'][:3] # what is our school domain? take the protocol # off the baseurl school_re = 'http[s]{0,1}:\/\/' school_url = re.sub(school_re, '', d['baseurl']) # try to figure out what machine this site lives on if 'location' in d: if d['location'][:3] == 'php': location = 'platform' else: location = d['location'] else: location = 'unknown' # get the school school = School.query.filter_by(domain=school_url).first() # if no school exists, create a new one with # name = sitename, district_id = 0 (special 'Unknown' # district) if school is None: school = School(name=d['sitename'], shortname=d['sitename'], domain=school_url, license='') school.district_id = 0 db.session.add(school) db.session.commit() # find the site site = Site.query.filter_by(baseurl=school_url).first() # if no site exists, make a new one, school_id = school.id if site is None: site = Site(name=d['sitename'], sitetype=d['sitetype'], baseurl='', basepath='', jenkins_cron_job=None, location='') site.school_id = school.id site.baseurl = school_url site.basepath = d['basepath'] site.location = location db.session.add(site) db.session.commit() # create new site_details table # site_id = site.id, timemodified = now() now = datetime.datetime.now() site_details = SiteDetail(siteversion=d['siteversion'], siterelease=d['siterelease'], adminemail=d['adminemail'], totalusers=d['totalusers'], adminusers=d['adminusers'], teachers=d['teachers'], activeusers=d['activeusers'], totalcourses=d['totalcourses'], timemodified=now) site_details.site_id = site.id # if there are courses on this site, try to # associate them with our catalog if d['courses']: # quick and ugly check to make sure we have # a json string if d['courses'][:2] != '[{': continue """ @TODO: create the correct association model for this to work courses = json.loads(d['courses']) associated_courses = [] for i, course in enumerate(courses): if course['serial'] != '0': course_serial = course['serial'][:4] orvsd_course = Course.query .filter_by(serial= course_serial) .first() if orvsd_course: # store this association # delete this course from the json string pass # put all the unknown courses back in the # site_details record site_details.courses = json.dumps(courses) """ site_details.courses = d['courses'] db.session.add(site_details) db.session.commit()
def put(name, adress): school = School(name=name, adress=adress) db.session.add(school) db.session.commit() return jsonify(school.json()) if school else ''