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. 读懂操作系统之缓存原理(cache)(三)

    前言 本节内容计划是讲解TLB与高速缓存的关系,但是在涉及高速缓的前提是我们必须要了解操作系统缓存原理,所以提前先详细了解下缓存原理,我们依然是采取循序渐进的方式来解答缓存原理,若有叙述不当之处,还请 ...

  2. 提高网站访问性能之Tomcat优化

    一.前言 tomcat 服务器在JavaEE项目中使用率非常高,所以在生产环境对tomcat的优化也变得非常重要了,对于tomcat的优化,主要是从2个方面入手,一是tomcat本身的配置,另一个是t ...

  3. https绕过证书认证请求 Get或Post请求(证书过期,忽略证书)

    报错信息 解决: postman方式 java请求 报错信息 javax.net.ssl.SSLHandshakeException: sun.security.validator.Validator ...

  4. PyQt5中QTableView函数讲解

    如果想熟悉QTableWidget,请参考PyQt5高级界面控件之QTableWidget(四) setSpan(int, int, int, int)四个参数分别代表,起始行,列,合并的行数,全并的 ...

  5. centos7 hadoop 单机模式安装配置

    前言 由于现在要用spark,而学习spark会和hdfs和hive打交道,之前在公司服务器配的分布式集群,离开公司之后,自己就不能用了,后来用ambari搭的三台虚拟机的集群太卡了,所以就上网查了一 ...

  6. 在IntelliJ IDEA中注释使用的说明

    /** * @author 标明该类模块的开发作者 * @version 标明该类模块的版本 * @see 参开转向,也就是相关的主题 * @param 对方法中的某些参数进行说明 * @return ...

  7. php 判断设备是手机还是平板还是pc

    1 <?php 2 //获取USER AGENT 3 $agent = strtolower($_SERVER['HTTP_USER_AGENT']); 4 5 //分析数据 6 $is_pc ...

  8. Java学习笔记6(集合类)

    集合类 集合按照其存储结构可以分为两大类,即单列集合Collection和双列集合Map. Collection:单列集合类的根接口,用于存储一系列符合某种规则的元素,有List和Set两个重要子接口 ...

  9. Beta冲刺--冲刺总结

    这个作业属于哪个课程 软件工程 (福州大学至诚学院 - 计算机工程系) 这个作业要求在哪里 Beta 冲刺 这个作业的目标 Beta冲刺--冲刺总结 作业正文 如下 其他参考文献 ... Beta冲刺 ...

  10. debug PostgreSQL 9.6.18 using Eclipse IDE on CentOS7

    目录 debug PostgreSQL 9.6.18 using Eclipse IDE on CentOS7 1.概览 2.建立用户 3.编译postgre 4.启动Eclipse 5.设置环境变量 ...