1.**本次作业实现的需求:**
角色:学校、学员、课程、讲师
要求:
创建北京、上海 2 所学校
创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开
课程包含,周期,价格,通过学校创建课程
通过学校创建班级, 班级关联课程、讲师
创建学员时,选择学校,关联班级
创建讲师角色时要关联学校,
提供两个角色接口
学员视图, 可以注册, 交学费, 选择班级,
讲师视图, 讲师可管理自己的班级, 上课时选择班级, 查看班级学员列表 , 修改所管理的学员的成绩
管理视图,创建讲师, 创建班级,创建课程
上面的操作产生的数据都通过pickle序列化保存到文件里
</br>
6. **测试:**
ATM普通用户启动脚本为 选课系统\bin\start.
-----------------------------------------------------------------------------
1.主登录界面
———————————————————————————————————————
------- 欢迎来到选课系统 ---------
1.学员系统
2.讲师系统
3.管理系统
4.退出
———————————————————————————————————————
2.学员系统界面
———————————————————————————————————————
0:选项
1:注册
2:学费缴纳
3:课程选择
4:退出
———————————————————————————————————————
3.讲师系统界面
———————————————————————————————————————
请输入老师用户名:北京老师
请输入老师密码:123456
登录成功!
0:选项
1:管理自己的班级
2:上课时选择班级
3:查看班级学生列表
4:修改成绩
5:退出
———————————————————————————————————————
4.管理员界面
———————————————————————————————————————
请输入管理员用户名:admin
请输入管理员用户密码:admin
登录成功!
0:选项
1:创建学校
2:查看学校
3:创建老师
4:查看老师
5:创建课程
6:查看课程
7:创建班级
8:查看班级
9:创建学生
10:查看学生
11:退出
请输入选项:
———————————————————————————————————————
7. **备注:**
1.因为pickle会把绝对路径格式化进去。。所以没有提供测试账户
2.进入管理员用户,直接输入用户名密码,即可建管理员用户。
3.以后每次登陆必须用上一步创建的用户名密码
4.第一次创建数据请按照管理员选项顺序即,学校-老师-课程-班级-学生创建,之后可不用
5.学员系统中缴费和选课都需要登录
6.教师系统中,因为不知道要怎么管理班级,就把班级打印了一遍。
7.用admin创建的老师和学生的密码均为123456,学生系统中创建可指定密码
代码:
首先是开始代码
在bin下的start,来开始调用主程序
1 import os,sys 2 3 4 base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 5 sys.path.append(base_dir) 6 7 from core import main 8 9 if __name__ == ‘__main__‘: 10 main.run()
start
conf下的seeting,为配置文件,里面主要存放了数据路径
1 import os 2 import logging 3 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 4 5 6 ADMIN_DB_DIR=os.path.join(BASE_DIR,‘db‘,‘admin‘) 7 SCHOOL_DB_DIR=os.path.join(BASE_DIR,‘db‘,‘school‘) 8 TEACHER_DB_DIR=os.path.join(BASE_DIR,‘db‘,‘teacher‘) 9 COURSE_DB_DIR=os.path.join(BASE_DIR,‘db‘,‘course‘) 10 COURSE_TO_TEACHER_DB_DIR=os.path.join(BASE_DIR,‘db‘,‘course_to_teacher‘) 11 CLASSES_DB_DIR=os.path.join(BASE_DIR,‘db‘,‘classes‘) 12 STUDENT_DB_DIR=os.path.join(BASE_DIR,‘db‘,‘student‘)
setting
core下的admin_sys.py,main.py,student_sys.py,teacher_sys.py分别对应文件的主逻辑,通过mian调用其他三个
admin_sys.py为管理员主逻辑
1 #!/usr/bin/env python 2 # coding=utf-8 3 #Author:yang 4 5 from lib.models import Student 6 from lib.models import School 7 from lib.models import Teacher 8 from lib.models import Course 9 from lib.models import Classes 10 from lib.models import Admin 11 12 def tes(func): 13 #处理异常的装饰器 14 def wapper(*args,**kwargs): 15 try: 16 func(*args,**kwargs) 17 except Exception : 18 print(‘请输入编号‘) 19 pass 20 return wapper 21 22 @tes 23 def create_school(): 24 #创建学校 25 name = input(‘请输入学校名字: ‘).strip() 26 addr = input(‘请输入学校地址: ‘).strip() 27 school_name_list = [] 28 for obj in School.get_list(): 29 school_name_list.append((obj.name,obj.addr)) 30 if (name, addr) in school_name_list: 31 print(‘校区已经存在!‘) 32 else: 33 school = School(name, addr) 34 school.save() 35 print(‘\033[33;1m[%s] [%s]校区 创建成功\033[0m‘ %(name,addr)) 36 37 38 def show_school(): 39 #打印学校 40 School.get_list() 41 for obj in School.get_list(): 42 print(‘\033[45;1m学校[%s] 地址[%s]\033[0m‘ 43 %(obj.name,obj.addr)) 44 45 46 47 @tes 48 def create_teacher(): 49 #创建老师 50 school_list = School.get_list() 51 for k, obj in enumerate(school_list): 52 print(k, obj, obj.addr) 53 sid = int(input(‘请选择需要创建对象的学校编号: ‘)) 54 school_obj = school_list[sid] 55 name = input(‘请输入老师名字: ‘).strip() 56 teacher_name_list = [] 57 for obj in Teacher.get_list(): 58 teacher_name_list.append((obj.name,obj.school_nid)) 59 if (name,school_obj.nid) in teacher_name_list: 60 print(‘老师已经存在!‘) 61 else: 62 teacher = Teacher(name,school_obj.nid) 63 teacher.save() 64 print(‘\033[33;1m[%s]老师 创建成功\033[0m‘ %name) 65 66 def show_teacher(): 67 #打印老师 68 Teacher.get_list() 69 for obj in Teacher.get_list(): 70 print(‘\033[45;1m[%s] [%s]校区 老师[%s]\033[0m‘ 71 % (obj.school_nid.get_obj_uuid().name,obj.school_nid.get_obj_uuid().addr,obj.name)) 72 73 @tes 74 def create_course(): 75 #创建课程 76 school_list = School.get_list() 77 for k, obj in enumerate(school_list): 78 print(k, obj, obj.addr) 79 sid = int(input(‘请选择创建课程的学校: ‘)) 80 school_obj = school_list[sid] 81 82 name = input(‘请输入课程名: ‘).strip() 83 price = input(‘请输入课程价格: ‘).strip() 84 period = input(‘请输入课程周期: ‘).strip() 85 86 course_name_list = [] 87 for obj in Course.get_list(): 88 course_name_list.append((obj.name, obj.school_nid)) 89 if (name, school_obj.nid) in course_name_list: 90 print(‘课程已经存在!‘) 91 else: 92 obj = Course(name, price, period, school_obj.nid) 93 obj.save() 94 print(‘\033[33;1m[%s]课程 创建成功\033[0m‘%obj.name) 95 96 def show_course(): 97 #打印课程 98 for obj in Course.get_list(): 99 print(‘\033[33;1m[%s] [%s]校区 [%s]课程 价格[%s] 周期[%s]\033[0m‘ 100 %(obj.school_nid.get_obj_uuid().name,obj.school_nid.get_obj_uuid().addr,101 obj.name,obj.price,obj.period)) 102 103 @tes 104 def create_classes(): 105 #创建班级 106 school_list = School.get_list() 107 for k, obj in enumerate(school_list): 108 print(k, obj, obj.addr) 109 sid = int(input(‘请选择创建班级的学校: ‘)) 110 school_obj = school_list[sid] 111 print(school_obj.addr) 112 course_list = Course.get_list() 113 for k, obj in enumerate(course_list): 114 if obj.school_nid.get_obj_uuid().addr == school_obj.addr: 115 print(k, obj.name) 116 cid= int(input(‘请选择创建班级的课程: ‘)) 117 course_obj = course_list[cid] 118 teacher_list = Teacher.get_list() 119 for k, obj in enumerate(teacher_list): 120 if obj.school_nid.get_obj_uuid().addr == school_obj.addr: 121 print(k, obj.name) 122 tid= int(input(‘请选择该课程的老师: ‘)) 123 teacher_obj = teacher_list[tid] 124 name = input(‘请输入班级名: ‘).strip() 125 classes_name_list = [] 126 for obj in Classes.get_list(): 127 classes_name_list.append((obj.name,obj.school_nid,obj.teacher_nid,obj.course_nid)) 128 if (name, teacher_obj.nid,course_obj.nid) in classes_name_list: 129 print(‘班级已经存在!‘) 130 else: 131 obj = Classes(name,school_obj.nid,teacher_obj.nid,course_obj.nid) 132 obj.save() 133 print(‘\033[33;1m[%s]班级 创建成功\033[0m‘%obj.name) 134 135 def show_classes(): 136 #打印班级 137 for obj in Classes.get_list(): 138 print(‘\033[33;1m[%s] [%s]校区 [%s]班级 老师[%s] 课程[%s]\033[0m‘ 139 %(obj.school_nid.get_obj_uuid().name,obj.school_nid.get_obj_uuid().addr,140 obj.name,obj.teacher_nid.get_obj_uuid().name,obj.course_nid.get_obj_uuid().name)) 141 142 @tes 143 def create_student(): 144 #创建学生 145 school_list = School.get_list() 146 for k, obj in enumerate(school_list): 147 print(k, obj, obj.addr) 148 sid = int(input(‘请选择学校: ‘)) 149 school_obj = school_list[sid] 150 print(school_obj.addr) 151 152 class_list = Classes.get_list() 153 for k, obj in enumerate(class_list): 154 if obj.school_nid.get_obj_uuid().addr == school_obj.addr: 155 print(k,obj.name) 156 cid = int(input(‘请选择需要创建学生的班级: ‘)) 157 class_obj = class_list[cid] 158 name = input(‘请输入学生名字: ‘).strip() 159 student_name_list = [] 160 for obj in Student.get_list(): 161 student_name_list.append((obj.name,obj.classes_nid)) 162 if (name,class_obj.nid) in student_name_list: 163 print(‘学生已经存在!‘) 164 else: 165 student = Student(name,class_obj.nid) 166 student.save() 167 print(‘\033[33;1m[%s]学生 创建成功\033[0m‘ %name) 168 169 170 171 def show_student(): 172 #打印学生 173 for obj in Student.get_list(): 174 print(‘\033[33;1m[%s]学生 [%s]班级\033[0m‘ 175 % (obj.name, obj.classes_nid.get_obj_uuid().name)) 176 177 178 def show(): 179 #打印列表选项 180 msg=‘‘‘ 181 0:选项 182 1:创建学校 183 2:查看学校 184 3:创建老师 185 4:查看老师 186 5:创建课程 187 6:查看课程 188 7:创建班级 189 8:查看班级 190 9:创建学生 191 10:查看学生 192 11:退出 193 ‘‘‘ 194 print(msg) 195 196 197 198 def main(): 199 #admin_sys主函数,调用其他函数 200 choice_dic={ 201 ‘0‘:show, 202 ‘1‘:create_school, 203 ‘2‘:show_school, 204 ‘3‘:create_teacher, 205 ‘4‘:show_teacher, 206 ‘5‘:create_course, 207 ‘6‘:show_course, 208 ‘7‘:create_classes, 209 ‘8‘:show_classes, 210 ‘9‘:create_student, 211 ‘10‘:show_student, 212 ‘11‘:exit 213 } 214 show() 215 while True: 216 choice=input(‘请输入选项: ‘).strip() 217 if choice not in choice_dic:continue 218 choice_dic[choice]() 219 220 def login(): 221 #验证登录函数 222 username = input(‘请输入管理员用户名:‘).strip() 223 password = input(‘请输入管理员用户密码:‘).strip() 224 admin_list = [] 225 for obj in Admin.get_list(): 226 admin_list.append((obj.username,obj.password)) 227 if admin_list ==[]: 228 admin = Admin(username,password) 229 admin.save() 230 print(‘注册成功!‘) 231 main() 232 if (username, password) in admin_list: 233 print(‘登录成功!‘) 234 main() 235 else: 236 print(‘用户名密码无效!‘)
admin_sys
main.py为登录界面主逻辑
1 #!/usr/bin/env python 2 # coding=utf-8 3 #Author:yang 4 from core import teacher_sys 5 from core import student_sys 6 from core import admin_sys 7 8 9 def run(): 10 #接收开始模块,并选择其他模块 11 menu = u‘‘‘ 12 ------- 欢迎来到选课系统 --------- 13 \033[32;1m 1.学员系统 14 2.讲师系统 15 3.管理系统 16 4.退出 17 \033[0m‘‘‘ 18 print(menu) 19 20 menu_a = { 21 ‘1‘: student_sys, 22 ‘2‘: teacher_sys, 23 ‘3‘:admin_sys, 24 ‘4‘:exit 25 } 26 while True: 27 choice = input(‘请输入选项: ‘).strip() 28 if choice.isdigit() and int(choice)<4and int(choice)>0: 29 menu_a[choice].login() 30 elif choice.isdigit() and int(choice)==4: 31 menu_a[choice]() 32 else: 33 print(‘请输入对应编号!‘)
main
student_sys.py为学员登录的主逻辑
1 #!/usr/bin/env python 2 # coding=utf-8 3 #Author:yang 4 from lib.models import Student 5 from lib.models import School 6 from lib.models import Classes 7 from core import admin_sys 8 def show(): 9 #打印列表选项 10 msg=‘‘‘ 11 0:选项 12 1:注册 13 2:学费缴纳 14 3:课程选择 15 4:退出 16 ‘‘‘ 17 print(msg) 18 19 20 def sign_in(): 21 #学生进行注册 22 school_list = School.get_list() 23 for k, obj in enumerate(school_list): 24 print(k, obj, obj.addr) 25 sid = int(input(‘请选择您的学校: ‘)) 26 school_obj = school_list[sid] 27 print(school_obj.addr) 28 class_list = Classes.get_list() 29 for k, obj in enumerate(class_list): 30 if obj.school_nid.get_obj_uuid().addr == school_obj.addr: 31 print(k,obj.name) 32 cid = int(input(‘请选择您的班级: ‘)) 33 class_obj = class_list[cid] 34 name = input(‘请输入您的名字: ‘).strip() 35 passwd = input(‘请输入您的密码: ‘).strip() 36 student_name_list = [] 37 for obj in Student.get_list(): 38 student_name_list.append((obj.name,obj.classes_nid)) 39 if (name,class_obj.nid) in student_name_list: 40 print(‘学生已经存在!‘) 41 else: 42 student = Student(name,class_obj.nid,passwd) 43 student.save() 44 print(‘\033[33;1m[%s]注册成功\033[0m‘ %name) 45 46 def payment(): 47 #学生进行缴费 48 admin_sys.show_student() 49 print(‘---------------------------------‘) 50 name = input(‘请输入您的名字: ‘).strip() 51 passwd = input(‘请输入您的密码: ‘).strip() 52 student_list = Student.get_list() 53 for obj in student_list: 54 if obj.name == name and obj.password == passwd: 55 a = obj.classes_nid.get_obj_uuid().course_nid.get_obj_uuid().name 56 b = obj.classes_nid.get_obj_uuid().course_nid.get_obj_uuid().price 57 print(‘\033[33;1m您的课程为%s您需要支付的课程费用为%s\033[0m‘%(a,b)) 58 else: 59 exit(‘用户名密码不正确‘) 60 payprice = input(‘是否要交费(Y/N): ‘).strip() 61 if payprice == ‘Y‘: 62 print(‘交付成功!‘) 63 else: 64 print(‘退出成功!‘) 65 66 67 def choice_classes(): 68 #课程选择 69 school_list=[] 70 classes_list ={} 71 calsses_exist=[] 72 admin_sys.show_student() 73 print(‘---------------------------------‘) 74 name = input(‘请输入您的名字: ‘).strip() 75 passwd = input(‘请输入您的密码: ‘).strip() 76 student_list = Student.get_list() 77 for obj in student_list: 78 if obj.name == name and obj.password == passwd: 79 school_list.append(obj.classes_nid.get_obj_uuid().school_nid.get_obj_uuid().addr) 80 calsses_exist.append(obj.classes_nid.get_obj_uuid().name) 81 82 for (k,obj2) in enumerate(Classes.get_list()): 83 if obj2.school_nid.get_obj_uuid().addr ==school_list[0]: 84 classes_list[k] = obj2 85 print((k,obj2.name)) 86 choice=int(input(‘请输入您要选择的课程编号: ‘)) 87 if classes_list[choice].name in calsses_exist: 88 print(‘您已经课程已存在‘) 89 print(‘您现在所有的课程为:‘) 90 for i in calsses_exist: 91 print(i) 92 else: 93 student = Student(name, classes_list[choice].nid,passwd) 94 student.save() 95 print(‘\033[33;1m[%s]学生 成功选择[%s]课程\033[0m‘ % (name, classes_list[choice].nid)) 96 print(‘您现在所有的课程为:‘) 97 print(classes_list[choice].name) 98 for i in calsses_exist: 99 print(i) 100 101 102 103 104 105 106 107 108 def main(): 109 #主函数,调用其他函数 110 choice_dic={ 111 ‘0‘:show, 112 ‘1‘:sign_in , 113 ‘2‘:payment, 114 ‘3‘:choice_classes, 115 ‘4‘:exit 116 } 117 show() 118 while True: 119 choice=input(‘请输入选项: ‘).strip() 120 if choice not in choice_dic:continue 121 choice_dic[choice]() 122 123 124 def login(): 125 #登录函数 126 main()
student_sys
teacher_sys.py为老师的主逻辑
1 #!/usr/bin/env python 2 # coding=utf-8 3 #Author:yang 4 5 #讲师视图, 讲师可管理自己的班级, 上课时选择班级, 查看班级学员列表 , 修改所管理的学员的成绩 6 7 from lib.models import Student 8 from lib.models import School 9 from lib.models import Teacher 10 from lib.models import Course 11 from lib.models import Classes 12 from lib.models import Admin 13 from lib.models import Score 14 from core import admin_sys 15 teacher_name_list=[] 16 classes_name_list={} 17 18 def classes(func): 19 #装饰器,打印登录讲师的班级列表 20 def wapper(*args,**kwargs): 21 for (k,obj) in enumerate(Classes.get_list()): 22 if obj.teacher_nid.get_obj_uuid().name ==teacher_name_list[-1]: 23 classes_name_list[k]=obj.name 24 print(k,obj.name) 25 func(*args,**kwargs) 26 return wapper 27 28 @classes 29 def manage_classes(): 30 #可管理的班级,,但是并不知道要管理什么。。。 31 choice = int(input(‘请选择您要管理的班级编号:‘)) 32 33 34 35 @classes 36 def classes_list(): 37 #选择去上课的班级 38 choice = int(input(‘请选择您将要去上课的班级编号:‘)) 39 print(‘选择成功,您将去%s班级上课‘%classes_name_list[choice]) 40 @classes 41 def student_list(): 42 #打印班级下面的学生 43 choice = int(input(‘请选择您要查看学生的班级:‘)) 44 print(‘您班级下面的学生:‘) 45 for (k, obj) in enumerate(Student.get_list()): 46 if obj.classes_nid.get_obj_uuid().name == classes_name_list[choice]: 47 print(k,obj.name) 48 49 @classes 50 def sorce(): 51 #修改学生成绩 52 choice = int(input(‘请选择您要查看学生的班级:‘)) 53 print(‘您班级下面的学生:‘) 54 student_name_list = {} 55 students_list= {} 56 for (k, obj) in enumerate(Student.get_list()): 57 if obj.classes_nid.get_obj_uuid().name == classes_name_list[choice]: 58 student_name_list[k] = obj.name 59 students_list[obj.name] = obj 60 print(k, obj.name) 61 choice2 = int(input(‘请选择您要修改成绩的学生:‘)) 62 sorce = input(‘请输入成绩:‘) 63 sorce_student= students_list[student_name_list[choice2]].score 64 sorce_student.set(student_name_list[choice2],sorce) 65 print(‘成绩修改成功!‘) 66 sorce2 = sorce_student.get(student_name_list[choice2]) 67 print("%s该学生的成绩为%s"%(student_name_list[choice2],sorce2)) 68 69 70 71 72 73 def show(): 74 #打印选项 75 msg=‘‘‘ 76 0:选项 77 1:管理自己的班级 78 2:上课时选择班级 79 3:查看班级学生列表 80 4:修改成绩 81 5:退出 82 ‘‘‘ 83 print(msg) 84 85 86 87 def main(): 88 #teacher主函数,调用其他函数 89 choice_dic={ 90 ‘0‘:show, 91 ‘1‘:manage_classes, 92 ‘2‘:classes_list, 93 ‘3‘:student_list, 94 ‘4‘:sorce, 95 ‘5‘:exit 96 97 } 98 show() 99 while True: 100 choice=input(‘请输入选项: ‘).strip() 101 if choice not in choice_dic:continue 102 choice_dic[choice]() 103 104 105 def login(): 106 #验证登录 107 admin_sys.show_teacher() 108 username = input(‘请输入老师用户名:‘).strip() 109 password = input(‘请输入老师密码:‘).strip() 110 teacher_list = [] 111 for obj in Teacher.get_list(): 112 teacher_list.append((obj.name,obj.password)) 113 if (username, password) in teacher_list: 114 teacher_name_list.append(username) 115 print(‘登录成功!‘) 116 main() 117 else: 118 print(‘用户名密码无效!‘)
teacher_sys
在db里面存储了各个对象的数据
最后在lib里面,存放了类模块
common.py生成随机数来标记对应的对象
1 import random 2 def create_nid(): 3 #创建唯一id 4 code_list = [] 5 for i in range(3): 6 random_num = random.randint(0,9) 7 a = random.randint(97,122) 8 random_letter = chr(a) 9 code_list.append(str(random_num)) 10 code_list.append(random_letter) 11 create_id = ‘‘.join(code_list) 12 return create_id
common
identifier.py定义NID对象
1 #!/usr/bin/env python 2 # coding=utf-8 3 #Author:yang 4 from lib import common 5 import os,pickle 6 7 class Nid(object): 8 #id主类 9 def __init__(self,db_path): 10 self.uuid = common.create_nid() 11 self.db_path = db_path 12 def __str__(self): 13 return self.uuid 14 def get_obj_uuid(self): 15 #获取单独对象 16 for filename in os.listdir(self.db_path): 17 if filename == self.uuid: 18 return pickle.load(open(os.path.join(self.db_path,filename),‘rb‘)) 19 return None 20 21 22 23 class AdminNid(Nid): 24 #管理员id类 25 def __init__(self,db_path): 26 super(AdminNid,self).__init__(db_path) 27 28 class SchoolNid(Nid): 29 #学校id类 30 def __init__(self,db_path): 31 super(SchoolNid,self).__init__(db_path) 32 33 class TeacherNid(Nid): 34 #老师id类 35 def __init__(self,db_path): 36 super(TeacherNid,self).__init__(db_path) 37 38 class CourseNid(Nid): 39 #课程id类 40 def __init__(self,db_path): 41 super(CourseNid,self).__init__(db_path) 42 43 44 class ClassesNid(Nid): 45 #班级id类 46 def __init__(self,db_path): 47 super(ClassesNid,self).__init__(db_path) 48 49 class StudentNid(Nid): 50 #学生id类 51 def __init__(self,db_path): 52 super(StudentNid,self).__init__(db_path)
identifier
models.py定义真正的对象
1 #!/usr/bin/env python 2 # coding=utf-8 3 #Author:yang 4 import os,pickle 5 from conf import setting 6 from lib import identifier 7 8 class BaseModel(object): 9 #对象主类 10 def save(self): 11 file_path = os.path.join(self.db_path,str(self.nid)) 12 pickle.dump(self,open(file_path,‘wb‘)) 13 @classmethod 14 def get_list(cls): 15 #获取所有对象 16 ret=[] 17 for filename in os.listdir(cls.db_path): 18 file_path = os.path.join(cls.db_path,filename) 19 ret.append(pickle.load(open(file_path,‘rb‘))) 20 return ret 21 22 class Admin(BaseModel): 23 #管理员类 24 db_path = setting.ADMIN_DB_DIR 25 def __init__(self,username,password): 26 self.nid = identifier.AdminNid(self.db_path) 27 self.username = username 28 self.password = password 29 30 31 class School(BaseModel): 32 #学校类 33 db_path = setting.SCHOOL_DB_DIR 34 def __init__(self,name,addr): 35 self.nid = identifier.SchoolNid(self.db_path) 36 self.name = name 37 self.addr = addr 38 39 def __str__(self): 40 return self.name 41 42 class Teacher(BaseModel): 43 #老师类 44 db_path = setting.TEACHER_DB_DIR 45 def __init__(self, name,school_nid,password=‘123456‘): 46 self.nid = identifier.TeacherNid(self.db_path) 47 self.name = name 48 self.school_nid = school_nid 49 self.password = password 50 51 class Course(BaseModel): 52 #课程类 53 db_path=setting.COURSE_DB_DIR 54 def __init__(self,name,price,period,school_nid): 55 self.nid=identifier.CourseNid(self.db_path) 56 self.name=name 57 self.price=price 58 self.period=period 59 self.school_nid=school_nid 60 61 class Classes(BaseModel): 62 #班级类 63 db_path = setting.CLASSES_DB_DIR 64 def __init__(self, name,school_nid,teacher_nid,course_nid): 65 self.nid = identifier.ClassesNid(self.db_path) 66 self.name = name 67 self.school_nid=school_nid 68 self.teacher_nid = teacher_nid 69 self.course_nid = course_nid 70 71 class Score(object): 72 #成绩类 73 def __init__(self,nid): 74 self.nid=nid 75 self.score_dict={} 76 77 def set(self,student_name,number): 78 self.score_dict[student_name]=number 79 80 def get(self,student_name): 81 return self.score_dict[student_name] 82 83 class Student(BaseModel): 84 #学生类 85 db_path = setting.STUDENT_DB_DIR 86 def __init__(self,name,classes_nid,password=‘123456‘): 87 self.nid=identifier.StudentNid(self.db_path) 88 self.name=name 89 self.classes_nid=classes_nid 90 self.score=Score(self.nid) 91 self.password=password
models
程序存在些未知bug。。