def insert_schools_data(): university = University.objects.first() for school_name, degrees in schools_data.items(): school = School(name=school_name) school.university = university school.save() for degree_name, subjects in degrees.items(): degree = Degree(title=degree_name) degree.school = school degree.save() for subject_code, subject_title in subjects.items(): subject = Subject(code=subject_code, title=subject_title['title']) subject.degree = degree subject.save()
def create_course(): try: print('创建课程'.center(60, '=')) school_list = School.get_all_obj_list() for k, obj in enumerate(school_list): print(k, obj['name'], obj['addr']) id = int(input('请选择学校: ')) school_obj = school_list[id] #print(school_obj,school_obj ['nid'] ) name = input('请输入课程名: ').strip() price = input('请输入课程价格: ').strip() period = input('请输入课程周期: ').strip() course_name_list = [(obj['name'], obj['school_nid']) for obj in Course.get_all_obj_list()] if name in course_name_list: raise Exception('\033[43;1m课程[%s] 已经存在,不可重复创建\033[0m' % (name)) obj = Course(name, price, period, school_obj['nid']) obj.save() status = True error = '' data = '\033[33;1m课程[%s] 价格[%s] 周期[%s]创建成功\033[0m' % ( obj.name, obj.price, obj.period) print(data) except Exception as e: status = False error = str(e) print('error: %s' % error) data = '' return {'status': status, 'error': error, 'data': data}
def create_student(): try: print('创建学生'.center(60, '=')) name = input("请输入姓名: ").strip() age = input("请输入年龄: ").strip() if name == '' or age == '': raise Exception("输入不能为空") if age.isdigit(): age = int(age) else: raise Exception("年龄应该是数字") student_name_list = [obj.name for obj in Student.get_all_obj_list()] if name in student_name_list: raise Exception("学生[%s]已存在" % name) school_list = School.get_all_obj_list() for k, obj in enumerate(school_list): print(k, '[%s] [%s]校区' % (obj.name, obj.addr)) s_sid = input("请选择学校:") if s_sid.isdigit(): s_sid = int(s_sid) if s_sid >= len(school_list): raise Exception("输入的学校不存在") else: raise Exception("输入的学校不存在") classes_list = Classes.get_all_obj_list() for k, obj in enumerate(classes_list): print(k, obj.name, '[%s]校区' % (obj.school_nid.get_obj_by_nid().addr)) sid = input("请选择班级:") if sid.isdigit(): sid = int(sid) if sid >= len(classes_list): raise Exception("输入的班级不存在") else: raise Exception("输入的班级不存在") if school_list[s_sid].nid.nid != classes_list[sid].school_nid.nid: raise Exception("[%s][%s]校区没有 [%s]班级" % (school_list[s_sid].name, school_list[s_sid].addr, classes_list[sid].name)) print( "学费为: ", classes_list[sid].course_to_teacher_list_nid. get_obj_by_nid().course_nid.get_obj_by_nid().price) obj = Student(name, age, classes_list[sid].nid) obj.save() status = True error = '' data = '\033[33;1m学生[%s] 创建成功\033[0m' % name except Exception as e: status = False error = str(e) data = '' return {'status': status, 'error': error, 'data': data}
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) print(data) except Exception as e: status = False error = str(e) print('error: %s' % error) data = '' return {'status': status, 'error': error, 'data': data}
def create_school(): try: print('创建学校'.center(60, '=')) name = input("请输入学校名字: ").strip() addr = input("请输入学校地址: ").strip() if name == '' or addr == '': raise Exception("输入不能为空") 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 create_course(): try: print('创建课程'.center(60, '=')) school_list = School.get_all_obj_list() for k, obj in enumerate(school_list): print(k, obj.name, obj.addr) sid = input("请选择学校: ").strip() if sid.isdigit(): sid = int(sid) if sid >= len(school_list): raise Exception("输入的学校不存在") else: raise Exception("输入的学校不存在") school_obj = school_list[sid] name = input("请输入课程名称: ").strip() price = input("请输入课程费用: ").strip() if name == '' or price == '': raise Exception("输入不能为空") if price.replace('.', '', 1).isdigit(): pass else: raise Exception("课程费用应该是数字") period = input("请输入课程周期: ").strip() if period == '': raise Exception("输入不能为空") course_name_list = [(obj.name, obj.school_nid.nid) for obj in Course.get_all_obj_list()] if (name, school_obj.nid.nid) in course_name_list: raise Exception('\033[43;1m课程[%s] 已经存在,不可重复创建\033[0m' % (name)) obj = Course(name, price, period, school_obj.nid) obj.save() status = True error = '' data = '\033[33;1m课程[%s] 价格[%s] 周期[%s]创建成功\033[0m' % ( obj.name, obj.price, obj.period) except Exception as e: status = False error = str(e) data = '' return {'status': status, 'error': error, 'data': data}
def create_classes(): try: print('创建班级'.center(60, '=')) school_list = School.get_all_obj_list() for k, obj in enumerate(school_list): print(k, obj.name, obj.addr) sid = input("请选择学校:") if sid.isdigit(): sid = int(sid) if sid >= len(school_list): raise Exception("输入的学校不存在") else: raise Exception("输入的学校不存在") school_obj = school_list[sid] name = input("请输入班级名称: ") course_to_teacher_list = Course_to_teacher.get_all_obj_list() for k, obj in enumerate(course_to_teacher_list): if school_obj.nid.nid == course_to_teacher_list[k].school_nid.nid: print( k, '课程[%s] 讲师[%s] [%s] [%s]校区' % (obj.course_nid.get_obj_by_nid().name, obj.teacher_nid.get_obj_by_nid().name, obj.school_nid.get_obj_by_nid().name, obj.school_nid.get_obj_by_nid().addr)) choice = input("请选择关联课程:") if choice.isdigit(): choice = int(choice) if choice >= len(course_to_teacher_list): raise Exception("没有该课程") else: raise Exception("没有该课程") obj = Classes(name, school_obj.nid, course_to_teacher_list[choice].nid) obj.save() status = 'True' error = '' data = '\033[33;1m班级[%s]创建成功\033[0m' % (name) except Exception as e: status = False error = str(e) data = '' return {'status': status, 'error': error, 'data': data}
def handle(self, *args, **options): School.objects.all().delete() print "Loading basic data" filename = 'STATE.csv' raw = os.path.join(PARSER_PATH, 'raw/') path = os.path.join(raw, filename) f = open(path, "r") raw_data = UnicodeDictReader(f, delimiter=',') ''' We don't import some school codes because they are not immediately relevant for the application. Here is the reference list as far as I can suss it out. Will need to find the actual reference list. 1: No idea 2: ISDs 3: districts 4: charter? 5: Also ISDs? 6: religious 7: service buildings, planetariums, etc. 8: corrections 9: special academies (charter?) 10: state ''' exclude = ['01', '06', '07'] records_to_insert = [] districts_saved = {} for line in raw_data: if line['Type'] not in exclude: entry = School() # The state data stores building name and district name in the same # column, so here we figure out which one we're dealing with. if line['Building Code'] == '00000': # This is a district line['District Name'] = line['Building Name'] entry.district_name = line['Building Name'] entry.district_code = line['District Code'] entry.building_code = '00000' else: # This is a state. entry.building_name = line['Building Name'] entry.building_code = line['Building Code'] # The state data does not include district name for schools, # so we have to go back and get that from the data that has # already been saved. try: entry.district_name = districts_saved[line['District Code']]['District Name'] entry.district_code = districts_saved[line['District Code']]['District Code'] except: print line['District Code'] print districts_saved assert False entry.slug = slugify(line['Building Name']) entry.district_slug = slugify(entry.district_name) # Save the districts one-by-one so that we can refer to them # when creating building records. if line['Building Code'] == '00000': districts_saved[line['District Code']] = line entry.save()
def show_school(): for obj in School.get_all_obj_list(): print('\033[45;1m学校[%s] 地址[%s] 创建日期[%s]\033[0m'.center(60,'-') \ %(obj['name'],obj['addr'],obj['create_time']))
def run(*args): parser = argparse.ArgumentParser( description="Setup a new school for OpenShiksha") parser.add_argument('--school', '-s', type=long, required=True, help='id for new school') parser.add_argument('--board', '-b', type=long, required=True, help='board id for new school') parser.add_argument('--name', '-n', required=True, help='The name of the new school') parser.add_argument( '--actual', '-a', action='store_true', help='actually send emails (otherwise only database changes are made)') argv = runscript_args_workaround(args) processed_args = parser.parse_args(argv) print 'Running with args:', processed_args snapshot_db() # first make sure school does not already exist new_school_id = processed_args.school try: school = School.objects.get(pk=new_school_id) raise Exception('Invalid school id: %s Already used for %s' % (new_school_id, school)) except School.DoesNotExist: pass # new_school_id - 1 should exist existing_school = School.objects.get(pk=new_school_id - 1) # make the new school entry board = Board.objects.get(pk=processed_args.board) name = processed_args.name root = User.objects.get(username='******') new_school = School(name=name, board=board, admin=root) new_school.save() #create school's admin user entry admin = User.objects.create_user( username='******' + str(new_school_id), email='hwcadmin_school_' + str(new_school_id) + '@openshiksha.org', password=SETUP_PASSWORD, first_name='hwcadmin', last_name='school_' + str(new_school_id)) # set up admin userinfo admin_userinfo = UserInfo(user=admin) admin_userinfo.group = HWCentralGroup.refs.ADMIN admin_userinfo.school = new_school admin_userinfo.save() # reassign new school's admin new_school.admin = admin new_school.save() # set the new school's profile # TODO: incorporate school profile options as command line args school_profile = SchoolProfile(school=new_school) school_profile.save() with open(USER_CSV_PATH) as csvfile: reader = csv.DictReader(csvfile) for row in reader: email = row['email'] fname = row['fname'] lname = row['lname'] username = build_username(fname, lname) group = row['group'] school = row['school'] print "Creating user : %s ,email: %s" % (username, email) user = User.objects.create_user(username=username, email=email, password=SETUP_PASSWORD) user.first_name = fname user.last_name = lname user.save() userinfo = UserInfo(user=user) userinfo.group = Group.objects.get(pk=group) userinfo.school = School.objects.get(pk=school) userinfo.save() # TODO: Dossier setup if processed_args.actual: send_activation_email(email) else: print "Skipping email sending for dry run" print "All users saved!" with open(HOME_CSV_PATH) as csvfile: reader = csv.DictReader(csvfile) for row in reader: parent = User.objects.get(email=row['parent']) assert parent.userinfo.group == HWCentralGroup.refs.PARENT children = get_students(row['children']) home = Home(parent=parent) print "Adding home for parent : %s" % parent home.save() for child in children: print '\tAdding %s as child' % child home.children.add(child) home.save() print "Added home for all parents" with open(CLASSROOM_CSV_PATH) as csvfile: reader = csv.DictReader(csvfile) for row in reader: classteacher = User.objects.get(email=row['classteacher']) assert classteacher.userinfo.group == HWCentralGroup.refs.TEACHER school = School.objects.get(pk=row['school']) standard = Standard.objects.get(number=row['standard']) students = get_students(row['students']) division = row['division'] classroom = ClassRoom() classroom.classTeacher = classteacher classroom.school = school classroom.standard = standard classroom.division = division print "Adding classroom %s with classteacher %s" % (classroom, classteacher) classroom.save() for student in students: print '\tAdding %s as classroom student' % student classroom.students.add(student) classroom.save() print "Added all classrooms" with open(SUBJECTROOM_CSV_PATH) as csvfile: reader = csv.DictReader(csvfile) for row in reader: teacher = User.objects.get(email=row['teacher']) assert teacher.userinfo.group == HWCentralGroup.refs.TEACHER subject = Subject.objects.get(pk=row['subject']) classroom = ClassRoom.objects.get(pk=row['classroom']) students = get_students(row['students']) subjectroom = SubjectRoom() subjectroom.teacher = teacher subjectroom.subject = subject subjectroom.classRoom = classroom print "Adding subjectroom %s with subjectteacher %s for classroom %s" % ( subjectroom, teacher, classroom) subjectroom.save() for student in students: print '\tAdding %s as subjectroom student' % student subjectroom.students.add(student) subjectroom.save() print "Added all subjectrooms" print "\n\nFull-School setup finished\n" enforcer_check()