作业需求:

用户角色,讲师\学员, 用户登陆后根据角色不同,能做的事情不同,分别如下

讲师视图

  管理班级,可创建班级,根据学员qq号把学员加入班级

  可创建指定班级的上课纪录,注意一节上课纪录对应多条学员的上课纪录, 即每节课都有整班学员上, 为了纪录每位学员的学习成绩,需在创建每节上课纪录是,同时 为这个班的每位学员创建一条上课纪录

  为学员批改成绩, 一条一条的手动修改成绩

学员视图

提交作业

查看作业成绩

一个学员可以同时属于多个班级,就像报了Linux的同时也可以报名Python一样, 所以提交作业时需先选择班级,再选择具体上课的节数

附加:学员可以查看自己的班级成绩排名

数据库关联示意图:

思路解析:

按照数据库关联,操作班级教室分数和上课记录

讲师视图
1.管理班级,可创建班级
  操作class表,输入classname后显示现在有几个课程几个课程表,然后让讲师创建TeacheCourse关联后才能创建班级
2. 根据学员qq号把学员加入班级
  操作StudentTeachClass表,把qq号加入班级ID,然后显示,课程,课程表,班级,学员,
3. 可创建指定班级的上课纪录,注意一节上课纪录对应多条学员的上课纪录,即每节课都有整班学员上,为了纪录每位学员的学习成绩,需在创建每节上课纪录,同时为这个班的每位学员创建一条上课纪录
  进入后显示班级,根据进入时候的班级讲师ID,操作teacherclass,操作teacher_course,找到对应的学生查看对应的班级的童鞋,操作RecordStudent
4. 为学员批改成绩, 一条一条的手动修改成绩
  1. 进入后显示班级,根据进入时候的班级讲师ID,操作teacherclass,操作teacher_course,
  2. 查看StudentHomework,查看学生的作业
  3. 为学员一条一条修改成绩和创建上课记录,操作RecordScore
学员视图
1. 提交作业
  显示课程,班级,上课节数,提交作业,做成绑定
2. 查看作业成绩
  查看RecordScore
3. 一个学员可以同时属于多个班级,就像报了Linux的同时也可以报名Python一样, 所以提交作业时需先选择班级,再选择具体上课的节数
4. 附加:学员可以查看自己的班级成绩排名
  操作recordscore
  排名,读取出所有的成绩和姓名,然后进行排序

Readme:

作者:yaobin

版本: 学员管理系统 示例版本 v0.1

开发环境: python3.6

程序介绍:

讲师视图

  管理班级,可创建班级,根据学员qq号把学员加入班级
  可创建指定班级的上课纪录,注意一节上课纪录对应多条学员的上课纪录, 即每节课都有整班学员上,
为了纪录每位学员的学习成绩,需在创建每节上课纪录是,同时为这个班的每位学员创建一条上课纪录
  为学员批改成绩, 一条一条的手动修改成绩 学员视图 提交作业
查看作业成绩
一个学员可以同时属于多个班级,就像报了Linux的同时也可以报名Python一样, 所以提交作业时需先选择班级,再选择具体上课的节数
附加:学员可以查看自己的班级成绩排名 文件目录结构 ├── bin
│   ├── __init__.py
│   └── tiny.py # 主程序
├── conf
│   ├── action_registers.py # 程序命令交互
│   ├── __init__.py
│   └── settings.py # 配置文件
├── log
│   └── __init__.py
├── modules
│   ├── actions.py # 欢迎页和程序命令交互
│   ├── db_conn.py # mysql连接交互
│   ├── utils.py # yaml配置交互
│   └── views.py # 创建表,表数据创建,查看数据库数据交互
│   └── db_insert.py # 插入数据范例
├── Server.zip
└── share
└── examples
├── new_bindhosts.yml # 主机绑定关系配置文件
├── new_groups.yml # 组创建,组关系绑定配置文件
├── new_hosts.yml # 主机配置文件
├── new_remoteusers.yml # 主机用户名密码配置文件
└── new_user.yml # 堡垒机用户配置文件

使用方法:

python3 bin/manage.py syncdb
python3 modules/db_insert.py
python3 bin/manage.py teacher
python3 bin/manage.py student

核心代码:

view.py

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Time:2017/12/15 21:34
__Author__ = 'Sean Yao'
import sqlalchemy.exc
from modules import models
from conf import settings
from modules.utils import print_err, yaml_parser
from modules.db_conn import engine, session
import codecs def syncdb(argvs):
'''
创建表结构方法
:param argvs:
:return:
'''
print("Syncing DB....")
engine = models.create_engine(settings.ConnParams, echo=True)
models.Base.metadata.create_all(engine) # 创建所有表结构 def auth_teacher():
'''
用户验证
do the user login authentication
:return:
'''
count = 0
while count < 3:
username = input("\033[32;1mUsername:\033[0m").strip()
if len(username) == 0:
continue
password = input("\033[32;1mPassword:\033[0m").strip()
if len(password) == 0:
continue
user_obj = session.query(models.Teacher).filter(models.Teacher.username == username,
models.Teacher.password == password).first()
if user_obj:
return user_obj
else:
print("wrong username or password, you have %s more chances." % (3-count-1))
count += 1
else:
print_err("too many attempts.") def auth_student():
'''
用户验证
do the user login authentication
:return:
'''
count = 0
while count < 3:
username = input("\033[32;1mUsername:\033[0m").strip()
if len(username) == 0:
continue
password = input("\033[32;1mPassword:\033[0m").strip()
if len(password) == 0:
continue
user_obj = session.query(models.Student).filter(models.Student.username == username,
models.Student.password == password).first()
if user_obj:
return user_obj
else:
print("wrong username or password, you have %s more chances." % (3-count-1))
count += 1
else:
print_err("too many attempts.") def list1(dict: dict):
''' 将字典转化为列表 '''
keys = dict.keys()
vals = dict.values()
list = [(key, val) for key, val in zip(keys, vals)]
return list def welcome_msg(user):
'''
:param user:
:return:
'''
WELCOME_MSG = '''\033[32;1m
------------- Welcome [%s] login -------------
\033[0m''' % user.username
print(WELCOME_MSG) def show_class(user):
'''
show教室
:param user:
:return:
'''
print('%s 请参照现有课程教室管理' % user.username)
data = session.query(models.ClassRoom).filter_by().all()
print('所有班级')
for index, x in enumerate(data):
print(index, x.classname) def show_course(user):
'''
展示课程,课程安排,教室
:param user:
:return:
'''
print('你可以创建班级关系或给学生分配班级')
teacher_class_obj = session.query(models.TeacherClass).filter_by(teacher_id=user.id).all()
for i in teacher_class_obj:
course_teacher_obj = session.query(models.TeacheCourse).filter_by(bind_teacher_class_id=i.id).all()
for x in course_teacher_obj:
time_course_obj = session.query(models.CourseClassRecord).filter_by(id=x.bind_course_time_id).first()
print('课堂ID: %s 课程:%s 课程安排:%s 教室:%s' % (x.id, time_course_obj.course.coursename,
time_course_obj.course_time.course_time_name,
i.class_room.classname)) def show_student_class(user):
print('%s 你所在的班级' % user.username)
student_class_obj = session.query(models.StudentTeachClass).filter_by(student_qq=user.qq_number).all()
for i in student_class_obj:
class_teacher_obj = session.query(models.TeacherClass).filter_by(
id=i.teacher_course.bind_teacher_class_id).first()
course_obj = session.query(models.CourseClassRecord).filter_by(
id=i.teacher_course.bind_course_time_id).first()
studentname_obj = session.query(models.Student).filter_by(
qq_number=i.student.qq_number).first()
print('绑定id:%s 课程:%s 课程时间:%s 讲师:%s 教室:%s 学生名:%s 学生qq %s' % (
i.id, course_obj.course.coursename, course_obj.course_time.course_time_name,
class_teacher_obj.teacher.username, class_teacher_obj.class_room.classname,
studentname_obj.username, studentname_obj.qq_number)) def view_student():
'''
查看学生
'''
student_obj = session.query(models.Student).filter_by().all()
for i in student_obj:
# 学生姓名QQ
print('现有学生:%s 学生QQ:%s' % (i.username, i.qq_number))
print("----------- END -----------") def view_student_class(user):
'''
查看该教室的学生,通过学生和老师id反查
:param user:
:return:
'''
teacher_class_obj = session.query(models.TeacherClass).filter_by(teacher_id=user.id).all()
for i in teacher_class_obj:
teachecourse_obj = session.query(
models.TeacheCourse).filter_by(bind_teacher_class_id=i.id).all()
for y in teachecourse_obj:
student_teachclass_obj = session.query(models.StudentTeachClass).filter_by(teacher_course_id=y.id).all()
for x in student_teachclass_obj:
class_teacher_obj = session.query(models.TeacherClass).filter_by(
id=x.teacher_course.bind_teacher_class_id).first()
course_obj = session.query(models.CourseClassRecord).filter_by(
id=x.teacher_course.bind_course_time_id).first()
studentname_obj = session.query(models.Student).filter_by(
qq_number=x.student.qq_number).first()
print('绑定id:%s 课程:%s 课程时间:%s 讲师:%s 教室:%s 学生名:%s 学生qq %s' % (
x.id, course_obj.course.coursename, course_obj.course_time.course_time_name,
class_teacher_obj.teacher.username, class_teacher_obj.class_room.classname,
studentname_obj.username, studentname_obj.qq_number)) def view_record(user):
'''
查看上课记录
:param user:
:return:
'''
record_student = session.query(models.RecordStudent).filter_by().all()
for i in record_student:
student_teachclass_obj = session.query(models.StudentTeachClass). \
filter_by(id=i.student_teach_class_id).first()
class_teacher_obj = session.query(models.TeacherClass).filter_by(
id=student_teachclass_obj.teacher_course.bind_teacher_class_id).first()
course_obj = session.query(models.CourseClassRecord).filter_by(
id=student_teachclass_obj.teacher_course.bind_course_time_id).first()
studentname_obj = session.query(models.Student).filter_by(
qq_number=student_teachclass_obj.student.qq_number).first()
if class_teacher_obj.teacher.username == user.username:
print('绑定id:%s 课程:%s 课程时间:%s 讲师:%s 教室:%s 学生名:%s 学生qq %s 上课记录:%s' % (
student_teachclass_obj.id, course_obj.course.coursename, course_obj.course_time.course_time_name,
class_teacher_obj.teacher.username, class_teacher_obj.class_room.classname,
studentname_obj.username, studentname_obj.qq_number, i.record.record)) def view_homework(user):
'''
查看作业
:param user:
:return:
'''
record_student = session.query(models.RecordStudent).filter_by().all()
for i in record_student:
student_teachclass_obj = session.query(models.StudentTeachClass). \
filter_by(id=i.student_teach_class_id).first()
class_teacher_obj = session.query(models.TeacherClass).filter_by(
id=student_teachclass_obj.teacher_course.bind_teacher_class_id).first()
course_obj = session.query(models.CourseClassRecord).filter_by(
id=student_teachclass_obj.teacher_course.bind_course_time_id).first()
studentname_obj = session.query(models.Student).filter_by(
qq_number=student_teachclass_obj.student.qq_number).first()
studenthomework_obj = session.query(models.StudentHomework).filter_by(
student_teach_class_id=i.student_teach_class_id).first()
if studenthomework_obj:
if class_teacher_obj.teacher.username == user.username:
print('绑定ID %s 课程:%s 课程时间:%s 讲师:%s 教室:%s 学生名:%s 学生qq %s 上课记录:%s 作业:%s' % (
student_teachclass_obj.id, course_obj.course.coursename, course_obj.course_time.course_time_name,
class_teacher_obj.teacher.username, class_teacher_obj.class_room.classname,
studentname_obj.username, studentname_obj.qq_number, i.record.record,
studenthomework_obj.homework.home_work)) def view_score(user):
'''
查看分数
:param user:
:return:
'''
record_student = session.query(models.RecordStudent).filter_by().all()
for i in record_student:
student_teachclass_obj = session.query(models.StudentTeachClass). \
filter_by(id=i.student_teach_class_id).first()
class_teacher_obj = session.query(models.TeacherClass).filter_by(
id=student_teachclass_obj.teacher_course.bind_teacher_class_id).first()
course_obj = session.query(models.CourseClassRecord).filter_by(
id=student_teachclass_obj.teacher_course.bind_course_time_id).first()
studentname_obj = session.query(models.Student).filter_by(
qq_number=student_teachclass_obj.student.qq_number).first()
studenthomework_obj = session.query(models.StudentHomework).filter_by(
student_teach_class_id=i.student_teach_class_id).first()
score_obj = session.query(models.RecordScore).filter_by(student_teach_class_id=i.student_teach_class_id).first()
if studenthomework_obj:
if score_obj:
if class_teacher_obj.teacher.username == user.username:
if score_obj.student_teacher_class.student.qq_number == studentname_obj.qq_number:
print('绑定ID %s 课程:%s 课程时间:%s 讲师:%s 教室:%s 学生名:%s 学生qq %s 上课记录:%s 作业:%s 分数:%s'
% (student_teachclass_obj.id, course_obj.course.coursename,
course_obj.course_time.course_time_name, class_teacher_obj.teacher.username,
class_teacher_obj.class_room.classname, studentname_obj.username,
studentname_obj.qq_number, i.record.record, studenthomework_obj.homework.home_work,
score_obj.score.score)) def teacher(argvs):
'''
讲师视图
:param argvs:
:return:
'''
user = auth_teacher()
if user:
welcome_msg(user)
exit_flag = False
while not exit_flag:
show_class(user)
show_course(user)
msg = '''
1) 创建班级
2)添加学员到班级
3)上课记录
4)批改成绩
5)添加学员
'''
print(msg)
while not exit_flag:
user_option = input("[ (q)quit, select num to manage]:").strip()
if len(user_option) == 0:
continue
if user_option == 'q':
exit_flag = True
if user_option == '':
course_name = input('请输入班级上的课程>>>>: ')
if len(course_name) == 0:
print('sorry...班级不能为空')
break
else:
course_time = input('请输入课程时间安排>>>>:')
if len(course_time) == 0:
print('sorry...课程时间不能为空')
break
else:
class_name = input('请输入班级名称>>>:')
if len(class_name) == 0:
print('sorry...班级名称不能为空')
break
# 课程名
course_name_obj = session.query(models.Course).filter_by(coursename=course_name).first()
# 课程安排
course_time_obj = session.query(models.CourseTime).filter_by(course_time_name=course_time).first()
# 教室名
class_name_obj = session.query(models.ClassRoom).filter_by(classname=class_name).first()
# 添加课程
if course_name_obj:
pass
else:
course_name_db_obj = models.Course(coursename=course_name)
session.add(course_name_db_obj)
session.commit()
# 添加课程安排
if course_time_obj:
pass
else:
course_time_db_obj = models.CourseTime(course_time_name=course_time)
session.add(course_time_db_obj)
session.commit()
if class_name_obj:
pass
else:
class_name_db_obj = models.ClassRoom(classname=class_name)
session.add(class_name_db_obj)
session.commit() course_name = session.query(models.Course).filter_by(coursename=course_name).first()
course_time = session.query(models.CourseTime).filter_by(course_time_name=course_time).first()
class_name = session.query(models.ClassRoom).filter_by(classname=class_name).first() # 创建课程课程时间关联
course_class_record_id_obj = session.query(models.CourseClassRecord).filter_by(
course_id=course_name.id).filter_by(course_time_id=course_time.id).all()
if course_class_record_id_obj:
pass
else:
course_class_record_id_obj = models.CourseClassRecord(course_id=course_name.id,
course_time_id=course_time.id)
session.add(course_class_record_id_obj)
session.commit() # 添加讲师教室关联
teacher_class_id_obj = session.query(models.TeacherClass).filter_by(
teacher_id=user.id).filter_by(class_room_id=class_name.id).all()
if teacher_class_id_obj:
pass
else:
teacher_class_id_obj = models.TeacherClass(teacher_id=user.id, class_room_id=class_name.id)
session.add(teacher_class_id_obj)
session.commit() # 查老师的对象
db_teacher_obj = session.query(models.Teacher).filter_by(id=user.id).first()
# 查课程对象
db_course_name_obj = session.query(models.Course).filter_by(
coursename=course_name.coursename).first()
# 查课程安排对象
db_course_time_obj = session.query(models.CourseTime). \
filter_by(course_time_name=course_time.course_time_name).first()
# 查教室对象
db_class_obj = session.query(models.ClassRoom).filter_by(classname=class_name.classname).first() # 教室讲师关联对象
db_teacher_class_obj = session.query(models.TeacherClass).filter_by(
class_room_id=db_class_obj.id).filter_by(teacher_id=user.id).first()
# 课程课程安排关联对象
db_course_class_obj = session.query(models.CourseClassRecord).filter_by(
course_id=db_course_name_obj.id).filter_by(course_time_id=db_course_time_obj.id).first() if db_teacher_class_obj and db_course_class_obj:
teacher_class = session.query(models.TeacheCourse).filter_by(
bind_teacher_class_id=db_teacher_class_obj.id).filter_by(
bind_course_time_id=db_course_class_obj.id).all()
if teacher_class:
print('班级已经关联了')
else:
teachecourse = models.TeacheCourse(bind_teacher_class_id=db_teacher_class_obj.id,
bind_course_time_id=db_course_class_obj.id)
session.add(teachecourse)
session.commit()
print('班级创建完毕')
show_course(user) elif user_option == '':
view_student()
view_student_class(user)
show_course(user)
add_choice = input('[ (y)是,(n)否, select num to manage]:').strip()
if add_choice == 'n':
break
elif add_choice == 'y':
teacher_input_qq = input('请输入学员QQ号>>>: ')
teacher_input_courseid = input('请输入课堂ID>>>:')
try:
qq = int(teacher_input_qq)
courseid = int(teacher_input_courseid)
except ValueError:
print('qq或课堂ID必须是数字')
break
student_teachclass_check_obj = session.query(
models.StudentTeachClass).filter_by(
teacher_course_id=teacher_input_courseid).filter_by(student_qq=teacher_input_qq).all()
if student_teachclass_check_obj:
print('学生已经在班级里了....')
else:
student_obj = session.query(models.Student).filter_by(qq_number=qq).all()
if student_obj:
for i in student_obj:
if teacher_input_qq == str(i.qq_number):
student_class_obj = models.StudentTeachClass(
teacher_course_id=courseid, student_qq=qq)
session.add(student_class_obj)
session.commit()
view_student_class(user)
else:
print('没有这个学生')
else:
print('no this option') elif user_option == '':
print('\n%s 管理的班级学员\n' % user.username)
view_student_class(user)
print('\n%s 管理的班级的上课记录\n' % user.username)
view_record(user)
record_choice = input('[ (y)是,(n)否, select num to manage]:').strip()
if record_choice == 'n':
break
elif record_choice == 'y':
record_id_input = input('请输入绑定id添加学员上课记录:')
# 插入绑定关系
record_input = input('[ 请输入学员上课记录(y)yes,(no)否]')
try:
courseid = int(record_id_input)
except ValueError:
print('绑定ID必须是数字')
break
if record_input == 'yes' or 'no':
record_in_obj = session.query(
models.RecordStudent).filter_by(student_teach_class_id=record_id_input).all()
if record_in_obj:
print('记录已经添加...')
else:
record_in_obj = session.query(models.Record).filter_by(record=record_input).first()
student_teachclass_id_obj = models.RecordStudent(
student_teach_class_id=record_id_input, record_id=record_in_obj.id)
session.add(student_teachclass_id_obj)
session.commit()
view_record(user)
else:
print('no this option') elif user_option == '':
print('\n%s 管理的班级的上课记录\n' % user.username)
view_record(user)
print('\n已交作业的童鞋\n')
view_homework(user)
print('\n已批改的成绩\n')
view_score(user)
choice_score_input = input('[ 批改成绩是否继续(y)是,(n)否, select num to manage]:').strip()
if choice_score_input == 'n':
break
elif choice_score_input == 'y':
while not exit_flag:
record_id_input = input('请输入显示的绑定id添加学员成绩:')
score_input = input('请输入分数..')
# 插入绑定关系
home_work_check = session.query(
models.StudentHomework).filter_by(student_teach_class_id=int(record_id_input)).all()
if home_work_check:
score = int(score_input)
if score > 100 or score < 0:
print('请输入100以内的整数')
else:
score_obj = session.query(models.Score).filter_by(score=score).all()
if score_obj:
for i in score_obj:
score_db_id_obj = session.query(
models.Score).filter_by(score=i.score).first()
record_score_obj = session.query(models.RecordScore).filter_by(
student_teach_class_id=record_id_input).first()
if record_score_obj:
print('该学员已经有成绩了...')
break
else:
add_score_obj = models.RecordScore(
student_teach_class_id=record_id_input, score_id=score_db_id_obj.id)
session.add(add_score_obj)
session.commit()
print('添加成绩完成')
view_score(user)
else:
score_db_obj = models.Score(score=score)
session.add(score_db_obj)
session.commit()
score_db_id_obj = session.query(models.Score).filter_by(score=score).first()
record_score_obj = session.query(models.RecordScore).filter_by(
student_teach_class_id=record_id_input).first()
if record_score_obj:
print('该学员已经有成绩了...')
break
else:
add_score_obj = models.RecordScore(
student_teach_class_id=record_id_input, score_id=score_db_id_obj.id)
session.add(add_score_obj)
session.commit()
print('添加成绩完成')
view_score(user)
else:
print('学生还没有交作业,请先联系学生交作业')
break
else:
print('no this option')
pass
elif user_option == '':
print('添加学员后请注意给学生分配教室并添加上课记录,课后请提示学生交作业')
student_add_input = input('[ 批改成绩是否继续(y)是,(n)否, select num to manage]:').strip()
student_name_input = input('请输入学生账号:')
student_password_input = input('请输入学生密码:')
student_qq_input = input('请输入学生qq号码:')
try:
qq = int(student_qq_input)
except ValueError:
print('qq必须是数字')
break
# 联合查询
student_check = session.query(
models.Student).filter_by(qq_number=qq).filter_by(username=student_name_input).all()
if student_check:
print('学生已经存在')
else:
# 联合查询不能避免qq号或用户名重复...数据库中做了qq号和用户名唯一
try:
student_obj = models.Student(
qq_number=qq, username=student_name_input, password=student_password_input)
session.add(student_obj)
session.commit()
print('添加学生完成,请给学生分配教室并添加上课记录,课后请提示学生交作业')
except sqlalchemy.exc.IntegrityError:
print('学生已经存在')
elif user_option == 'q':
exit_flag = True
else:
print("no this option..") def student(argvs):
'''
学生视图
:param argvs:
:return:
'''
user = auth_student()
if user:
print('student')
welcome_msg(user)
exit_flag = False
show_student_class(user)
msg = '''
1)选择课程班级
2) 提交作业
3)查看作业成绩
4)查看所属班级成绩排名
'''
print(msg)
while not exit_flag:
user_option = input("[ (q)quit, select num to manage]:").strip()
if len(user_option) == 0:
continue
if user_option == 'q':
exit_flag = True
if user_option == '':
print('请联系您的讲师帮您安排课程和教室')
elif user_option == '':
home_work_add_choice = input('[ (y)是,(n)否, select num to manage]:').strip()
if home_work_add_choice == 'n':
break
elif home_work_add_choice == 'y':
home_work_course_time_input = input('请输入上课节数/课程时间>>>:')
home_work_classroom_input = input('请输入所在班级/教室>>>: ')
home_work_classid_input = input('请输入对应教室的绑定ID>>>:')
student_class_obj = session.query(models.StudentTeachClass).filter_by(
id=int(home_work_classid_input)).all()
if student_class_obj:
for i in student_class_obj:
course_obj = session.query(models.CourseClassRecord).filter_by(
id=i.teacher_course.bind_course_time_id).first()
# 检查作业
student_home_work_id_check = session.query(
models.HomeWork).filter_by(home_work=user.username+'_'+course_obj.course_time.
course_time_name+'_'+'home_work').all()
if student_home_work_id_check:
print('已经交作业了,不需要重复提交')
else:
home_add = input('[ (y)是,(n)否, to add home_work]:').strip()
if home_add == 'n':
break
if home_add == 'y':
homework = \
models.HomeWork(
home_work=user.username+'_' + course_obj.course_time.course_time_name + '_' +
'home_work')
session.add(homework)
session.commit()
home_work_id = session.query(models.HomeWork).filter_by(
home_work=user.username+'_' + course_obj.course_time.course_time_name+'_' +
'home_work').first()
record_home_work = models.StudentHomework(
student_teach_class_id=i.id, homework_id=home_work_id.id)
session.add(record_home_work)
session.commit()
print('作业添加完成,请提醒老师添加上课记录和批改成绩...')
break
else:
print('没有这个班级...') elif user_option == '':
print('如果没有成绩的请先交作业然后找讲师批改成绩')
student_record_id = input('请输入您的绑定ID,查看作业信息;')
record_student = session.query(models.RecordStudent).filter_by().all()
for i in record_student:
student_teachclass_obj = session.query(models.StudentTeachClass). \
filter_by(id=student_record_id).first()
class_teacher_obj = session.query(models.TeacherClass).filter_by(
id=student_teachclass_obj.teacher_course.bind_teacher_class_id).first()
course_obj = session.query(models.CourseClassRecord).filter_by(
id=student_teachclass_obj.teacher_course.bind_course_time_id).first()
studentname_obj = session.query(models.Student).filter_by(
qq_number=user.qq_number).first()
studenthomework_obj = session.query(models.StudentHomework).filter_by(
student_teach_class_id=student_record_id).first()
score_obj = session.query(models.RecordScore).filter_by(
student_teach_class_id=i.student_teach_class_id).first()
if studenthomework_obj:
if user.username == studentname_obj.username:
if score_obj:
if score_obj.student_teacher_class.student.qq_number == studentname_obj.qq_number:
print('绑定ID %s 课程:%s 课程时间:%s 讲师:%s 教室:%s 学生名:%s 学生qq %s 上课记录:%s 作业:%s 分数:%s'
% (student_teachclass_obj.id, course_obj.course.coursename,
course_obj.course_time.course_time_name,
class_teacher_obj.teacher.username,
class_teacher_obj.class_room.classname, studentname_obj.username,
studentname_obj.qq_number, i.record.record,
studenthomework_obj.homework.home_work,
score_obj.score.score)) elif user_option == '':
print('查看班级排名.请按照所在班级的绑定ID查询排名')
home_work_course_time_input = input('请输入上课节数/课程时间>>>:')
home_work_classroom_input = input('请输入所在班级/教室>>>: ')
record_student = session.query(models.RecordStudent).filter_by().all()
tmp_dict = {}
for i in record_student:
student_teachclass_obj = session.query(models.StudentTeachClass). \
filter_by(id=i.student_teach_class_id).first()
class_teacher_obj = session.query(models.TeacherClass).filter_by(
id=student_teachclass_obj.teacher_course.bind_teacher_class_id).first()
course_obj = session.query(models.CourseClassRecord).filter_by(
id=student_teachclass_obj.teacher_course.bind_course_time_id).first()
studentname_obj = session.query(models.Student).filter_by(
qq_number=student_teachclass_obj.student.qq_number).first()
studenthomework_obj = session.query(models.StudentHomework).filter_by(
student_teach_class_id=i.student_teach_class_id).first()
score_obj = session.query(models.RecordScore).filter_by(
student_teach_class_id=i.student_teach_class_id).first()
if home_work_course_time_input == course_obj.course_time.course_time_name \
and home_work_classroom_input == class_teacher_obj.class_room.classname:
if studenthomework_obj:
if score_obj:
if score_obj.student_teacher_class.student.qq_number == studentname_obj.qq_number:
if score_obj.score.score in tmp_dict.keys():
tmp_dict[score_obj.score.score].append(studentname_obj.username)
else:
tmp_dict[score_obj.score.score] = [studentname_obj.username]
# 分数排序,按道理应该是用group_by 这里偷个懒
tmp_list = []
for key in tmp_dict.keys():
tmp_list.append(key)
tmp_list.sort(reverse=True)
for key in tmp_list:
for name in tmp_dict[key]:
print(name, key) elif user_option == 'q':
exit_flag = True
else:
print('no this option')

models.py

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Time:2017/12/19 20:36
__Author__ = 'Sean Yao'
import datetime
from sqlalchemy import Table, Column, Integer, String, DATE, ForeignKey, Enum, UniqueConstraint, DateTime, Text
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_utils import ChoiceType, PasswordType
from sqlalchemy import create_engine Base = declarative_base() class TeacheCourse(Base):
'''
课程/课程表/讲师/教室/关联
'''
__tablename__ = 'teacher_course'
__table_args__ = (UniqueConstraint('bind_teacher_class_id', 'bind_course_time_id', name='_class_uc'),)
id = Column(Integer, primary_key=True)
bind_teacher_class_id = Column('bind_teacher_class_id', Integer, ForeignKey('bind_teacher_class.id'))
bind_course_time_id = Column('bind_course_time_id', Integer, ForeignKey('bind_course_time.id')) teacher_class = relationship('TeacherClass', backref='teacher_course')
course_class_record = relationship('CourseClassRecord', backref='teacher_course') def __repr__(self):
return self.id, self.teacher_class.id, self.bind_course_time_id class RecordScore(Base):
'''
打分/关联 老师视图操作
1 66
2 88
'''
__tablename__ = 'record_score'
__table_args__ = (UniqueConstraint('student_teach_class_id', 'score_id', name='_record_score_uc'),) id = Column(Integer, primary_key=True)
student_teach_class_id = Column(
'student_teach_class_id', Integer, ForeignKey('student_teach_class.id'), unique=True)
score_id = Column('score_id', Integer, ForeignKey('score.id')) score = relationship('Score', backref='record_score')
student_teacher_class = relationship('StudentTeachClass', backref='record_score') def __repr__(self):
return self.id, self.student_teacher_class.teacher_course.id, self.student_teacher_class.student.qq_number, \
self.score.score class RecordStudent(Base):
'''
上课记录/关联 老师视图操作
1 yes
2 no
'''
__tablename__ = 'record_student'
__table_args__ = (UniqueConstraint('student_teach_class_id', 'record_id', name='_record_class_uc'),) id = Column(Integer, primary_key=True)
student_teach_class_id = Column(
'student_teach_class_id', Integer, ForeignKey('student_teach_class.id'), unique=True)
record_id = Column('record_id', Integer, ForeignKey('record.id')) record = relationship('Record', backref='record_student')
student_teacher_class = relationship('StudentTeachClass', backref='record_student') def __repr__(self):
return self.id, self.student_teacher_class.teacher_course.id, self.student_teacher_class.student.qq_number, \
self.record.record class StudentHomework(Base):
'''
课程/课程表/讲师/教室/学生/作业/关联 学生视图操作
449010391 1
'''
__tablename__ = 'student_homework'
__table_args__ = (UniqueConstraint('student_teach_class_id', 'homework_id', name='_record_homework_uc'),) id = Column(Integer, primary_key=True)
student_teach_class_id = Column(
'student_teach_class_id', Integer, ForeignKey('student_teach_class.id'), unique=True)
homework_id = Column('homework_id', Integer, ForeignKey('homework.id')) homework = relationship('HomeWork', backref='student_homework')
student_teacher_class = relationship('StudentTeachClass', backref='student_homework') def __repr__(self):
return self.id, self.student_teacher_class.teacher_course.id, self.student_teacher_class.student.qq_number, \
self.homework.home_work class StudentTeachClass(Base):
'''
课程/课程表/讲师/教室/学生/关联
python/python1/alex/python_1 449010391
1 449010391
'''
__tablename__ = 'student_teach_class'
__table_args__ = (UniqueConstraint('student_qq', 'teacher_course_id', name='_record_uc'),) id = Column(Integer, primary_key=True)
teacher_course_id = Column('teacher_course_id', Integer, ForeignKey('teacher_course.id'))
student_qq = Column('student_qq', Integer, ForeignKey('student.qq_number')) teacher_course = relationship("TeacheCourse", backref='student_teach_class')
student = relationship('Student', backref='student_teach_class') def __repr__(self):
# qq号,讲师/教室/课程/课程表
return self.id, self.student.qq_number, self.teacher_course.bind_teacher_class_id, \
self.teacher_course.bind_course_time_id class Course(Base):
'''
课程表
课程唯一
'''
__tablename__ = 'course'
id = Column(Integer, primary_key=True)
coursename = Column(String(64), unique=True, nullable=False) def __repr__(self):
return self.id, self.coursename class CourseTime(Base):
'''
课程时间表
课程时间唯一
'''
__tablename__ = 'course_time'
id = Column(Integer, primary_key=True)
course_time_name = Column(String(64), unique=True, nullable=False) def __repr__(self):
return self.id, self.course_time_name class Teacher(Base):
'''
teacher 表
老师名字唯一
'''
__tablename__ = 'teacher'
id = Column(Integer, primary_key=True)
username = Column(String(64), unique=True, nullable=False)
password = Column(String(128), nullable=False) def __repr__(self):
return self.id, self.username, self.password, class ClassRoom(Base):
'''
班级表
班级唯一
'''
__tablename__ = 'class_room'
id = Column(Integer, primary_key=True)
classname = Column(String(64), unique=True, nullable=False) def __repr__(self):
return self.id, self.classname class Student(Base):
'''
student表
用户名/qq号/唯一
'''
__tablename__ = 'student'
id = Column(Integer, primary_key=True)
qq_number = Column(Integer, unique=True, nullable=False)
username = Column(String(64), unique=True, nullable=False)
password = Column(String(128), nullable=False) def __repr__(self):
return self.id, self.qq_number, self.username, self.password class Score(Base):
'''
成绩表
成绩不唯一可能不同的童鞋得到的分数一样
'''
__tablename__ = 'score'
id = Column(Integer, primary_key=True)
score = Column(Integer, unique=True, nullable=False) def __repr__(self):
return self.id, self.score class HomeWork(Base):
'''
作业表
作业唯一对应不同的童鞋和课程
'''
__tablename__ = 'homework'
id = Column(Integer, unique=True, primary_key=True)
home_work = Column(String(128)) def __repr__(self):
return self.id, self.home_work class Record(Base):
'''
上课记录
唯一只有yes/no
'''
__tablename__ = 'record'
id = Column(Integer, primary_key=True)
action_choices = [
(u'yes', u'Yes'),
(u'no', u'No'),
]
record = Column(ChoiceType(action_choices), unique=True) def __repr__(self):
return self.id, self.record class CourseClassRecord(Base):
'''
课程/课程时间/关联
课程:pyrhon 课程时间:python_day1
课程:linux 课程时间:linux_day1
课程:linux 课程时间:linux_day2
课程和课程时间联合唯一
'''
__tablename__ = "bind_course_time"
# 联合唯一
__table_args__ = (UniqueConstraint('course_id', 'course_time_id', name='_course_uc'),)
id = Column(Integer, primary_key=True)
course_id = Column(Integer, ForeignKey('course.id'))
course_time_id = Column(Integer, ForeignKey('course_time.id'))
course = relationship('Course', backref='bind_course_time')
course_time = relationship('CourseTime', backref='bind_course_time') def __repr__(self):
return self.id, self.course.coursename, self.course_time.course_time_name class TeacherClass(Base):
'''
老师/班级/关联
老师和班级联合唯一
老师:alex 班级:python_S14
老师:alex 班级:python_S15
'''
__tablename__ = "bind_teacher_class"
__table_args__ = (UniqueConstraint('teacher_id', 'class_room_id', name='_class_uc'),) id = Column(Integer, primary_key=True)
teacher_id = Column(Integer, ForeignKey('teacher.id'))
class_room_id = Column(Integer, ForeignKey('class_room.id'))
teacher = relationship('Teacher', backref='bind_teacher_class')
class_room = relationship('ClassRoom', backref='bind_teacher_class') def __repr__(self):
return self.id, self.teacher.username, self.class_room.classname

程序测试样图:

添加多个学生后,给学生绑定了课堂,并登陆学生交了作业,讲师批改作业后学生可以查看分数排名

python作业学员管理系统(第十二周)的更多相关文章

  1. python第六十八天--第十二周作业

    主题: 需求: 用户角色,讲师\学员, 用户登陆后根据角色不同,能做的事情不同,分别如下讲师视图 管理班级,可创建班级,根据学员qq号把学员加入班级 可创建指定班级的上课纪录,注意一节上课纪录对应多条 ...

  2. Python作业工资管理系统(第三周)

    作业内容: 实现效果: 从info.txt文件中读取员工及其工资信息,最后将修改或增加的员工工资信息也写入原info.txt文件. 效果演示: 1. 查询员工工资 2. 修改员工工资 3. 增加新员工 ...

  3. 2017-2018-1 《Linux内核原理与设计》第十二周作业

    <linux内核原理与设计>第十二周作业 Sql注入基础原理介绍 分组: 和20179215袁琳完成实验 一.实验说明   SQL注入攻击通过构建特殊的输入作为参数传入Web应用程序,而这 ...

  4. 第十二周作业_PSP总结报告

    回顾1 (1)回想一下你曾经对计算机专业的畅想 当初你是如何做出选择计算机专业的决定的?经过一个学期,你的看法改变了么,为什么? 你认为过去接触到的课程是否符合你对计算机专业的期待,为什么?经过一个学 ...

  5. 20155213 第十二周课堂作业MySort

    20155213 第十二周课堂作业MySort 作业要求 模拟实现Linux下Sort -t : -k 2的功能 参考 Sort的实现 提交码云链接和代码运行截图 初始代码 1 import java ...

  6. 第十二周博客作业 <西北师范大学| 周安伟>

    第十二周作业 助教博客链接https://home.cnblogs.com/u/zaw-315/ 作业要求链接https://www.cnblogs.com/nwnu-daizh/p/10831971 ...

  7. 2019-2020-1 20199329《Linux内核原理与分析》第十二周作业

    <Linux内核原理与分析>第十二周作业 一.本周内容概述: 通过编程理解 Set-UID 的运行机制与安全问题 完成实验楼上的<SET-UID程序漏洞实验> 二.本周学习内容 ...

  8. 201521123061 《Java程序设计》第十二周学习总结

    201521123061 <Java程序设计>第十二周学习总结 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对 ...

  9. 201521123072《java程序设计》第十二周学习总结

    201521123072<java程序设计>第十二周学习总结 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对象 ...

随机推荐

  1. eclipse报错:Could not resolve bean definition resource pattern [classpath:spring/applicationContext-*.xml]或者找不到

    1.把xml文件复制到WEB-INF下 2.路径改成 [/WEB-INF/spring/applicationContext-*.xml]

  2. 雷林鹏分享:XML 教程

    XML 教程 XML 指可扩展标记语言(eXtensible Markup Language). XML 被设计用来传输和存储数据. XML 很重要,也很容易学习. 现在开始学习 XML! XML 文 ...

  3. LeetCode--278--第一个错误的版本

    问题描述: 你是产品经理,目前正在带领一个团队开发新的产品.不幸的是,你的产品的最新版本没有通过质量检测.由于每个版本都是基于之前的版本开发的,所以错误的版本之后的所有版本都是错的. 假设你有 n 个 ...

  4. p1470 Longest Prefix

    原本就想到dp,可是是我的思路是在串的各个位置都遍历一次set,看dp[i-st[k]]是否为1且前length(st[k])是st[k].这样200000*200*10会超时.更好的办法是在i位取前 ...

  5. xgboost原理及应用--转

    1.背景 关于xgboost的原理网络上的资源很少,大多数还停留在应用层面,本文通过学习陈天奇博士的PPT地址和xgboost导读和实战 地址,希望对xgboost原理进行深入理解. 2.xgboos ...

  6. php-fpm.conf文件的位置在哪里

    在php的安装目录下的etc目录下:

  7. mac中 hosts地址

    /etc/hosts 拉出hosts文件,修改之后再拉进去

  8. 卸载WPS后怎么WORD的图标还是WPS

    在电脑中选择使用Microsoft Office并将之前安装的WPS Office办公软件卸载了.但是卸载之后发现电脑系统中的Word.Excel等文件无法正常显示图标.在这样的情况下,我们应该如何解 ...

  9. Fiddler 抓包工具总结【转载】

    原博主连接在文章底部 Fiddler是一个蛮好用的抓包工具,可以将网络传输发送与接受的数据包进行截获.重发.编辑.转存等操作.也可以用来检测网络安全.反正好处多多,举之不尽呀!当年学习的时候也蛮费劲, ...

  10. Python函数式编程,map/reduce,filter和sorted

    什么是函数式编程? 与面向对象编程(Object-oriented programming)和过程式编程(Procedural programming)并列的编程范式. 最主要的特征是,函数是第一等公 ...