2020-04-15 00:09:28

程序目录:

import os
BASE_PATH=os.path.dirname(os.path.dirname(__file__)) DB_PATH=os.path.join(BASE_PATH,'db')

settings.py

from interface import admin_interface
from lib import common
from interface import commin_interface user_info={
'user':None
}
# -管理员注册
def register():
while True:
username=input('>>:').strip()
pwd=input('>>:').strip()
re_pwd=input('>>:').strip()
if pwd == re_pwd:
flag,msg=admin_interface.register_interface(username,pwd)
if flag:
print(msg)
break
else:
print(msg)
else:
print('两次密码不一致')
# -管理员登录
def login():
while True:
username=input('>>:').strip()
pwd=input('>>:').strip()
flag,msg=commin_interface.login_interface(username,pwd,user_type='admin')
if flag:
user_info['user']=username
print(msg)
break
else:
print(msg)
# -创建学校
@common.auth('Admin')
def create_school():
while True:
school_name=input('>>:').strip()
school_address=input('>>:').strip()
flag,msg=admin_interface.crete_school_interface(school_name,school_address,user_info.get('user'))
if flag:
print(msg)
break
else:
print(msg) # -创建课程
@common.auth('Admin')
def create_class():
while True:
flag,school_list_msg=commin_interface.get_all_school_list()
if not flag:
print(school_list_msg)
break
for index,school_name in enumerate(school_list_msg):
print(f'编号:{index}名称:{school_name}')
choice=input('选择学校>>:').strip()
if not choice.isdigit():
print('请输入纯数字')
continue
choice=int(choice)
if choice not in range(len(school_list_msg)):
print('没有该编号')
continue
school_name=school_list_msg[choice]
course_name=input('创建课程名:').strip()
flag,msg=admin_interface.create_course_interface(school_name,course_name,user_info.get('user'))
if flag:
print(msg)
break
else:
print(msg) # -创建老师
@common.auth('Admin')
def create_teacher():
while True:
teacher_name=input('>>:').strip()
flag,msg=admin_interface.create_teacher_interface(teacher_name,user_info.get('user'))
if flag:
print(msg)
break
else:
print(msg) func_dic={
'':register,
'':login,
'':create_school,
'':create_class,
'':create_teacher,
}
def run():
while True:
print('''
1-管理员注册
2-管理员登录
3-创建学校
4-创建课程
5-创建老师
''')
choice=input('>>:').strip()
if choice == 'q':
user_info['user']=None
break
if choice not in func_dic:
continue func_dic.get(choice)()

admin.py

from core import admin
from core import student
from core import teacher func_dic={
'':admin.run,
'':student.run,
'':teacher.run, } def run():
while True:
print('''
1、管理员功能
2、学生功能
3、老师功能
''')
choice=input('>>:').strip()
if choice not in func_dic:
continue
func_dic.get(choice)()

src.py

from lib import common
from interface import student_interfacce
from interface import commin_interface
user_info={
'user':None
}
# -注册
def register():
while True:
username=input('>>:').strip()
pwd=input('>>:').strip()
re_pwd=input('>>:').strip()
if pwd == re_pwd:
flag,msg=student_interfacce.regisiter_interface(username,pwd)
if flag:
print(msg)
break
else:
print(msg)
# -登录
def login():
while True:
username=input('>>:').strip()
pwd=input('>>:').strip()
falg,msg=commin_interface.login_interface(username,pwd,user_type='student')
if falg:
user_info['user']=username
print(msg)
break
else:
print(msg)
# -选择校区
@common.auth('Student')
def choice_school():
while True:
#1.打印校区列表
flag,school_list=commin_interface.get_all_school_list()
if not flag:
print(school_list)
break
for index,school_name in enumerate(school_list):
print(f'编号{index}:学校名:{school_name}')
choice=input('>>:').strip()
if not choice.isdigit():
print('请输入纯数字')
continue
choice=int(choice)
if choice not in range(len(school_list)):
print('没有该编号')
continue
school_name=school_list[choice]
flag,msg=student_interfacce.choice_school(school_name,user_info.get('user'))
if flag:
print(msg)
break
else:
print(msg)
break # -选择课程
@common.auth('Student')
def choice_class():
while True:
#1获取学生选择的校区下的课程
flag,course_list=student_interfacce.get_school_course(user_info.get('user'))
if not flag:
print(course_list)
break
for index,course_name in enumerate(course_list):
print(f'编号:{index}课程名称:{course_name}')
choice=input('>>:').strip()
if not choice.isdigit():
print('请输入纯数字')
continue
choice=int(choice)
if choice not in range(len(course_list)):
print('没有该编号')
continue
course_name=course_list[choice]
flag,msg=student_interfacce.choice_course(course_name,user_info.get('user'))
if flag:
print(msg)
break
else:
print(msg) pass
# -查看成绩
@common.auth('Student')
def check_score():
flag,score_dic=student_interfacce.check_score(user_info.get('user'))
if flag:
print(score_dic)
else:
print(score_dic) func_dic={
'':register,
'':login,
'':choice_school,
'':choice_class,
'':check_score,
}
def run():
while True:
print('''
1-注册
2-登录
3-选择校区
4-选择班级
5-查看成绩
''')
choice=input('>>:').strip()
if choice == 'q':
user_info['user'] = None
break
if choice not in func_dic:
continue func_dic.get(choice)()

student.py

from lib import common
from interface import commin_interface
from interface import teacher_interface
user_info={
'user':None
}
# -登录
def login():
while True:
username=input('>>:').strip()
pwd=input('>>:').strip()
flag,msg=commin_interface.login_interface(username,pwd,user_type='teacher')
if flag:
user_info['user']=username
print(msg)
break
else:
print(msg)
# -查看教授课程
@common.auth('Teacher')
def check_course():
flag,course_list=teacher_interface.check_course_interface(user_info.get('user'))
if flag:
print(course_list)
else:
print(course_list)
# -选择教授课程
@common.auth('Teacher')
def choice_course():
while True:
#1.先选择校区
flag,school_list=commin_interface.get_all_school_list()
if not flag:
print(school_list)
break
for index,school_name in enumerate(school_list):
print(f'编号{index}:学校名:{school_name}')
choice=input('>>:').strip()
if not choice.isdigit():
print('请输入纯数字')
continue
choice=int(choice)
if choice not in range(len(school_list)):
print('没有该编号')
continue
school_name=school_list[choice]
#2.选择课程
flag,course_list=commin_interface.check_course(school_name)
if not flag:
print(course_list)
break
for index2,course_name in enumerate(course_list):
print(f'编号:{index2}课程名称:{course_name}')
choice2=input('>>:').strip()
if not choice2.isdigit():
print('请输入纯数字')
continue
choice2=int(choice2)
if choice2 not in range(len(course_list)):
print('没有该编号')
continue
course_name=course_list[choice2]
flag,msg=teacher_interface.choice_course_interface(course_name,user_info.get('user'))
if flag:
print(msg)
break
else:
print(msg)
# -查看课程学员
@common.auth('Teacher')
def check_student():
while True:
#1.先选择查看老师下的课程
flag,course_list=teacher_interface.check_course_interface(user_info.get('user'))
if not flag:
print(course_list)
break
for index,course_name in enumerate(course_list):
print(f'编号:{index}课程名:{course_name}')
choice=input('>>:').strip()
if not choice.isdigit():
print('请输入纯数字')
continue
choice=int(choice)
if choice not in range(len(course_list)):
print('没有该编号')
continue
course_name=course_list[choice]
#2.查看课程下的学生
flag1,student_list=teacher_interface.check_student_interface(course_name,user_info.get('user'))
if flag:
print(student_list)
break
else:
print(student_list)
# -修改学生成绩
@common.auth('Teacher')
def change_score():
while True:
# 1.先选择查看老师下的课程
flag, course_list = teacher_interface.check_course_interface(user_info.get('user'))
if not flag:
print(course_list)
break
for index, course_name in enumerate(course_list):
print(f'编号:{index}课程名:{course_name}')
choice = input('>>:').strip()
if not choice.isdigit():
print('请输入纯数字')
continue
choice = int(choice)
if choice not in range(len(course_list)):
print('没有该编号')
continue
course_name = course_list[choice]
# 2.查看课程下的学生
flag1, student_list = teacher_interface.check_student_interface(course_name, user_info.get('user'))
if not flag1:
print('该课程没有学生')
continue
for index,student_name in enumerate(student_list):
print(f'编号:{index}姓名:{student_name}')
choice=input('>>:').strip()
if not choice.isdigit():
print('请输入纯数字')
continue
choice=int(choice)
if choice not in range(len(student_list)):
print('没有该编号')
continue
student_name=student_list[choice]
score=input('修改后的分数:').strip()
msg=teacher_interface.change_score_interface(student_name,course_name,score,user_info.get('user'))
print(msg) func_dic={
'':login,
'':check_course,
'':choice_course,
'':check_student,
'':change_score,
}
def run():
while True:
print('''
1-登录
2-查看教授课程
3-选择教授课程
4-查看课程学员
5-修改学生成绩
''')
choice=input('>>:').strip()
if choice == 'q':
user_info['user'] = None
break
if choice not in func_dic:
continue func_dic.get(choice)()

teacher.py

from conf import settings
import os,pickle
def save(obj):
user_dir=os.path.join(settings.DB_PATH,obj.__class__.__name__)
if not os.path.exists(user_dir):
os.mkdir(user_dir)
user_path=os.path.join(user_dir,obj.name)
with open(user_path,'wb') as f:
pickle.dump(obj,f) def select(cls,name):
user_dir=os.path.join(settings.DB_PATH,cls.__name__)
user_path=os.path.join(user_dir,name)
if os.path.exists(user_path):
with open(user_path,'rb') as f:
obj=pickle.load(f)
return obj

db_handler.py

from db import db_handler

class Base:
def save(self):
db_handler.save(self)
@classmethod
def select(cls,name):
admin_obj=db_handler.select(cls,name)
return admin_obj
class Admin(Base):
def __init__(self,name,pwd):
self.name=name
self.pwd=pwd
def create_school(self,school_name,school_address):
school_obj=School(school_name,school_address)
school_obj.save()
def create_course(self,school_obj,course_name):
course_obj=Course(course_name)
course_obj.save()
school_obj.course_list.append(course_name)
school_obj.save()
def create_teacher(self,teacher_name,teacher_pwd):
teacher_obj=Teacher(teacher_name,teacher_pwd)
teacher_obj.save() class School(Base):
def __init__(self,name,address):
self.name=name
self.address=address
self.course_list=[] class Course(Base):
def __init__(self,name):
self.name=name
self.student_list=[]
class Student(Base):
def __init__(self,name,pwd):
self.name=name
self.pwd=pwd
self.school=None
self.course_list=[]
self.score_dic={}
def add_school(self,school_name):
self.school=school_name
self.save()
def add_course(self,course_name):
self.course_list.append(course_name)
self.save()
course_obj=Course(course_name)
course_obj.student_list.append(self.name)
course_obj.save()
self.score_dic[course_name]=0
self.save() class Teacher(Base):
def __init__(self,name,pwd):
self.name=name
self.pwd=pwd
self.course_list=[] def check_course(self):
return self.course_list def choice_course(self,course_name):
self.course_list.append(course_name)
self.save() def check_student(self,course_name):
course_obj=Course.select(course_name)
student_list=course_obj.student_list
return student_list def change_score(self,student_name,course_name,score,):
student_obj=Student.select(student_name)
student_obj.score_dic[course_name]=score
student_obj.save()

modles.py

from db import modles
#注册
def register_interface(username,pwd):
admin_obj=modles.Admin.select(username)
if admin_obj:
return False,'用户已存在'
admin_obj=modles.Admin(username,pwd)
admin_obj.save()
return True,'注册成功' def crete_school_interface(school_name,school_address,user):
school_obj=modles.School.select(school_name)
if school_obj:
return False,'该学校已存在'
admin_obj=modles.Admin.select(user)
admin_obj.create_school(school_name,school_address)
return True,'创建成功' def create_course_interface(school_name,course_name,user):
school_obj=modles.School.select(school_name)
if course_name in school_obj.course_list:
return False,'课程已存在'
admin_obj=modles.Admin.select(user)
admin_obj.create_course(school_obj,course_name)
return True,'创建成功' def create_teacher_interface(name,user,pwd=''):
teacher_obj=modles.Teacher.select(name)
if teacher_obj:
return False,'该老师已存在'
admin_obj=modles.Admin.select(user)
teacher_obj=admin_obj.create_teacher(name,pwd)
return True,'创建成功'

admin_interface.py

from conf import settings
import os
from db import modles
#获取所有学校列表
def get_all_school_list():
school_path=os.path.join(settings.DB_PATH,'School')
if os.path.exists(school_path):
school_list=os.listdir(school_path)
return True,school_list
return False,'没有学校' #所有用户登录功能
def login_interface(name,pwd,user_type):
if user_type == 'admin':
obj=modles.Admin.select(name)
elif user_type == 'student':
obj=modles.Student.select(name)
elif user_type == 'teacher':
obj=modles.Teacher.select(name)
else:
return False,'没有权限'
if obj:
if pwd == obj.pwd:
return True,'登录成功'
return False,'密码错误'
return False,'用户不存在' #查看课程接口
def check_course(school_name):
school_obj=modles.School.select(school_name)
course_list=school_obj.course_list
if course_list:
return True,course_list
return False,'没有课程,请联系管理员'

common_interface.py

from db import modles
#注册接口
def regisiter_interface(username,pwd):
student_obj=modles.Student.select(username)
if student_obj:
return False,'该用户已存在'
student_obj=modles.Student(username,pwd)
student_obj.save()
return True,'注册成功' #选择校区接口
def choice_school(school_name,student_name):
student_obj=modles.Student.select(student_name)
if student_obj.school:
return False,'已选择学校'
student_obj.add_school(school_name)
return True,'选择学校成功' #选择课程接口
def choice_course(course_name,student_name):
student_obj=modles.Student.select(student_name)
if course_name in student_obj.course_list:
return False,'该课程已存在'
student_obj.add_course(course_name)
return True,'选择课程成功' #查看分数接口
def check_score(student_name):
student_obj=modles.Student.select(student_name)
score_dic=student_obj.score_dic
if score_dic:
return True,score_dic
return False,'没有成绩,联系老师' #获取学生已选择的校区下的课程
def get_school_course(student_name):
student_obj=modles.Student.select(student_name)
school_name=student_obj.school
school_obj=modles.School.select(school_name)
course_list=school_obj.course_list
if course_list:
return True,course_list
return False,'该学校没有课程'

student_interface.py

from db import modles

#查看课程列表接口
def check_course_interface(teacher_name):
teacher_obj=modles.Teacher.select(teacher_name)
course_list=teacher_obj.check_course()
if course_list:
return True,course_list
return False,'没有课程' #选择课程接口
def choice_course_interface(course_name,teacher_name):
teacher_obj=modles.Teacher.select(teacher_name)
course_list=teacher_obj.course_list
if course_name in course_list:
return False,'该课程已存在'
teacher_obj.choice_course(course_name)
return True,'选择课程成功' #查看课程下的学生接口
def check_student_interface(course_name,teacher_name):
teacher_obj=modles.Teacher.select(teacher_name)
student_list=teacher_obj.check_student(course_name)
if student_list:
return True,student_list
return False,'该课程没有学生' #修改学生分数接口
def change_score_interface(student_name,course_name,score,teacher_name):
teacher_obj=modles.Teacher.select(teacher_name)
teacher_obj.change_score(student_name,course_name,score,)
return '修改成功'

teacher_interface.py

# 登录认证装饰器
def auth(role):
def login_auth(func):
from core import admin,student,teacher
def inner(*args,**kwargs):
if role == 'Admin':
if admin.user_info.get('user'):
res=func(*args,**kwargs)
return res
else:
print('请登录,再进行操作')
admin.login()
func()
if role == 'Student':
if student.user_info.get('user'):
res=func(*args,**kwargs)
return res
else:
print('请登录,再进行操作')
student.login()
func()
if role == 'Teacher':
if teacher.user_info.get('user'):
res=func(*args,**kwargs)
return res
else:
print('请登录,再进行操作')
teacher.login()
func()
return inner
return login_auth

common.py

#软件使用说明
本周作业:综合应用面向对象 角色:学校、学员、课程、讲师
要求:
1. 创建北京、上海 2 所学校
2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开
3. 课程包含,周期,价格,通过学校创建课程
4. 通过学校创建班级, 班级关联课程、讲师
5. 创建学员时,选择学校,关联班级
5. 创建讲师角色时要关联学校,
6. 提供两个角色接口
6.1 学员视图, 可以注册, 交学费, 选择班级,
6.2 讲师视图, 讲师可管理自己的班级, 上课时选择班级, 查看班级学员列表 , 修改所管理的学员的成绩
6.3 管理视图,创建讲师, 创建班级,创建课程 7. 上面的操作产生的数据都通过pickle序列化保存到文件里 -需求分析
-管理员视图
-管理员注册
-管理员登录
-创建学校
-创建班级
-创建课程
-创建老师
-学生视图
-注册
-登录
-选择校区
-选择班级
-交学费
-查看成绩
-老师视图
-登录
-查看教授课程
-选择教授课程
-查看课程学员
-修改学生成绩
-项目的架构设计
三层架构
-视图层
-core
-src.py主视图
-admin.py管理员视图
-student.py学生视图
-teacher.py老师视图
-接口层
-interface
-admin_interface.py管理员接口
-student_interface.py学生接口
-teacher_interface.py老师接口 -数据处理层
-db
-modles.py 存放类
-da_handler.py保存\查看数据 3.分任务开发
4.测试
5.上线

readme.md

import os,sys
sys.path.append(os.path.dirname(__file__)) from core import src
if __name__ == '__main__':
src.run()

start.py

 

选课系统<基于面向过程\对象>的更多相关文章

  1. 【二十】mysqli基于面向过程与面向对象的编程

    面向过程的方式 musqli扩展库操作mysql数据库步骤: 1.获取连接并选择数据库 //语法 mysqli_connect(host,username,password,dbname,port,s ...

  2. 简单的学生选课系统——基于Servlet+Ajax

    以前挖的坑,早晚要往里掉.基础太薄弱,要恶补.在此程序前,我还对Servlet没有一个清晰的概念:一周时间写好此程序之后,对Servlet的理解清晰许多. 这周一直在恶补Spring,今天正好完成了S ...

  3. python全栈开发-Day11 迭代器、生成器、面向过程编程

    一. 迭代器 一 .迭代的概念 迭代器即迭代的工具,那什么是迭代呢? 迭代是一个重复的过程,每次重复即一次迭代,并且每次迭代的结果都是下一次迭代的初始值 while True: #只是单纯地重复,因而 ...

  4. Python之路【第六篇】:Python迭代器、生成器、面向过程编程

    阅读目录 一.迭代器 1.迭代的概念 #迭代器即迭代的工具,那什么是迭代呢? #迭代是一个重复的过程,每次重复即一次迭代,并且每次迭代的结果都是下一次迭代的初始值 代码如下: while True: ...

  5. 为什么大一先要学C语言(面向过程)再学C++或JAVA(面向对象)?

    面向对象和面向过程各有千秋 一.面向过程与面向对象对比  面向过程:强调的是每一个功能的步骤,有很多很多方法组成,这些方法相互调用,完成需求. 面向对象:强调的是对象,然后由对象去调用功能. 面向过程 ...

  6. python之迭代器、生成器、面向过程编程

    一 迭代器 一 迭代的概念 #迭代器即迭代的工具,那什么是迭代呢?#迭代是一个重复的过程,每次重复即一次迭代,并且每次迭代的结果都是下一次迭代的初始值 while True: #只是单纯地重复,因而不 ...

  7. python基础知识14---迭代器、生成器、面向过程编程

    阅读目录 一 迭代器 二 生成器 三 面向过程编程 一 迭代器 1 迭代的概念 #迭代器即迭代的工具,那什么是迭代呢? #迭代是一个重复的过程,每次重复即一次迭代,并且每次迭代的结果都是下一次迭代的初 ...

  8. PYTHON-匿名函数,递归与二分法,面向过程编程

    """匿名函数1 什么是匿名函数 def定义的是有名函数:特点是可以通过名字重复调用 def func(): #func=函数的内存地址 pass 匿名函数就是没有名字的 ...

  9. python之旅:迭代器、生成器、面向过程编程

    1.什么是迭代器? 1.什么是迭代器 迭代的工具 什么是迭代? 迭代是一个重复的过程,每一次重复都是基于上一次结果而进行的 # 单纯的重复并不是迭代 while True: print('=====& ...

随机推荐

  1. kvm的命令简单使用

    virsh命令常用参数总结   参数 参数说明 基础操作 list 查看虚拟机列表,列出域 start 启动虚拟机,开始一个(以前定义的)非活跃的域 shutdown 关闭虚拟机,关闭一个域 dest ...

  2. 了解JSON Web令牌(JWT)

    JSON Web Token(JWT)是目前最流行的跨域身份验证解决方案. (一) 跨域身份验证 Internet服务无法与用户身份验证分开. 用户向服务器发送用户名和密码. 验证服务器后,相关数据( ...

  3. DeDecms远程写入漏洞webshell (dedecms漏洞)

    解释下Apache解析文件的流程: 当Apache检测到一个文件有多个扩展名时,如1.php.bak,会从右向左判断,直到有一个Apache认识的扩展名.如果所有的扩展名Apache都不认识,那么变会 ...

  4. SpringBoot后端系统的基础架构

    前言 前段时间完成了毕业设计课题--<基于Spring Boot + Vue的直播后台管理系统>,项目名为LBMS,主要完成了对直播平台数据的可视化展示和分级的权限管理.虽然相当顺利地通过 ...

  5. 2019-02-08 Python学习之Scrapy的简单了解

    今天遇到的问题和昨天差不多,一个Scrapy装了好久,anaconda卸了又装,pycharm卸了又装,环境变量配置一堆,依赖包下载一堆.查了一堆资料总算是搞好了. Scripy: 先放个框架结构图( ...

  6. numpy.stack和numpy.concatenate的区别

    在使用numpy进行矩阵运算的时候踩到的坑,原因是不能正确区分numpy.concatenate和numpy.stack在功能上的差异. 先说numpy.concatenate,直接看文档: nump ...

  7. 几种颜色模型(颜色空间):HSV CMYK RGB

    RGB和CMY颜色模型都是面向硬件的,而HSV(Hue Saturation Value)颜色模型是面向用户的. HSV(Hue, Saturation, Value)是根据颜色的直观特性由A. R. ...

  8. 使用Bundle在Activity中交换数据

    大概过程 编写demo activity_main.xml <?xml version="1.0" encoding="utf-8"?> <R ...

  9. Activity学习笔记1

    Activity概述 简单的理解Activity就是指Android手机或平板的一个屏,类似Window的一个窗口,浏览器的一个页面. Activity的4种状态 Activity的生命周期 创建Ac ...

  10. cb08a_c++_顺序容器的操作1

    cb08a_c++_顺序容器的操作1容器定义的类型别名begin(闭区间)和end(开区间)成员{first,last)左闭右开,左包括,右不包括,end()指向最后一个的下一个. /*cb08a_c ...