Rumah  >  Artikel  >  pembangunan bahagian belakang  >  python第六十八天--第十二周作业

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

PHP中文网
PHP中文网asal
2017-07-10 18:13:061532semak imbas

主题:

需求:

用户角色,讲师\学员, 用户登陆后根据角色不同,能做的事情不同,分别如下
讲师视图
  管理班级,可创建班级,根据学员qq号把学员加入班级
  可创建指定班级的上课纪录,注意一节上课纪录对应多条学员的上课纪录, 即每节课都有整班学员上, 为了纪录每位学员的学习成绩,需在创建每节上课纪录是,同时 为这个班的每位学员创建一条上课纪录
  为学员批改成绩, 一条一条的手动修改成绩
学员视图
提交作业
查看作业成绩
一个学员可以同时属于多个班级,就像报了Linux的同时也可以报名Python一样, 所以提交作业时需先选择班级,再选择具体上课的节数
附加:学员可以查看自己的班级成绩排名

 

学员管理系统<br><br>实现功能:<br>1、系统初始化<br>2、管理员视图<br>    功能:创建讲师、查看讲师、创建班级、查看班级、关联讲师与班级、创建学员、查看学员、班级关联学员<br>3、讲师视图<br>    功能:管理班级、创建班级(自动与自己关联)、班级增加学员、增加新课节、<br>          指定班级上课,选择上课课节(自动创建课程记录,同时为这个班的每位学员创建一条上课纪录)<br>          批改成绩(先选择一个班级、再选择学员)<br>4、学员视图<br>    功能:提交作业<br>          查看作业成绩<br>          查看班级中的总成绩排名<br><br><br>stude_mag_sys/#程序目录<br>|- - -__init__.py<br>|- - -bin/#启动目录<br>|      |- - -__init__.py<br>|      |- - -admin_start.py#管理员视图启动<br>|      |- - -mag_init.py#系统初始化<br>|      |- - -student.py#学员视图启动<br>|      |- - -teach_start.py#讲师视图启动<br>|<br>|- - -cfg/#配置目录<br>|      |- - -__init__.py<br>|      |- - -config.py#配置文件<br>|<br>|- - -core/#主逻辑目录<br>|      |- - -__init__.py<br>|      |- - -admain_class.py#主要逻辑 类<br>|      |- - -admin_log.py#管理员逻辑 类<br>|      |- - -student_class.py#学员逻辑 类<br>|      |- - -teach_class.py#讲师逻辑 类<br>|<br>|- - -REDMAE

 

 

先上一个表结构图   

 

 

流程美图来一张:

 

stude_mag_sys/#程序目录<br>|- - -__init__.py<br>|- - -bin/#启动目录<br>|      |- - -__init__.py
|      |- - -admin_start.py#管理员视图启动
<span style="color: #008080"> 1</span> <span style="color: #0000ff">import</span><span style="color: #000000"> os ,sys
</span><span style="color: #008080"> 2</span> <span style="color: #0000ff">from</span> sqlalchemy <span style="color: #0000ff">import</span><span style="color: #000000"> create_engine
</span><span style="color: #008080"> 3</span> BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(<span style="color: #800080">__file__</span>)))<span style="color: #008000">#</span><span style="color: #008000">获取相对路径转为绝对路径赋于变量</span>
<span style="color: #008080"> 4</span> sys.path.append(BASE_DIR)<span style="color: #008000">#</span><span style="color: #008000">增加环境变量</span>
<span style="color: #008080"> 5</span> <span style="color: #0000ff">from</span> core <span style="color: #0000ff">import</span><span style="color: #000000"> admin_class
</span><span style="color: #008080"> 6</span> <span style="color: #0000ff">from</span> core <span style="color: #0000ff">import</span><span style="color: #000000"> admin_log
</span><span style="color: #008080"> 7</span> <span style="color: #0000ff">from</span> cfg <span style="color: #0000ff">import</span><span style="color: #000000"> config
</span><span style="color: #008080"> 8</span> <span style="color: #0000ff">if</span> <span style="color: #800080">__name__</span> == <span style="color: #800000">'</span><span style="color: #800000">__main__</span><span style="color: #800000">'</span><span style="color: #000000">:
</span><span style="color: #008080"> 9</span>     <span style="color: #008000">#</span><span style="color: #008000">                      用户 密码  主机             库</span>
<span style="color: #008080">10</span>     <span style="color: #008000">#</span><span style="color: #008000">engine = create_engine(config.HOSTS,)#连接</span>
<span style="color: #008080">11</span>     <span style="color: #008000">#</span><span style="color: #008000">admin_class.Base.metadata.create_all(admin_class.engine)#创建表结构</span>
<span style="color: #008080">12</span>     <span style="color: #0000ff">while</span><span style="color: #000000"> True:
</span><span style="color: #008080">13</span>         admin=<span style="color: #000000">admin_log.Admin_Mag()
</span><span style="color: #008080">14</span>         admin.user_log()
View Code
|      |- - -mag_init.py#系统初始化
<span style="color: #008080"> 1</span> <span style="color: #0000ff">import</span><span style="color: #000000"> os ,sys
</span><span style="color: #008080"> 2</span> <span style="color: #0000ff">from</span> sqlalchemy <span style="color: #0000ff">import</span><span style="color: #000000"> create_engine
</span><span style="color: #008080"> 3</span> <span style="color: #0000ff">from</span> sqlalchemy.orm <span style="color: #0000ff">import</span><span style="color: #000000"> sessionmaker, relationship
</span><span style="color: #008080"> 4</span> BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(<span style="color: #800080">__file__</span>)))<span style="color: #008000">#</span><span style="color: #008000">获取相对路径转为绝对路径赋于变量</span>
<span style="color: #008080"> 5</span> sys.path.append(BASE_DIR)<span style="color: #008000">#</span><span style="color: #008000">增加环境变量</span>
<span style="color: #008080"> 6</span> <span style="color: #0000ff">from</span> core <span style="color: #0000ff">import</span><span style="color: #000000"> admin_class
</span><span style="color: #008080"> 7</span> <span style="color: #0000ff">from</span> core <span style="color: #0000ff">import</span><span style="color: #000000"> admin_log
</span><span style="color: #008080"> 8</span> <span style="color: #0000ff">from</span> cfg <span style="color: #0000ff">import</span><span style="color: #000000"> config
</span><span style="color: #008080"> 9</span> <span style="color: #0000ff">if</span> <span style="color: #800080">__name__</span> == <span style="color: #800000">'</span><span style="color: #800000">__main__</span><span style="color: #800000">'</span><span style="color: #000000">:
</span><span style="color: #008080">10</span>     <span style="color: #008000">#</span><span style="color: #008000">                      用户 密码  主机             库</span>
<span style="color: #008080">11</span>     <span style="color: #008000">#</span><span style="color: #008000">engine = create_engine(config.HOSTS,)#连接</span>
<span style="color: #008080">12</span> 
<span style="color: #008080">13</span>     admin_class.Base.metadata.create_all(admin_class.engine)<span style="color: #008000">#</span><span style="color: #008000">创建表结构</span>
<span style="color: #008080">14</span>     A1 = admin_class.Admin_user(name=config.USER,pwd=config.PWD)<span style="color: #008000">#</span><span style="color: #008000">初始化</span>
<span style="color: #008080">15</span>     Session_class=sessionmaker(bind=admin_class.engine)<span style="color: #008000">#</span><span style="color: #008000">创建与数据库的会话 类</span>
<span style="color: #008080">16</span>     Session=Session_class()<span style="color: #008000">#</span><span style="color: #008000">生成实例</span>
<span style="color: #008080">17</span> <span style="color: #000000">    Session.add(A1)
</span><span style="color: #008080">18</span>     Session.commit()
View Code
|      |- - -student.py#学员视图启动
<span style="color: #008080">1</span> <span style="color: #0000ff">import</span><span style="color: #000000"> os ,sys
</span><span style="color: #008080">2</span> BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(<span style="color: #800080">__file__</span>)))<span style="color: #008000">#</span><span style="color: #008000">获取相对路径转为绝对路径赋于变量</span>
<span style="color: #008080">3</span> sys.path.append(BASE_DIR)<span style="color: #008000">#</span><span style="color: #008000">增加环境变量</span>
<span style="color: #008080">4</span> <span style="color: #0000ff">from</span> core.student_class <span style="color: #0000ff">import</span><span style="color: #000000"> Stu_Mag
</span><span style="color: #008080">5</span> <span style="color: #0000ff">from</span> cfg <span style="color: #0000ff">import</span><span style="color: #000000"> config
</span><span style="color: #008080">6</span> <span style="color: #0000ff">if</span> <span style="color: #800080">__name__</span> == <span style="color: #800000">'</span><span style="color: #800000">__main__</span><span style="color: #800000">'</span><span style="color: #000000">:
</span><span style="color: #008080">7</span>     <span style="color: #0000ff">while</span><span style="color: #000000"> True:
</span><span style="color: #008080">8</span>         stu=<span style="color: #000000">Stu_Mag()
</span><span style="color: #008080">9</span>         stu.user_log()
View Code
|      |- - -teach_start.py#讲师视图启动
<span style="color: #008080">1</span> <span style="color: #0000ff">import</span><span style="color: #000000"> os ,sys
</span><span style="color: #008080">2</span> BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(<span style="color: #800080">__file__</span>)))<span style="color: #008000">#</span><span style="color: #008000">获取相对路径转为绝对路径赋于变量</span>
<span style="color: #008080">3</span> sys.path.append(BASE_DIR)<span style="color: #008000">#</span><span style="color: #008000">增加环境变量</span>
<span style="color: #008080">4</span> <span style="color: #0000ff">from</span> core.teach_class <span style="color: #0000ff">import</span><span style="color: #000000"> Teach_Mag
</span><span style="color: #008080">5</span> <span style="color: #0000ff">from</span> cfg <span style="color: #0000ff">import</span><span style="color: #000000"> config
</span><span style="color: #008080">6</span> <span style="color: #0000ff">if</span> <span style="color: #800080">__name__</span> == <span style="color: #800000">'</span><span style="color: #800000">__main__</span><span style="color: #800000">'</span><span style="color: #000000">:
</span><span style="color: #008080">7</span>     <span style="color: #0000ff">while</span><span style="color: #000000"> True:
</span><span style="color: #008080">8</span>         teach=<span style="color: #000000">Teach_Mag()
</span><span style="color: #008080">9</span>         teach.user_log()
View Code

 

|- - -cfg/#配置目录<br>|      |- - -__init__.py<br>|      |- - -config.py#配置文件
<span style="color: #008080"> 1</span> <span style="color: #0000ff">import</span><span style="color: #000000"> os ,sys
</span><span style="color: #008080"> 2</span> BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(<span style="color: #800080">__file__</span>)))<span style="color: #008000">#</span><span style="color: #008000">获取相对路径转为绝对路径赋于变量</span>
<span style="color: #008080"> 3</span> sys.path.append(BASE_DIR)<span style="color: #008000">#</span><span style="color: #008000">增加环境变量</span>
<span style="color: #008080"> 4</span> 
<span style="color: #008080"> 5</span> BAES=<span style="color: #800000">'</span><span style="color: #800000">test_student_mag</span><span style="color: #800000">'</span><span style="color: #008000">#</span><span style="color: #008000">库名</span>
<span style="color: #008080"> 6</span> HOSTS=<span style="color: #800000">"</span><span style="color: #800000">mysql+pymysql://root:root@127.0.0.1:3306/</span><span style="color: #800000">"</span>+BAES+<span style="color: #800000">"</span><span style="color: #800000">?charset=utf8</span><span style="color: #800000">"</span><span style="color: #008000">#</span><span style="color: #008000">连接</span>
<span style="color: #008080"> 7</span> USER=<span style="color: #800000">'</span><span style="color: #800000">admin</span><span style="color: #800000">'</span>
<span style="color: #008080"> 8</span> PWD=<span style="color: #800000">'</span><span style="color: #800000">admin</span><span style="color: #800000">'</span>
<span style="color: #008080"> 9</span> 
<span style="color: #008080">10</span> ADMIN_OPEN=<span style="color: #000000">[
</span><span style="color: #008080">11</span>     (<span style="color: #800000">'</span><span style="color: #800000">创建讲师</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">add_teach</span><span style="color: #800000">'</span><span style="color: #000000">),
</span><span style="color: #008080">12</span>     (<span style="color: #800000">'</span><span style="color: #800000">查看讲师</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">teach_l</span><span style="color: #800000">'</span><span style="color: #000000">),
</span><span style="color: #008080">13</span>     (<span style="color: #800000">'</span><span style="color: #800000">创建班级</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">add_class</span><span style="color: #800000">'</span><span style="color: #000000">),
</span><span style="color: #008080">14</span>     (<span style="color: #800000">'</span><span style="color: #800000">查看班级</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">class_l</span><span style="color: #800000">'</span><span style="color: #000000">),
</span><span style="color: #008080">15</span>     (<span style="color: #800000">'</span><span style="color: #800000">讲师关联班级</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">assoc</span><span style="color: #800000">'</span><span style="color: #000000">),
</span><span style="color: #008080">16</span>     (<span style="color: #800000">'</span><span style="color: #800000">创建学员</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">add_stu</span><span style="color: #800000">'</span><span style="color: #000000">),
</span><span style="color: #008080">17</span>     (<span style="color: #800000">'</span><span style="color: #800000">查看学员</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">stu_l</span><span style="color: #800000">'</span><span style="color: #000000">),
</span><span style="color: #008080">18</span>     (<span style="color: #800000">'</span><span style="color: #800000">班级关联学员</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">class_student</span><span style="color: #800000">'</span><span style="color: #000000">),
</span><span style="color: #008080">19</span>     (<span style="color: #800000">'</span><span style="color: #800000">退出</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">tech_exit</span><span style="color: #800000">'</span><span style="color: #000000">),
</span><span style="color: #008080">20</span> <span style="color: #000000">]
</span><span style="color: #008080">21</span> 
<span style="color: #008080">22</span> TEACH_OPEN=<span style="color: #000000">[
</span><span style="color: #008080">23</span>     (<span style="color: #800000">'</span><span style="color: #800000">查看班级</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">show_class</span><span style="color: #800000">'</span><span style="color: #000000">),
</span><span style="color: #008080">24</span>     ( <span style="color: #800000">'</span><span style="color: #800000">创建新班级</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">add_class</span><span style="color: #800000">'</span><span style="color: #000000">),
</span><span style="color: #008080">25</span>     (<span style="color: #800000">'</span><span style="color: #800000">班级增加学员</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">add_student</span><span style="color: #800000">'</span><span style="color: #000000">),
</span><span style="color: #008080">26</span>      (<span style="color: #800000">'</span><span style="color: #800000">增加新课节</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">add_lesson</span><span style="color: #800000">'</span><span style="color: #000000">),
</span><span style="color: #008080">27</span>       (<span style="color: #800000">'</span><span style="color: #800000">开始上课</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">add_cla_day</span><span style="color: #800000">'</span><span style="color: #000000">),
</span><span style="color: #008080">28</span>        (<span style="color: #800000">'</span><span style="color: #800000">批改成绩</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">set_results</span><span style="color: #800000">'</span><span style="color: #000000">),
</span><span style="color: #008080">29</span>     (<span style="color: #800000">'</span><span style="color: #800000">退出</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">tech_exit</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">30</span> <span style="color: #000000">]
</span><span style="color: #008080">31</span> STUED_OPEN=<span style="color: #000000">[
</span><span style="color: #008080">32</span>     (<span style="color: #800000">'</span><span style="color: #800000">提交作业</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">up_work</span><span style="color: #800000">'</span><span style="color: #000000">),
</span><span style="color: #008080">33</span>     ( <span style="color: #800000">'</span><span style="color: #800000">查看成绩</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">set_resu</span><span style="color: #800000">'</span><span style="color: #000000">),
</span><span style="color: #008080">34</span>     (<span style="color: #800000">'</span><span style="color: #800000">查看班级排行</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">cla_top</span><span style="color: #800000">'</span><span style="color: #000000">),
</span><span style="color: #008080">35</span>     (<span style="color: #800000">'</span><span style="color: #800000">退出</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">tech_exit</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">36</span> ]
View Code
|- - -core/#主逻辑目录<br>|      |- - -__init__.py<br>|      |- - -admain_class.py#主要逻辑 类
<span style="color: #008080"> 1</span> <span style="color: #008000">#</span><span style="color: #008000">!usr/bin/env python</span>
<span style="color: #008080"> 2</span> <span style="color: #008000">#</span><span style="color: #008000">-*-coding:utf-8-*-</span>
<span style="color: #008080"> 3</span> <span style="color: #008000">#</span><span style="color: #008000"> Author calmyan </span>
<span style="color: #008080"> 4</span> <span style="color: #008000">#</span><span style="color: #008000">python </span>
<span style="color: #008080"> 5</span> <span style="color: #008000">#</span><span style="color: #008000">2017/7/7    17:46</span>
<span style="color: #008080"> 6</span> <span style="color: #008000">#</span><span style="color: #008000">__author__='Administrator'</span>
<span style="color: #008080"> 7</span> <span style="color: #008000">#</span><span style="color: #008000"> 创建表</span>
<span style="color: #008080"> 8</span> <span style="color: #0000ff">import</span><span style="color: #000000"> os ,sys
</span><span style="color: #008080"> 9</span> BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(<span style="color: #800080">__file__</span>)))<span style="color: #008000">#</span><span style="color: #008000">获取相对路径转为绝对路径赋于变量</span>
<span style="color: #008080">10</span> sys.path.append(BASE_DIR)<span style="color: #008000">#</span><span style="color: #008000">增加环境变量</span>
<span style="color: #008080">11</span> <span style="color: #0000ff">from</span> sqlalchemy.ext.declarative <span style="color: #0000ff">import</span><span style="color: #000000"> declarative_base
</span><span style="color: #008080">12</span> <span style="color: #0000ff">from</span> sqlalchemy <span style="color: #0000ff">import</span><span style="color: #000000"> Column, Integer, String, ForeignKey, UniqueConstraint, Index,Table,DATE
</span><span style="color: #008080">13</span> <span style="color: #0000ff">from</span> sqlalchemy.orm <span style="color: #0000ff">import</span><span style="color: #000000"> sessionmaker, relationship
</span><span style="color: #008080">14</span> <span style="color: #0000ff">from</span> sqlalchemy <span style="color: #0000ff">import</span><span style="color: #000000"> create_engine
</span><span style="color: #008080">15</span> <span style="color: #0000ff">from</span> sqlalchemy <span style="color: #0000ff">import</span> func <span style="color: #008000">#</span><span style="color: #008000">统计</span>
<span style="color: #008080">16</span> <span style="color: #0000ff">from</span>  cfg <span style="color: #0000ff">import</span><span style="color: #000000"> config
</span><span style="color: #008080">17</span> Base = declarative_base()<span style="color: #008000">#</span><span style="color: #008000">生成orm 基类</span>
<span style="color: #008080">18</span> 
<span style="color: #008080">19</span> <span style="color: #008000">#</span><span style="color: #008000">创建班级关联学员表,自动维护</span>
<span style="color: #008080">20</span> class_name_m2m_student = Table(<span style="color: #800000">'</span><span style="color: #800000">class_name_m2m_student</span><span style="color: #800000">'</span><span style="color: #000000">, Base.metadata,
</span><span style="color: #008080">21</span>                         Column(<span style="color: #800000">'</span><span style="color: #800000">class_name_id</span><span style="color: #800000">'</span>,Integer,ForeignKey(<span style="color: #800000">'</span><span style="color: #800000">class_name.id</span><span style="color: #800000">'</span>)),<span style="color: #008000">#</span><span style="color: #008000">关联外键,班级id</span>
<span style="color: #008080">22</span>                         Column(<span style="color: #800000">'</span><span style="color: #800000">student_id</span><span style="color: #800000">'</span>,Integer,ForeignKey(<span style="color: #800000">'</span><span style="color: #800000">student.id</span><span style="color: #800000">'</span>)),<span style="color: #008000">#</span><span style="color: #008000">关联外键,学员id</span>
<span style="color: #008080">23</span> <span style="color: #000000">                        )
</span><span style="color: #008080">24</span> <span style="color: #008000">#</span><span style="color: #008000">创建班级关联老师表,自动维护</span>
<span style="color: #008080">25</span> teacher_name_m2m_class = Table(<span style="color: #800000">'</span><span style="color: #800000">teacher_name_m2m_class</span><span style="color: #800000">'</span><span style="color: #000000">, Base.metadata,
</span><span style="color: #008080">26</span>                         Column(<span style="color: #800000">'</span><span style="color: #800000">teacher_id</span><span style="color: #800000">'</span>,Integer,ForeignKey(<span style="color: #800000">'</span><span style="color: #800000">teacher.id</span><span style="color: #800000">'</span>)),<span style="color: #008000">#</span><span style="color: #008000">关联外键,老师id</span>
<span style="color: #008080">27</span>                         Column(<span style="color: #800000">'</span><span style="color: #800000">class_name_id</span><span style="color: #800000">'</span>,Integer,ForeignKey(<span style="color: #800000">'</span><span style="color: #800000">class_name.id</span><span style="color: #800000">'</span>)),<span style="color: #008000">#</span><span style="color: #008000">关联外键,班级id</span>
<span style="color: #008080">28</span> <span style="color: #000000">                        )
</span><span style="color: #008080">29</span> <span style="color: #008000">#</span><span style="color: #008000">班级表</span>
<span style="color: #008080">30</span> <span style="color: #0000ff">class</span> Class_name(Base):<span style="color: #008000">#</span><span style="color: #008000">班级表</span>
<span style="color: #008080">31</span>     <span style="color: #800080">__tablename__</span> = <span style="color: #800000">'</span><span style="color: #800000">class_name</span><span style="color: #800000">'</span>
<span style="color: #008080">32</span>     id = Column(Integer,primary_key=<span style="color: #000000">True)
</span><span style="color: #008080">33</span>     name = Column(String(64),unique=<span style="color: #000000">True)
</span><span style="color: #008080">34</span>     students = relationship(<span style="color: #800000">'</span><span style="color: #800000">Student</span><span style="color: #800000">'</span>,secondary=class_name_m2m_student,backref=<span style="color: #800000">'</span><span style="color: #800000">class_name</span><span style="color: #800000">'</span>)<span style="color: #008000">#</span><span style="color: #008000">关联学员,班级</span>
<span style="color: #008080">35</span>     <span style="color: #008000">#</span><span style="color: #008000">teachers = relationship('Teacher',secondary=class_name_m2m_teacher,backref='class_name')#关联老师,班级</span>
<span style="color: #008080">36</span>     <span style="color: #0000ff">def</span> <span style="color: #800080">__repr__</span><span style="color: #000000">(self):
</span><span style="color: #008080">37</span>         <span style="color: #0000ff">return</span><span style="color: #000000"> self.name
</span><span style="color: #008080">38</span> 
<span style="color: #008080">39</span> <span style="color: #008000">#</span><span style="color: #008000">老师表</span>
<span style="color: #008080">40</span> <span style="color: #0000ff">class</span> Teacher(Base):<span style="color: #008000">#</span><span style="color: #008000">老师表</span>
<span style="color: #008080">41</span>     <span style="color: #800080">__tablename__</span> = <span style="color: #800000">'</span><span style="color: #800000">teacher</span><span style="color: #800000">'</span>
<span style="color: #008080">42</span>     id = Column(Integer, primary_key=<span style="color: #000000">True)
</span><span style="color: #008080">43</span>     name = Column(String(32<span style="color: #000000">))
</span><span style="color: #008080">44</span>     user = Column(String(32),unique=<span style="color: #000000">True)
</span><span style="color: #008080">45</span>     pwd = Column(String(32<span style="color: #000000">))
</span><span style="color: #008080">46</span>     class_n = relationship(<span style="color: #800000">'</span><span style="color: #800000">Class_name</span><span style="color: #800000">'</span>,secondary=teacher_name_m2m_class,backref=<span style="color: #800000">'</span><span style="color: #800000">teach_name</span><span style="color: #800000">'</span>)<span style="color: #008000">#</span><span style="color: #008000">关联老师,班级</span>
<span style="color: #008080">47</span>     <span style="color: #0000ff">def</span> <span style="color: #800080">__repr__</span><span style="color: #000000">(self):
</span><span style="color: #008080">48</span>         <span style="color: #0000ff">return</span><span style="color: #000000"> self.name
</span><span style="color: #008080">49</span> 
<span style="color: #008080">50</span> <span style="color: #008000">#</span><span style="color: #008000">学员表</span>
<span style="color: #008080">51</span> <span style="color: #0000ff">class</span> Student(Base):<span style="color: #008000">#</span><span style="color: #008000">学员表</span>
<span style="color: #008080">52</span>     <span style="color: #800080">__tablename__</span> = <span style="color: #800000">'</span><span style="color: #800000">student</span><span style="color: #800000">'</span>
<span style="color: #008080">53</span>     id = Column(Integer, primary_key=<span style="color: #000000">True)
</span><span style="color: #008080">54</span>     name = Column(String(32<span style="color: #000000">))
</span><span style="color: #008080">55</span>     pwd = Column(String(64<span style="color: #000000">))
</span><span style="color: #008080">56</span>     qq = Column(Integer,nullable=False,unique=<span style="color: #000000">True)
</span><span style="color: #008080">57</span>     <span style="color: #0000ff">def</span> <span style="color: #800080">__repr__</span><span style="color: #000000">(self):
</span><span style="color: #008080">58</span>         <span style="color: #0000ff">return</span><span style="color: #000000"> self.id
</span><span style="color: #008080">59</span> 
<span style="color: #008080">60</span> <span style="color: #008000">#</span><span style="color: #008000">进度  课节表</span>
<span style="color: #008080">61</span> <span style="color: #0000ff">class</span><span style="color: #000000"> Lesson(Base):
</span><span style="color: #008080">62</span>     <span style="color: #800080">__tablename__</span>=<span style="color: #800000">'</span><span style="color: #800000">lesson</span><span style="color: #800000">'</span>
<span style="color: #008080">63</span>     id = Column(Integer, primary_key=<span style="color: #000000">True)
</span><span style="color: #008080">64</span>     name=Column(String(32),unique=True)<span style="color: #008000">#</span><span style="color: #008000">唯一课节名</span>
<span style="color: #008080">65</span>     <span style="color: #0000ff">def</span> <span style="color: #800080">__repr__</span><span style="color: #000000">(self):
</span><span style="color: #008080">66</span>         <span style="color: #0000ff">return</span><span style="color: #000000"> self.name
</span><span style="color: #008080">67</span> 
<span style="color: #008080">68</span> <span style="color: #008000">#</span><span style="color: #008000">课程表</span>
<span style="color: #008080">69</span> <span style="color: #0000ff">class</span> Class_Day(Base):<span style="color: #008000">#</span><span style="color: #008000">课程表</span>
<span style="color: #008080">70</span>     <span style="color: #800080">__tablename__</span>=<span style="color: #800000">'</span><span style="color: #800000">class_day</span><span style="color: #800000">'</span>
<span style="color: #008080">71</span>     id=Column(Integer,primary_key=<span style="color: #000000">True)
</span><span style="color: #008080">72</span>     class_id=Column(Integer,ForeignKey(<span style="color: #800000">"</span><span style="color: #800000">class_name.id</span><span style="color: #800000">"</span>),nullable=False)<span style="color: #008000">#</span><span style="color: #008000">外键 班级</span>
<span style="color: #008080">73</span>     lesson_id= Column(Integer,ForeignKey(<span style="color: #800000">"</span><span style="color: #800000">lesson.id</span><span style="color: #800000">"</span>),nullable=False)<span style="color: #008000">#</span><span style="color: #008000">课程进度</span>
<span style="color: #008080">74</span>     class_n=relationship(<span style="color: #800000">"</span><span style="color: #800000">Class_name</span><span style="color: #800000">"</span>,foreign_keys=[class_id],backref=<span style="color: #800000">"</span><span style="color: #800000">m_class_day</span><span style="color: #800000">"</span>)<span style="color: #008000">#</span><span style="color: #008000">自定义关联反查 班级Class_name通过m_class_day 查Class_day</span>
<span style="color: #008080">75</span>     lesson_n=relationship(<span style="color: #800000">"</span><span style="color: #800000">Lesson</span><span style="color: #800000">"</span>,foreign_keys=[lesson_id],backref=<span style="color: #800000">"</span><span style="color: #800000">m_lesson_day</span><span style="color: #800000">"</span>)<span style="color: #008000">#</span><span style="color: #008000">自定义关联反查 课节Lesson通过m_lesson_day 查Class_day</span>
<span style="color: #008080">76</span>     <span style="color: #0000ff">def</span> <span style="color: #800080">__repr__</span><span style="color: #000000">(self):
</span><span style="color: #008080">77</span>         <span style="color: #0000ff">return</span> self.id<span style="color: #008000">#</span><span style="color: #008000">课程名ID</span>
<span style="color: #008080">78</span> 
<span style="color: #008080">79</span> <span style="color: #0000ff">class</span> Student_work(Base):<span style="color: #008000">#</span><span style="color: #008000">  作业 上 课记录</span>
<span style="color: #008080">80</span>     <span style="color: #800080">__tablename__</span>=<span style="color: #800000">'</span><span style="color: #800000">student_work</span><span style="color: #800000">'</span>
<span style="color: #008080">81</span>     id=Column(Integer,primary_key=<span style="color: #000000">True)
</span><span style="color: #008080">82</span>     students_id=Column(Integer,ForeignKey(<span style="color: #800000">"</span><span style="color: #800000">student.id</span><span style="color: #800000">"</span>))<span style="color: #008000">#</span><span style="color: #008000">外键 学员ID</span>
<span style="color: #008080">83</span>     class_id= Column(Integer,ForeignKey(<span style="color: #800000">'</span><span style="color: #800000">class_day.id</span><span style="color: #800000">'</span>))<span style="color: #008000">#</span><span style="color: #008000">班级课程 日期 ID</span>
<span style="color: #008080">84</span>     status= Column(String(32),nullable=False)<span style="color: #008000">#</span><span style="color: #008000">作业提交 状态</span>
<span style="color: #008080">85</span>     results= Column(String(64))<span style="color: #008000">#</span><span style="color: #008000">成绩</span>
<span style="color: #008080">86</span>     students_w=relationship(<span style="color: #800000">"</span><span style="color: #800000">Student</span><span style="color: #800000">"</span>,foreign_keys=[students_id],backref=<span style="color: #800000">"</span><span style="color: #800000">m_study_class</span><span style="color: #800000">"</span>)<span style="color: #008000">#</span><span style="color: #008000">自定义关联反查 学员类Student通过m_study_class 查student_work</span>
<span style="color: #008080">87</span>     stu_class=relationship(<span style="color: #800000">"</span><span style="color: #800000">Class_Day</span><span style="color: #800000">"</span>,foreign_keys=[class_id],backref=<span style="color: #800000">"</span><span style="color: #800000">class_stu_work</span><span style="color: #800000">"</span>)<span style="color: #008000">#</span><span style="color: #008000">自定义关联反查 班级Class_name通过m_class_study 查Student_work</span>
<span style="color: #008080">88</span> 
<span style="color: #008080">89</span> <span style="color: #0000ff">class</span><span style="color: #000000"> Admin_user(Base):
</span><span style="color: #008080">90</span>     <span style="color: #800080">__tablename__</span>=<span style="color: #800000">'</span><span style="color: #800000">admin_user</span><span style="color: #800000">'</span>
<span style="color: #008080">91</span>     id=Column(Integer,primary_key=<span style="color: #000000">True)
</span><span style="color: #008080">92</span>     name=Column(String(32),nullable=False,unique=<span style="color: #000000">True)
</span><span style="color: #008080">93</span>     pwd=Column(String(64),nullable=<span style="color: #000000">False)
</span><span style="color: #008080">94</span> 
<span style="color: #008080">95</span> <span style="color: #008000">#</span><span style="color: #008000">                      用户 密码  主机             库</span>
<span style="color: #008080">96</span> engine = create_engine(config.HOSTS,)<span style="color: #008000">#</span><span style="color: #008000">连接</span>
<span style="color: #008080">97</span> Base.metadata.create_all(engine)<span style="color: #008000">#</span><span style="color: #008000">创建表结构</span>
View Code
|      |- - -admin_log.py#管理员逻辑 类
<span style="color: #008080">  1</span> <span style="color: #008000">#</span><span style="color: #008000">!usr/bin/env python</span>
<span style="color: #008080">  2</span> <span style="color: #008000">#</span><span style="color: #008000">-*-coding:utf-8-*-</span>
<span style="color: #008080">  3</span> <span style="color: #008000">#</span><span style="color: #008000"> Author calmyan </span>
<span style="color: #008080">  4</span> <span style="color: #008000">#</span><span style="color: #008000">python </span>
<span style="color: #008080">  5</span> <span style="color: #008000">#</span><span style="color: #008000">2017/7/9    23:12</span>
<span style="color: #008080">  6</span> <span style="color: #008000">#</span><span style="color: #008000">__author__='Administrator'</span>
<span style="color: #008080">  7</span> <span style="color: #0000ff">import</span><span style="color: #000000"> os ,sys
</span><span style="color: #008080">  8</span> BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(<span style="color: #800080">__file__</span>)))<span style="color: #008000">#</span><span style="color: #008000">获取相对路径转为绝对路径赋于变量</span>
<span style="color: #008080">  9</span> sys.path.append(BASE_DIR)<span style="color: #008000">#</span><span style="color: #008000">增加环境变量</span>
<span style="color: #008080"> 10</span> <span style="color: #0000ff">from</span> sqlalchemy.orm <span style="color: #0000ff">import</span><span style="color: #000000"> sessionmaker, relationship
</span><span style="color: #008080"> 11</span> <span style="color: #0000ff">from</span> core <span style="color: #0000ff">import</span><span style="color: #000000"> admin_class
</span><span style="color: #008080"> 12</span> <span style="color: #0000ff">from</span> cfg <span style="color: #0000ff">import</span><span style="color: #000000"> config
</span><span style="color: #008080"> 13</span> <span style="color: #008000">#</span><span style="color: #008000">管理登陆</span>
<span style="color: #008080"> 14</span> <span style="color: #0000ff">class</span><span style="color: #000000"> Admin_Mag(object):
</span><span style="color: #008080"> 15</span>     <span style="color: #0000ff">def</span> <span style="color: #800080">__init__</span><span style="color: #000000">(self):
</span><span style="color: #008080"> 16</span>         self.Session_class=sessionmaker(bind=admin_class.engine)<span style="color: #008000">#</span><span style="color: #008000">创建与数据库的会话 类</span>
<span style="color: #008080"> 17</span>         self.Session=self.Session_class()<span style="color: #008000">#</span><span style="color: #008000">生成实例</span>
<span style="color: #008080"> 18</span>     <span style="color: #008000">#</span><span style="color: #008000">开始相关操作</span>
<span style="color: #008080"> 19</span>     <span style="color: #0000ff">def</span> openatin(self):<span style="color: #008000">#</span><span style="color: #008000">开始相关操作</span>
<span style="color: #008080"> 20</span>         <span style="color: #0000ff">while</span><span style="color: #000000"> True:
</span><span style="color: #008080"> 21</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">\033[35;1m管理员界面\033[0m</span><span style="color: #800000">'</span>.center(60,<span style="color: #800000">'</span><span style="color: #800000">=</span><span style="color: #800000">'</span><span style="color: #000000">))
</span><span style="color: #008080"> 22</span>             <span style="color: #0000ff">for</span> index,i <span style="color: #0000ff">in</span><span style="color: #000000"> enumerate(config.ADMIN_OPEN):
</span><span style="color: #008080"> 23</span>                 <span style="color: #0000ff">print</span>(index,<span style="color: #800000">'</span><span style="color: #800000">:</span><span style="color: #800000">'</span><span style="color: #000000">,i[0])
</span><span style="color: #008080"> 24</span>             id=input(<span style="color: #800000">'</span><span style="color: #800000">请选择>>:</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080"> 25</span>             <span style="color: #0000ff">if</span><span style="color: #000000"> id.isdigit():
</span><span style="color: #008080"> 26</span>                 <span style="color: #0000ff">if</span> int(id)>=len(config.ADMIN_OPEN):<span style="color: #0000ff">continue</span>
<span style="color: #008080"> 27</span>                 s=config.ADMIN_OPEN[int(id)][1<span style="color: #000000">]
</span><span style="color: #008080"> 28</span>             <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080"> 29</span>                 <span style="color: #0000ff">continue</span>
<span style="color: #008080"> 30</span>             <span style="color: #0000ff">if</span> hasattr(self,s):<span style="color: #008000">#</span><span style="color: #008000">是反射否存在</span>
<span style="color: #008080"> 31</span>                 func=getattr(self,s)<span style="color: #008000">#</span><span style="color: #008000">调用</span>
<span style="color: #008080"> 32</span>                 func()<span style="color: #008000">#</span><span style="color: #008000">执行</span>
<span style="color: #008080"> 33</span> 
<span style="color: #008080"> 34</span>     <span style="color: #008000">#</span><span style="color: #008000">关联讲师班级</span>
<span style="color: #008080"> 35</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> assoc(self):
</span><span style="color: #008080"> 36</span>         t_id=<span style="color: #000000">self.tech_cher()
</span><span style="color: #008080"> 37</span>         cla_id=<span style="color: #000000">self.class_cher()
</span><span style="color: #008080"> 38</span>         <span style="color: #008000">#</span><span style="color: #008000">讲师表对象</span>
<span style="color: #008080"> 39</span>         t=self.Session.query(admin_class.Teacher).filter(admin_class.Teacher.id==<span style="color: #000000">t_id).first()
</span><span style="color: #008080"> 40</span>         <span style="color: #008000">#</span><span style="color: #008000">获取班级对象</span>
<span style="color: #008080"> 41</span>         c=self.Session.query(admin_class.Class_name).filter(admin_class.Class_name.id==<span style="color: #000000">cla_id).first()
</span><span style="color: #008080"> 42</span> <span style="color: #000000">        t.class_n.append(c)
</span><span style="color: #008080"> 43</span> <span style="color: #000000">        self.Session.commit()
</span><span style="color: #008080"> 44</span>         <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">讲师:</span><span style="color: #800000">'</span>,t.name,<span style="color: #800000">'</span><span style="color: #800000">班级:</span><span style="color: #800000">'</span><span style="color: #000000">,c.name)
</span><span style="color: #008080"> 45</span>         <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">关联完成!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080"> 46</span> 
<span style="color: #008080"> 47</span>     <span style="color: #008000">#</span><span style="color: #008000">讲师表对象</span>
<span style="color: #008080"> 48</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> tech_cher(self):
</span><span style="color: #008080"> 49</span>         <span style="color: #008000">#</span><span style="color: #008000">t=self.Session.query(admin_class.Teacher).all()#讲师表对象</span>
<span style="color: #008080"> 50</span>         t=<span style="color: #000000">self.teach_l()
</span><span style="color: #008080"> 51</span>         <span style="color: #008000">#</span><span style="color: #008000">for i in t :</span>
<span style="color: #008080"> 52</span>             <span style="color: #008000">#</span><span style="color: #008000">print('编号',i.id,'>>:',i.name)</span>
<span style="color: #008080"> 53</span>         t_id=input(<span style="color: #800000">'</span><span style="color: #800000">请按编号选择讲师>>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080"> 54</span>         <span style="color: #0000ff">if</span>  t_id.isdigit() :<span style="color: #008000">#</span><span style="color: #008000">判断是否是整数</span>
<span style="color: #008080"> 55</span>             <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span> t:<span style="color: #008000">#
</span><span style="color: #008080"> 56</span>                 <span style="color: #0000ff">if</span> int(t_id)==<span style="color: #000000">i.id:
</span><span style="color: #008080"> 57</span>                     <span style="color: #0000ff">return</span> int(t_id)<span style="color: #008000">#</span><span style="color: #008000">返回班级ID</span>
<span style="color: #008080"> 58</span>             <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080"> 59</span>                 <span style="color: #0000ff">pass</span>
<span style="color: #008080"> 60</span>         <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080"> 61</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">选择讲师有误!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080"> 62</span>             <span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080"> 63</span>     <span style="color: #008000">#</span><span style="color: #008000">创建班级</span>
<span style="color: #008080"> 64</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> add_class(self):
</span><span style="color: #008080"> 65</span>         <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">\033[35;1m创建班级界面\033[0m</span><span style="color: #800000">'</span>.center(60,<span style="color: #800000">'</span><span style="color: #800000">=</span><span style="color: #800000">'</span><span style="color: #000000">))
</span><span style="color: #008080"> 66</span> <span style="color: #000000">        self.class_l()
</span><span style="color: #008080"> 67</span>         attr=input(<span style="color: #800000">"</span><span style="color: #800000">输入班级名>>:</span><span style="color: #800000">"</span><span style="color: #000000">).strip()
</span><span style="color: #008080"> 68</span>         self.class_list=self.Session.query(admin_class.Class_name).all()<span style="color: #008000">#</span><span style="color: #008000">获取班级名列表</span>
<span style="color: #008080"> 69</span>         <span style="color: #0000ff">if</span> attr <span style="color: #0000ff">in</span> self.class_list:<span style="color: #008000">#</span><span style="color: #008000">如果存在</span>
<span style="color: #008080"> 70</span>             <span style="color: #0000ff">return</span> <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">班级名重复!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080"> 71</span>         c=admin_class.Class_name(name=attr)<span style="color: #008000">#</span><span style="color: #008000">创建新班级</span>
<span style="color: #008080"> 72</span> <span style="color: #000000">        self.add_all(c)
</span><span style="color: #008080"> 73</span> 
<span style="color: #008080"> 74</span>     <span style="color: #008000">#</span><span style="color: #008000">查看讲师</span>
<span style="color: #008080"> 75</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> teach_l(self):
</span><span style="color: #008080"> 76</span>         t=<span style="color: #000000">self.Session.query(admin_class.Teacher).all()
</span><span style="color: #008080"> 77</span>         <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span><span style="color: #000000"> t:
</span><span style="color: #008080"> 78</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">编号:</span><span style="color: #800000">'</span>,i.id,<span style="color: #800000">'</span><span style="color: #800000">讲师姓名:</span><span style="color: #800000">'</span>,i.name,<span style="color: #800000">'</span><span style="color: #800000">用户名:</span><span style="color: #800000">'</span>,i.user,<span style="color: #800000">'</span><span style="color: #800000">密码</span><span style="color: #800000">'</span>,i.pwd,<span style="color: #800000">'</span><span style="color: #800000"> 管理班级:</span><span style="color: #800000">'</span><span style="color: #000000">,i.class_n)
</span><span style="color: #008080"> 79</span>         <span style="color: #0000ff">return</span><span style="color: #000000"> t
</span><span style="color: #008080"> 80</span> 
<span style="color: #008080"> 81</span> 
<span style="color: #008080"> 82</span>     <span style="color: #008000">#</span><span style="color: #008000">查看班级</span>
<span style="color: #008080"> 83</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> class_l(self):
</span><span style="color: #008080"> 84</span>         c=self.Session.query(admin_class.Class_name).all()<span style="color: #008000">#</span><span style="color: #008000">班级对象</span>
<span style="color: #008080"> 85</span>         <span style="color: #0000ff">print</span>(<span style="color: #800000">"</span><span style="color: #800000">全部班级信息</span><span style="color: #800000">"</span>.center(50,<span style="color: #800000">'</span><span style="color: #800000">-</span><span style="color: #800000">'</span><span style="color: #000000">))
</span><span style="color: #008080"> 86</span>         <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span><span style="color: #000000"> c:
</span><span style="color: #008080"> 87</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">编号</span><span style="color: #800000">'</span>,i.id,<span style="color: #800000">'</span><span style="color: #800000">>>:</span><span style="color: #800000">'</span><span style="color: #000000">,i.name)
</span><span style="color: #008080"> 88</span>         <span style="color: #0000ff">return</span><span style="color: #000000"> c
</span><span style="color: #008080"> 89</span> 
<span style="color: #008080"> 90</span>     <span style="color: #008000">#</span><span style="color: #008000">查看班级选择</span>
<span style="color: #008080"> 91</span>     <span style="color: #0000ff">def</span> class_cher(self):<span style="color: #008000">#</span><span style="color: #008000">查看班级</span>
<span style="color: #008080"> 92</span>         c=<span style="color: #000000">self.class_l()
</span><span style="color: #008080"> 93</span>         class_id=input(<span style="color: #800000">'</span><span style="color: #800000">请按编号选择班级>>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080"> 94</span>         <span style="color: #0000ff">if</span>  class_id.isdigit() :<span style="color: #008000">#</span><span style="color: #008000">判断是否是整数</span>
<span style="color: #008080"> 95</span>             <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span> c:<span style="color: #008000">#
</span><span style="color: #008080"> 96</span>                 <span style="color: #0000ff">if</span> int(class_id)==<span style="color: #000000">i.id:
</span><span style="color: #008080"> 97</span>                     <span style="color: #0000ff">return</span> int(class_id)<span style="color: #008000">#</span><span style="color: #008000">返回班级ID</span>
<span style="color: #008080"> 98</span>             <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080"> 99</span>                 <span style="color: #0000ff">pass</span>
<span style="color: #008080">100</span>         <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">101</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">选择班级有误!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">102</span>             <span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080">103</span>     <span style="color: #008000">#</span><span style="color: #008000">创建讲师</span>
<span style="color: #008080">104</span>     <span style="color: #0000ff">def</span> add_teach(self):<span style="color: #008000">#</span><span style="color: #008000">创建讲师</span>
<span style="color: #008080">105</span>         <span style="color: #0000ff">while</span><span style="color: #000000"> True:
</span><span style="color: #008080">106</span>             name =input(<span style="color: #800000">'</span><span style="color: #800000">输入讲师姓名>>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080">107</span>             user =input(<span style="color: #800000">'</span><span style="color: #800000">输入讲师用户名>>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080">108</span>             pwd =input(<span style="color: #800000">'</span><span style="color: #800000">输入讲师密码>>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080">109</span>             t1 = admin_class.Teacher(name=name,user=user,pwd=<span style="color: #000000">pwd)
</span><span style="color: #008080">110</span> <span style="color: #000000">            self.add_all(t1)
</span><span style="color: #008080">111</span>             e=input(<span style="color: #800000">'</span><span style="color: #800000">是否继续 Y/y 继续! 其他返回</span><span style="color: #800000">'</span><span style="color: #000000">).upper().strip()
</span><span style="color: #008080">112</span>             <span style="color: #0000ff">if</span> e==<span style="color: #800000">'</span><span style="color: #800000">Y</span><span style="color: #800000">'</span>:<span style="color: #0000ff">continue</span>
<span style="color: #008080">113</span>             <span style="color: #0000ff">break</span>
<span style="color: #008080">114</span>     <span style="color: #008000">#</span><span style="color: #008000">学员添加</span>
<span style="color: #008080">115</span>     <span style="color: #0000ff">def</span> add_stu(self):<span style="color: #008000">#</span><span style="color: #008000">学员添加</span>
<span style="color: #008080">116</span>         <span style="color: #0000ff">while</span><span style="color: #000000"> True:
</span><span style="color: #008080">117</span>             name =input(<span style="color: #800000">'</span><span style="color: #800000">输入学员姓名>>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080">118</span>             pwd =input(<span style="color: #800000">'</span><span style="color: #800000">输入学员密码>>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080">119</span>             qq =input(<span style="color: #800000">'</span><span style="color: #800000">输入学员QQ>>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080">120</span>             <span style="color: #0000ff">if</span> <span style="color: #0000ff">not</span><span style="color: #000000"> qq.isdigit():
</span><span style="color: #008080">121</span>                 <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">QQ必需是数字</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">122</span>                 <span style="color: #0000ff">continue</span>
<span style="color: #008080">123</span>             s=admin_class.Student(name=name,pwd=pwd,qq=<span style="color: #000000">int(qq))
</span><span style="color: #008080">124</span> <span style="color: #000000">            self.add_all(s)
</span><span style="color: #008080">125</span>             e=input(<span style="color: #800000">'</span><span style="color: #800000">是否继续 Y/y 继续! 其他返回</span><span style="color: #800000">'</span><span style="color: #000000">).upper().strip()
</span><span style="color: #008080">126</span>             <span style="color: #0000ff">if</span> e==<span style="color: #800000">'</span><span style="color: #800000">Y</span><span style="color: #800000">'</span>:<span style="color: #0000ff">continue</span>
<span style="color: #008080">127</span>             <span style="color: #0000ff">break</span>
<span style="color: #008080">128</span> 
<span style="color: #008080">129</span>     <span style="color: #008000">#</span><span style="color: #008000">查看学员</span>
<span style="color: #008080">130</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> stu_l(self):
</span><span style="color: #008080">131</span>         student_l=<span style="color: #000000">self.Session.query(admin_class.Student).all()
</span><span style="color: #008080">132</span>         <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span><span style="color: #000000"> student_l:
</span><span style="color: #008080">133</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">ID:</span><span style="color: #800000">'</span>,i.id,<span style="color: #800000">'</span><span style="color: #800000">学员姓名:</span><span style="color: #800000">'</span>,i.name,<span style="color: #800000">'</span><span style="color: #800000">QQ:</span><span style="color: #800000">'</span>,i.qq,<span style="color: #800000">'</span><span style="color: #800000">培训班级:</span><span style="color: #800000">'</span><span style="color: #000000">,i.class_name)
</span><span style="color: #008080">134</span>         <span style="color: #0000ff">return</span><span style="color: #000000"> student_l
</span><span style="color: #008080">135</span> 
<span style="color: #008080">136</span>     <span style="color: #008000">#</span><span style="color: #008000">学员选择</span>
<span style="color: #008080">137</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> stu_cher(self):
</span><span style="color: #008080">138</span>         student_l=<span style="color: #000000">self.stu_l()
</span><span style="color: #008080">139</span>         stu_id=input(<span style="color: #800000">'</span><span style="color: #800000">请按ID选择学员>>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080">140</span>         <span style="color: #0000ff">if</span>  stu_id.isdigit() :<span style="color: #008000">#</span><span style="color: #008000">判断是否是整数</span>
<span style="color: #008080">141</span>             <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span> student_l:<span style="color: #008000">#
</span><span style="color: #008080">142</span>                 <span style="color: #0000ff">if</span> int(stu_id)==<span style="color: #000000">i.id:
</span><span style="color: #008080">143</span>                     <span style="color: #0000ff">return</span> int(stu_id)<span style="color: #008000">#</span><span style="color: #008000">返回班级ID</span>
<span style="color: #008080">144</span>             <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">145</span>                 <span style="color: #0000ff">pass</span>
<span style="color: #008080">146</span>         <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">147</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">选择学员有误!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">148</span>             <span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080">149</span> 
<span style="color: #008080">150</span>     <span style="color: #008000">#</span><span style="color: #008000">班级关联学员</span>
<span style="color: #008080">151</span>     <span style="color: #0000ff">def</span> class_student(self):<span style="color: #008000">#</span><span style="color: #008000">班级增加学员</span>
<span style="color: #008080">152</span>         <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">\033[35;1m班级关联学员界面\033[0m</span><span style="color: #800000">'</span>.center(60,<span style="color: #800000">'</span><span style="color: #800000">=</span><span style="color: #800000">'</span><span style="color: #000000">))
</span><span style="color: #008080">153</span>         cla_id=self.class_cher()<span style="color: #008000">#</span><span style="color: #008000">调用查看班级</span>
<span style="color: #008080">154</span>         <span style="color: #0000ff">if</span> <span style="color: #0000ff">not</span> cla_id:<span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080">155</span>         <span style="color: #008000">#</span><span style="color: #008000">获取班级对象</span>
<span style="color: #008080">156</span>         c=self.Session.query(admin_class.Class_name).filter(admin_class.Class_name.id==<span style="color: #000000">cla_id).first()
</span><span style="color: #008080">157</span>         <span style="color: #0000ff">if</span> <span style="color: #0000ff">not</span> c:<span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080">158</span>         stu_id=<span style="color: #000000">self.stu_cher()
</span><span style="color: #008080">159</span>         <span style="color: #008000">#</span><span style="color: #008000">student_qq=input('请输入学生QQ号码>>:').strip()</span>
<span style="color: #008080">160</span>         s_qq=self.Session.query(admin_class.Student).filter(admin_class.Student.id==stu_id).first()<span style="color: #008000">#</span><span style="color: #008000">学员qq对象</span>
<span style="color: #008080">161</span>         <span style="color: #0000ff">if</span> s_qq:<span style="color: #008000">#</span><span style="color: #008000">如果有这个qq</span>
<span style="color: #008080">162</span>             c.students.append(s_qq)<span style="color: #008000">#</span><span style="color: #008000">加入班级</span>
<span style="color: #008080">163</span> <span style="color: #000000">            self.Session.commit()
</span><span style="color: #008080">164</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">加入班级成功!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">165</span>         <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">166</span>             <span style="color: #0000ff">return</span> <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">对应的学员不存在</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">167</span> 
<span style="color: #008080">168</span>     <span style="color: #008000">#</span><span style="color: #008000">增加函数</span>
<span style="color: #008080">169</span>     <span style="color: #0000ff">def</span> add_all(self,lists):<span style="color: #008000">#</span><span style="color: #008000">增加函数</span>
<span style="color: #008080">170</span> <span style="color: #000000">        self.Session.add_all([lists])
</span><span style="color: #008080">171</span>         confirm=input(<span style="color: #800000">'</span><span style="color: #800000">请进行确认: 按\033[31;1mN\033[0m回滚操作,其他键确认!</span><span style="color: #800000">'</span><span style="color: #000000"> ).upper().strip()
</span><span style="color: #008080">172</span>         <span style="color: #0000ff">if</span> confirm==<span style="color: #800000">"</span><span style="color: #800000">N</span><span style="color: #800000">"</span><span style="color: #000000">:
</span><span style="color: #008080">173</span>             self.Session.rollback()<span style="color: #008000">#
</span><span style="color: #008080">174</span>             <span style="color: #0000ff">return</span><span style="color: #000000"> False
</span><span style="color: #008080">175</span>         <span style="color: #0000ff">try</span><span style="color: #000000">:
</span><span style="color: #008080">176</span> <span style="color: #000000">            self.Session.commit()
</span><span style="color: #008080">177</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">操作成功</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">178</span>             <span style="color: #0000ff">return</span>
<span style="color: #008080">179</span>         <span style="color: #0000ff">except</span><span style="color: #000000"> Exception as e:
</span><span style="color: #008080">180</span>             self.Session.rollback()<span style="color: #008000">#
</span><span style="color: #008080">181</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">操作失败!,可能该信息已经存在!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">182</span>             <span style="color: #0000ff">print</span><span style="color: #000000">(e)
</span><span style="color: #008080">183</span>             <span style="color: #0000ff">return</span>
<span style="color: #008080">184</span>     <span style="color: #008000">#</span><span style="color: #008000">退出</span>
<span style="color: #008080">185</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> tech_exit(self):
</span><span style="color: #008080">186</span>         <span style="color: #0000ff">return</span><span style="color: #000000">  exit()
</span><span style="color: #008080">187</span> 
<span style="color: #008080">188</span>      <span style="color: #008000">#</span><span style="color: #008000">登陆</span>
<span style="color: #008080">189</span>     <span style="color: #008000">#</span><span style="color: #008000">登陆</span>
<span style="color: #008080">190</span>     <span style="color: #0000ff">def</span> user_log(self):<span style="color: #008000">#</span><span style="color: #008000">登陆</span>
<span style="color: #008080">191</span>         user_n=input(<span style="color: #800000">'</span><span style="color: #800000">请输入管理员用户名>>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080">192</span>         aut_obj=self.Session.query(admin_class.Admin_user).filter(admin_class.Admin_user.name==<span style="color: #000000">user_n).first()
</span><span style="color: #008080">193</span>         <span style="color: #0000ff">if</span><span style="color: #000000"> aut_obj:
</span><span style="color: #008080">194</span>             <span style="color: #008000">#</span><span style="color: #008000">print(self.aut_obj_1.pwd)#用户对应密码</span>
<span style="color: #008080">195</span>             pwds=input(<span style="color: #800000">'</span><span style="color: #800000">请输入密码>>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080">196</span>             <span style="color: #0000ff">if</span> pwds ==<span style="color: #000000"> aut_obj.pwd:
</span><span style="color: #008080">197</span> 
<span style="color: #008080">198</span> <span style="color: #000000">                self.openatin()
</span><span style="color: #008080">199</span>             <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">200</span>                 <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">密码有误</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">201</span>                 <span style="color: #0000ff">return</span>
<span style="color: #008080">202</span>         <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">203</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">输入的用户名不存</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">204</span>             <span style="color: #0000ff">return</span>
View Code
|      |- - -student_class.py#学员逻辑 类
<span style="color: #008080">  1</span> <span style="color: #008000">#</span><span style="color: #008000">!usr/bin/env python</span>
<span style="color: #008080">  2</span> <span style="color: #008000">#</span><span style="color: #008000">-*-coding:utf-8-*-</span>
<span style="color: #008080">  3</span> <span style="color: #008000">#</span><span style="color: #008000"> Author calmyan </span>
<span style="color: #008080">  4</span> <span style="color: #008000">#</span><span style="color: #008000">python </span>
<span style="color: #008080">  5</span> <span style="color: #008000">#</span><span style="color: #008000">2017/7/8    12:29</span>
<span style="color: #008080">  6</span> <span style="color: #008000">#</span><span style="color: #008000">__author__='Administrator'</span>
<span style="color: #008080">  7</span> <span style="color: #0000ff">import</span><span style="color: #000000"> os ,sys
</span><span style="color: #008080">  8</span> BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(<span style="color: #800080">__file__</span>)))<span style="color: #008000">#</span><span style="color: #008000">获取相对路径转为绝对路径赋于变量</span>
<span style="color: #008080">  9</span> sys.path.append(BASE_DIR)<span style="color: #008000">#</span><span style="color: #008000">增加环境变量</span>
<span style="color: #008080"> 10</span> <span style="color: #0000ff">from</span> sqlalchemy.ext.declarative <span style="color: #0000ff">import</span><span style="color: #000000"> declarative_base
</span><span style="color: #008080"> 11</span> <span style="color: #0000ff">from</span> sqlalchemy <span style="color: #0000ff">import</span><span style="color: #000000"> Column, Integer, String, ForeignKey, UniqueConstraint, Index
</span><span style="color: #008080"> 12</span> <span style="color: #0000ff">from</span> sqlalchemy.orm <span style="color: #0000ff">import</span><span style="color: #000000"> sessionmaker, relationship
</span><span style="color: #008080"> 13</span> <span style="color: #0000ff">from</span> sqlalchemy <span style="color: #0000ff">import</span><span style="color: #000000"> create_engine
</span><span style="color: #008080"> 14</span> <span style="color: #0000ff">from</span> sqlalchemy <span style="color: #0000ff">import</span> func <span style="color: #008000">#</span><span style="color: #008000">统计</span>
<span style="color: #008080"> 15</span> <span style="color: #0000ff">from</span>  core <span style="color: #0000ff">import</span><span style="color: #000000"> admin_class
</span><span style="color: #008080"> 16</span> <span style="color: #0000ff">from</span>  cfg <span style="color: #0000ff">import</span><span style="color: #000000"> config
</span><span style="color: #008080"> 17</span> <span style="color: #008000">#</span><span style="color: #008000">学员类</span>
<span style="color: #008080"> 18</span> <span style="color: #0000ff">class</span><span style="color: #000000"> Stu_Mag(object):
</span><span style="color: #008080"> 19</span> 
<span style="color: #008080"> 20</span>     <span style="color: #0000ff">def</span> <span style="color: #800080">__init__</span><span style="color: #000000">(self):
</span><span style="color: #008080"> 21</span>         self.Session_class=sessionmaker(bind=admin_class.engine)<span style="color: #008000">#</span><span style="color: #008000">创建与数据库的会话 类</span>
<span style="color: #008080"> 22</span>         self.Session=self.Session_class()<span style="color: #008000">#</span><span style="color: #008000">生成实例</span>
<span style="color: #008080"> 23</span>         self.stu_name=<span style="color: #800000">''</span><span style="color: #008000">#</span><span style="color: #008000">学员姓名</span>
<span style="color: #008080"> 24</span> 
<span style="color: #008080"> 25</span>     <span style="color: #008000">#</span><span style="color: #008000">开始相关操作</span>
<span style="color: #008080"> 26</span>     <span style="color: #0000ff">def</span> openatin(self):<span style="color: #008000">#</span><span style="color: #008000">开始相关操作</span>
<span style="color: #008080"> 27</span>         <span style="color: #0000ff">while</span><span style="color: #000000"> True:
</span><span style="color: #008080"> 28</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">\033[32;1m学员界面\033[0m</span><span style="color: #800000">'</span>.center(60,<span style="color: #800000">'</span><span style="color: #800000">=</span><span style="color: #800000">'</span><span style="color: #000000">))
</span><span style="color: #008080"> 29</span>             <span style="color: #0000ff">print</span>((<span style="color: #800000">'</span><span style="color: #800000">\033[36;1m[%s]\033[0m</span><span style="color: #800000">'</span>%self.stu_name).center(60,<span style="color: #800000">'</span><span style="color: #800000">=</span><span style="color: #800000">'</span><span style="color: #000000">))
</span><span style="color: #008080"> 30</span> 
<span style="color: #008080"> 31</span>             <span style="color: #0000ff">for</span> index,i <span style="color: #0000ff">in</span><span style="color: #000000"> enumerate(config.STUED_OPEN):
</span><span style="color: #008080"> 32</span>                 <span style="color: #0000ff">print</span>(index,<span style="color: #800000">'</span><span style="color: #800000">:</span><span style="color: #800000">'</span><span style="color: #000000">,i[0])
</span><span style="color: #008080"> 33</span>             id=input(<span style="color: #800000">'</span><span style="color: #800000">请选择>>:</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080"> 34</span>             <span style="color: #0000ff">if</span><span style="color: #000000"> id.isdigit():
</span><span style="color: #008080"> 35</span>                 <span style="color: #0000ff">if</span> int(id)>=len(config.STUED_OPEN):<span style="color: #0000ff">continue</span>
<span style="color: #008080"> 36</span>                 s=config.STUED_OPEN[int(id)][1<span style="color: #000000">]
</span><span style="color: #008080"> 37</span>             <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080"> 38</span>                 <span style="color: #0000ff">continue</span>
<span style="color: #008080"> 39</span>             <span style="color: #0000ff">if</span> hasattr(self,s):<span style="color: #008000">#</span><span style="color: #008000">是反射否存在</span>
<span style="color: #008080"> 40</span>                 func=getattr(self,s)<span style="color: #008000">#</span><span style="color: #008000">调用</span>
<span style="color: #008080"> 41</span>                 func()<span style="color: #008000">#</span><span style="color: #008000">执行</span>
<span style="color: #008080"> 42</span> 
<span style="color: #008080"> 43</span>     <span style="color: #008000">#</span><span style="color: #008000">提交作业</span>
<span style="color: #008080"> 44</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> up_work(self):
</span><span style="color: #008080"> 45</span>         class_id=<span style="color: #000000">self.class_l()
</span><span style="color: #008080"> 46</span>         <span style="color: #0000ff">if</span> <span style="color: #0000ff">not</span><span style="color: #000000"> class_id:
</span><span style="color: #008080"> 47</span>             <span style="color: #0000ff">return</span> None<span style="color: #008000">#</span><span style="color: #008000">班级ID</span>
<span style="color: #008080"> 48</span>         les_id=self.lessn_obj(class_id)<span style="color: #008000">#</span><span style="color: #008000">课节表ID\</span>
<span style="color: #008080"> 49</span>         <span style="color: #0000ff">if</span> <span style="color: #0000ff">not</span> les_id:<span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080"> 50</span>         cl_dayid=self.class_less(class_id,les_id)<span style="color: #008000">#</span><span style="color: #008000">课程表ID</span>
<span style="color: #008080"> 51</span>         <span style="color: #0000ff">if</span><span style="color: #000000"> cl_dayid:
</span><span style="color: #008080"> 52</span>             stu_id=self.stu_obj.id<span style="color: #008000">#</span><span style="color: #008000">学员ID</span>
<span style="color: #008080"> 53</span>             stu_work=self.Session.query(admin_class.Student_work).filter_by(students_id=stu_id,class_id=<span style="color: #000000">cl_dayid.id).first()
</span><span style="color: #008080"> 54</span>             <span style="color: #0000ff">if</span><span style="color: #000000"> stu_work:
</span><span style="color: #008080"> 55</span>                 <span style="color: #0000ff">if</span> stu_work.status==<span style="color: #800000">'</span><span style="color: #800000">yes</span><span style="color: #800000">'</span><span style="color: #000000">:
</span><span style="color: #008080"> 56</span>                     <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">\033[31;1m作业已经提交,不能重复提交!\033[0m</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080"> 57</span>                     <span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080"> 58</span>                 <span style="color: #008000">#</span><span style="color: #008000">对应的课程表</span>
<span style="color: #008080"> 59</span>                 les_n=self.Session.query(admin_class.Class_Day).filter_by(class_id=class_id,lesson_id=<span style="color: #000000">les_id).first()
</span><span style="color: #008080"> 60</span>                 <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">姓名:</span><span style="color: #800000">'</span>,self.stu_name,<span style="color: #800000">'</span><span style="color: #800000">班级:</span><span style="color: #800000">'</span>,les_n.class_n,<span style="color: #800000">'</span><span style="color: #800000">课节:</span><span style="color: #800000">'</span>,les_n.lesson_n,<span style="color: #800000">'</span><span style="color: #800000">作业提交状态:</span><span style="color: #800000">'</span>,stu_work.status,<span style="color: #800000">'</span><span style="color: #800000">成绩:</span><span style="color: #800000">'</span><span style="color: #000000">,stu_work.results)
</span><span style="color: #008080"> 61</span>                 chend=input(<span style="color: #800000">'</span><span style="color: #800000">提交作业>>>: Y/y 确认!</span><span style="color: #800000">'</span><span style="color: #000000">).upper().strip()
</span><span style="color: #008080"> 62</span>                 <span style="color: #0000ff">if</span> chend==<span style="color: #800000">'</span><span style="color: #800000">Y</span><span style="color: #800000">'</span><span style="color: #000000">:
</span><span style="color: #008080"> 63</span>                     self.Session.query(admin_class.Student_work).filter_by(students_id=stu_id,class_id=cl_dayid.id).update({<span style="color: #800000">"</span><span style="color: #800000">status</span><span style="color: #800000">"</span>:<span style="color: #800000">"</span><span style="color: #800000">yes</span><span style="color: #800000">"</span><span style="color: #000000">})
</span><span style="color: #008080"> 64</span>                     <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">提交完成!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080"> 65</span> <span style="color: #000000">                    self.Session.commit()
</span><span style="color: #008080"> 66</span>                     <span style="color: #0000ff">return</span>
<span style="color: #008080"> 67</span>                 <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080"> 68</span>                     <span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080"> 69</span>             <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080"> 70</span>                 <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">\033[31;1m您可能没有上本节课!无法提交\033[0m</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080"> 71</span>                 <span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080"> 72</span>         <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080"> 73</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">\033[31;1m本节课可能没有开始!\033[0m</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080"> 74</span>             <span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080"> 75</span> 
<span style="color: #008080"> 76</span> 
<span style="color: #008080"> 77</span>     <span style="color: #008000">#</span><span style="color: #008000">获取课程ID</span>
<span style="color: #008080"> 78</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> class_less(self,cla_id,les_id):
</span><span style="color: #008080"> 79</span>         cl_dayid=self.Session.query(admin_class.Class_Day).filter(admin_class.Class_Day.class_id==<span style="color: #000000">cla_id).\
</span><span style="color: #008080"> 80</span>             filter(admin_class.Class_Day.lesson_id==les_id).first()<span style="color: #008000">#</span><span style="color: #008000">获取班级课程表id</span>
<span style="color: #008080"> 81</span>         <span style="color: #0000ff">if</span><span style="color: #000000"> cl_dayid:
</span><span style="color: #008080"> 82</span>             <span style="color: #0000ff">return</span><span style="color: #000000"> cl_dayid
</span><span style="color: #008080"> 83</span>         <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080"> 84</span>             <span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080"> 85</span> 
<span style="color: #008080"> 86</span>     <span style="color: #008000">#</span><span style="color: #008000">获取课程表 选课节</span>
<span style="color: #008080"> 87</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> lessn_obj(self,cla):
</span><span style="color: #008080"> 88</span>         les_l=self.Session.query(admin_class.Class_Day).filter_by(class_id=<span style="color: #000000">cla).all()
</span><span style="color: #008080"> 89</span>         <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span><span style="color: #000000"> les_l:
</span><span style="color: #008080"> 90</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">编号:</span><span style="color: #800000">'</span>,i.lesson_id,<span style="color: #800000">'</span><span style="color: #800000">课节:</span><span style="color: #800000">'</span><span style="color: #000000">,i.lesson_n)
</span><span style="color: #008080"> 91</span>         les_id=input(<span style="color: #800000">'</span><span style="color: #800000">请按编号选择课节 >>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080"> 92</span>         <span style="color: #0000ff">if</span><span style="color: #000000"> les_id.isdigit():
</span><span style="color: #008080"> 93</span>             <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span><span style="color: #000000"> les_l:
</span><span style="color: #008080"> 94</span>                 <span style="color: #0000ff">if</span> int(les_id)==<span style="color: #000000">i.lesson_id:
</span><span style="color: #008080"> 95</span>                     <span style="color: #0000ff">return</span> int(les_id)<span style="color: #008000">#</span><span style="color: #008000">返回课节ID</span>
<span style="color: #008080"> 96</span>             <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080"> 97</span>                 <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">选择课节有误!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080"> 98</span>                 <span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080"> 99</span>         <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">100</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">选择课节有误!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">101</span>             <span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080">102</span> 
<span style="color: #008080">103</span>     <span style="color: #008000">#</span><span style="color: #008000">查看班级选择</span>
<span style="color: #008080">104</span>     <span style="color: #0000ff">def</span> class_l(self):<span style="color: #008000">#</span><span style="color: #008000">查看班级</span>
<span style="color: #008080">105</span>         <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span><span style="color: #000000"> self.stu_obj.class_name:
</span><span style="color: #008080">106</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">编号</span><span style="color: #800000">'</span>,i.id,<span style="color: #800000">'</span><span style="color: #800000">>>:</span><span style="color: #800000">'</span><span style="color: #000000">,i.name)
</span><span style="color: #008080">107</span>         class_id=input(<span style="color: #800000">'</span><span style="color: #800000">请按编号选择班级>>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080">108</span>         <span style="color: #0000ff">if</span>  class_id.isdigit() :<span style="color: #008000">#</span><span style="color: #008000">判断是否是整数</span>
<span style="color: #008080">109</span>             <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span> self.stu_obj.class_name:<span style="color: #008000">#</span><span style="color: #008000">是否在学员的班级中</span>
<span style="color: #008080">110</span>                 <span style="color: #0000ff">if</span> int(class_id)==<span style="color: #000000">i.id:
</span><span style="color: #008080">111</span>                     <span style="color: #0000ff">return</span> int(class_id)<span style="color: #008000">#</span><span style="color: #008000">返回班级ID</span>
<span style="color: #008080">112</span>             <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">113</span>                 <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">选择班级有误!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">114</span>                 <span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080">115</span>         <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">116</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">选择班级有误!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">117</span>             <span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080">118</span> 
<span style="color: #008080">119</span>     <span style="color: #008000">#</span><span style="color: #008000">查看课节</span>
<span style="color: #008080">120</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> lesson_l(self):
</span><span style="color: #008080">121</span>         <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span><span style="color: #000000"> self.les:
</span><span style="color: #008080">122</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">编号</span><span style="color: #800000">'</span>,i.id,<span style="color: #800000">'</span><span style="color: #800000">>>:</span><span style="color: #800000">'</span><span style="color: #000000">,i)
</span><span style="color: #008080">123</span>         les_id=input(<span style="color: #800000">'</span><span style="color: #800000">请按编号选择课节 >>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080">124</span>         <span style="color: #0000ff">if</span><span style="color: #000000"> les_id.isdigit():
</span><span style="color: #008080">125</span>             <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span><span style="color: #000000"> self.les:
</span><span style="color: #008080">126</span>                 <span style="color: #0000ff">if</span> int(les_id)==<span style="color: #000000">i.id:
</span><span style="color: #008080">127</span>                     <span style="color: #0000ff">return</span> int(les_id)<span style="color: #008000">#</span><span style="color: #008000">返回课节ID</span>
<span style="color: #008080">128</span>             <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">129</span>                 <span style="color: #0000ff">pass</span>
<span style="color: #008080">130</span>         <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">131</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">选择课节有误!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">132</span>             <span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080">133</span> 
<span style="color: #008080">134</span>     <span style="color: #008000">#</span><span style="color: #008000">查看成绩</span>
<span style="color: #008080">135</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> set_resu(self):
</span><span style="color: #008080">136</span>         class_id=self.class_l()<span style="color: #008000">#</span><span style="color: #008000">班级ID</span>
<span style="color: #008080">137</span>         les_l=self.Session.query(admin_class.Class_Day).filter_by(class_id=class_id).all()<span style="color: #008000">#</span><span style="color: #008000">本班所有课节</span>
<span style="color: #008080">138</span>         stu_id=self.stu_obj.id<span style="color: #008000">#</span><span style="color: #008000">学员ID</span>
<span style="color: #008080">139</span>         <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span><span style="color: #000000"> les_l:
</span><span style="color: #008080">140</span>             stu_work=self.Session.query(admin_class.Student_work).filter_by(students_id=stu_id,class_id=i.id).first()<span style="color: #008000">#</span><span style="color: #008000">取对应的课节</span>
<span style="color: #008080">141</span>             <span style="color: #0000ff">if</span><span style="color: #000000"> stu_work:
</span><span style="color: #008080">142</span>                 cla_day=self.Session.query(admin_class.Class_Day).filter_by(id=stu_work.class_id).first()<span style="color: #008000">#</span><span style="color: #008000">课程表对象</span>
<span style="color: #008080">143</span>                 <span style="color: #0000ff">if</span><span style="color: #000000"> cla_day:
</span><span style="color: #008080">144</span>                     <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">姓名:</span><span style="color: #800000">'</span>,self.stu_name,<span style="color: #800000">'</span><span style="color: #800000">班级:</span><span style="color: #800000">'</span>,cla_day.class_n,<span style="color: #800000">'</span><span style="color: #800000">课节:</span><span style="color: #800000">'</span>,cla_day.lesson_n,<span style="color: #800000">'</span><span style="color: #800000"> 作业提交状态:</span><span style="color: #800000">'</span>,stu_work.status,<span style="color: #800000">'</span><span style="color: #800000">成绩:</span><span style="color: #800000">'</span><span style="color: #000000">,stu_work.results)
</span><span style="color: #008080">145</span>                 <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">146</span>                     <span style="color: #0000ff">pass</span>
<span style="color: #008080">147</span>             <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">148</span>                 <span style="color: #0000ff">pass</span>
<span style="color: #008080">149</span> 
<span style="color: #008080">150</span>     <span style="color: #008000">#</span><span style="color: #008000">查看排名</span>
<span style="color: #008080">151</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> cla_top(self):
</span><span style="color: #008080">152</span>         class_id=self.class_l()<span style="color: #008000">#</span><span style="color: #008000">班级ID</span>
<span style="color: #008080">153</span>         les_l=self.Session.query(admin_class.Class_Day).filter_by(class_id=class_id).all()<span style="color: #008000">#</span><span style="color: #008000">取当前班级的所有课节</span>
<span style="color: #008080">154</span>         stu_id_l=self.Session.query(admin_class.Student).all()<span style="color: #008000">#</span><span style="color: #008000">取学生id</span>
<span style="color: #008080">155</span>         top_list=[]<span style="color: #008000">#</span><span style="color: #008000">分数</span>
<span style="color: #008080">156</span>         <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span><span style="color: #000000"> stu_id_l:
</span><span style="color: #008080">157</span>             resut=<span style="color: #000000">0
</span><span style="color: #008080">158</span>             <span style="color: #0000ff">for</span> j <span style="color: #0000ff">in</span><span style="color: #000000"> les_l:
</span><span style="color: #008080">159</span>                 stu_work=self.Session.query(admin_class.Student_work).filter_by(students_id=i.id,class_id=<span style="color: #000000">j.id).first()
</span><span style="color: #008080">160</span>                 <span style="color: #0000ff">if</span> <span style="color: #0000ff">not</span> stu_work:<span style="color: #0000ff">continue</span>
<span style="color: #008080">161</span>                 <span style="color: #0000ff">if</span><span style="color: #000000"> stu_work.results:
</span><span style="color: #008080">162</span>                     resut+=<span style="color: #000000">int(stu_work.results)
</span><span style="color: #008080">163</span>             <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">164</span> <span style="color: #000000">                top_list.append((resut,i.name))
</span><span style="color: #008080">165</span>         <span style="color: #0000ff">print</span><span style="color: #000000">(top_list)
</span><span style="color: #008080">166</span> <span style="color: #000000">        self.sort(top_list)
</span><span style="color: #008080">167</span>         <span style="color: #0000ff">for</span> index,i <span style="color: #0000ff">in</span><span style="color: #000000"> enumerate(top_list):
</span><span style="color: #008080">168</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">名次</span><span style="color: #800000">'</span>,index+1,<span style="color: #800000">'</span><span style="color: #800000">总分数--姓名:</span><span style="color: #800000">'</span><span style="color: #000000">,i)
</span><span style="color: #008080">169</span> 
<span style="color: #008080">170</span>     <span style="color: #008000">#</span><span style="color: #008000">排序</span>
<span style="color: #008080">171</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> sort(self,ls):
</span><span style="color: #008080">172</span>         <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span> range(len(ls)-1<span style="color: #000000">):
</span><span style="color: #008080">173</span>             <span style="color: #0000ff">for</span> j <span style="color: #0000ff">in</span> range(len(ls)-i-1<span style="color: #000000">):
</span><span style="color: #008080">174</span>                 <span style="color: #0000ff">if</span> ls[j]<ls[j+1<span style="color: #000000">]:
</span><span style="color: #008080">175</span>                     ls[j],ls[j+1] =ls[j+1<span style="color: #000000">],ls[j]
</span><span style="color: #008080">176</span>         <span style="color: #0000ff">return</span><span style="color: #000000"> ls
</span><span style="color: #008080">177</span> 
<span style="color: #008080">178</span> 
<span style="color: #008080">179</span> 
<span style="color: #008080">180</span>     <span style="color: #008000">#</span><span style="color: #008000">退出</span>
<span style="color: #008080">181</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> tech_exit(self):
</span><span style="color: #008080">182</span>         <span style="color: #0000ff">return</span><span style="color: #000000">  exit()
</span><span style="color: #008080">183</span> 
<span style="color: #008080">184</span>     <span style="color: #008000">#</span><span style="color: #008000">登陆</span>
<span style="color: #008080">185</span>     <span style="color: #0000ff">def</span> user_log(self):<span style="color: #008000">#</span><span style="color: #008000">登陆</span>
<span style="color: #008080">186</span>             user_n=input(<span style="color: #800000">'</span><span style="color: #800000">请输入用户名(qq)>>:<span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080">187</span>             <span style="color: #0000ff">if</span> <span style="color: #0000ff">not</span> user_n.isdigit():<span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080">188</span>             aut_obj=self.Session.query(admin_class.Student).filter(admin_class.Student.qq==<span style="color: #000000">int(user_n)).first()
</span><span style="color: #008080">189</span>             <span style="color: #0000ff">if</span><span style="color: #000000"> aut_obj:
</span><span style="color: #008080">190</span>                 <span style="color: #008000">#</span><span style="color: #008000">print(self.aut_obj_1.pwd)#用户对应密码</span>
<span style="color: #008080">191</span>                 pwds=input(<span style="color: #800000">'</span><span style="color: #800000">请输入密码>>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080">192</span>                 <span style="color: #0000ff">if</span> pwds ==<span style="color: #000000"> aut_obj.pwd:
</span><span style="color: #008080">193</span>                     self.stu_name=<span style="color: #000000">aut_obj.name
</span><span style="color: #008080">194</span>                     self.qq=<span style="color: #000000">aut_obj.qq
</span><span style="color: #008080">195</span>                     self.stu_obj = self.Session.query(admin_class.Student).filter(admin_class.Student.qq==self.qq).first()<span style="color: #008000">#</span><span style="color: #008000">取当前学员对象实例</span>
<span style="color: #008080">196</span> <span style="color: #000000">                    self.openatin()
</span><span style="color: #008080">197</span>                 <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">198</span>                     <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">密码有误</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">199</span>                     <span style="color: #0000ff">return</span>
<span style="color: #008080">200</span>             <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">201</span>                 <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">输入的用户名不存</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">202</span>                 <span style="color: #0000ff">return</span>
<span style="color: #008080">203</span> 
<span style="color: #008080">204</span> 
<span style="color: #008080">205</span> 
<span style="color: #008080">206</span>     <span style="color: #008000">#</span><span style="color: #008000">stu.up_work()</span>
View Code
|      |- - -teach_class.py#讲师逻辑 类
<span style="color: #008080">  1</span> <span style="color: #008000">#</span><span style="color: #008000">!usr/bin/env python</span>
<span style="color: #008080">  2</span> <span style="color: #008000">#</span><span style="color: #008000">-*-coding:utf-8-*-</span>
<span style="color: #008080">  3</span> <span style="color: #008000">#</span><span style="color: #008000"> Author calmyan </span>
<span style="color: #008080">  4</span> <span style="color: #008000">#</span><span style="color: #008000">python </span>
<span style="color: #008080">  5</span> <span style="color: #008000">#</span><span style="color: #008000">2017/7/7    17:48</span>
<span style="color: #008080">  6</span> <span style="color: #008000">#</span><span style="color: #008000">__author__='Administrator'</span>
<span style="color: #008080">  7</span> 
<span style="color: #008080">  8</span> <span style="color: #0000ff">import</span><span style="color: #000000"> os ,sys
</span><span style="color: #008080">  9</span> BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(<span style="color: #800080">__file__</span>)))<span style="color: #008000">#</span><span style="color: #008000">获取相对路径转为绝对路径赋于变量</span>
<span style="color: #008080"> 10</span> sys.path.append(BASE_DIR)<span style="color: #008000">#</span><span style="color: #008000">增加环境变量</span>
<span style="color: #008080"> 11</span> <span style="color: #0000ff">from</span> sqlalchemy.ext.declarative <span style="color: #0000ff">import</span><span style="color: #000000"> declarative_base
</span><span style="color: #008080"> 12</span> <span style="color: #0000ff">from</span> sqlalchemy <span style="color: #0000ff">import</span><span style="color: #000000"> Column, Integer, String, ForeignKey, UniqueConstraint, Index
</span><span style="color: #008080"> 13</span> <span style="color: #0000ff">from</span> sqlalchemy.orm <span style="color: #0000ff">import</span><span style="color: #000000"> sessionmaker, relationship
</span><span style="color: #008080"> 14</span> <span style="color: #0000ff">from</span> sqlalchemy <span style="color: #0000ff">import</span><span style="color: #000000"> create_engine
</span><span style="color: #008080"> 15</span> <span style="color: #0000ff">from</span> sqlalchemy <span style="color: #0000ff">import</span> func <span style="color: #008000">#</span><span style="color: #008000">统计</span>
<span style="color: #008080"> 16</span> <span style="color: #0000ff">from</span>  core <span style="color: #0000ff">import</span><span style="color: #000000"> admin_class
</span><span style="color: #008080"> 17</span> <span style="color: #0000ff">from</span>  cfg <span style="color: #0000ff">import</span><span style="color: #000000"> config
</span><span style="color: #008080"> 18</span> 
<span style="color: #008080"> 19</span> <span style="color: #008000">#</span><span style="color: #008000">讲师类</span>
<span style="color: #008080"> 20</span> <span style="color: #0000ff">class</span><span style="color: #000000"> Teach_Mag(object):
</span><span style="color: #008080"> 21</span> 
<span style="color: #008080"> 22</span>     <span style="color: #0000ff">def</span> <span style="color: #800080">__init__</span><span style="color: #000000">(self):
</span><span style="color: #008080"> 23</span>         self.Session_class=sessionmaker(bind=admin_class.engine)<span style="color: #008000">#</span><span style="color: #008000">创建与数据库的会话 类</span>
<span style="color: #008080"> 24</span>         self.Session=self.Session_class()<span style="color: #008000">#</span><span style="color: #008000">生成实例</span>
<span style="color: #008080"> 25</span>         self.teach_name=<span style="color: #800000">''</span>
<span style="color: #008080"> 26</span> 
<span style="color: #008080"> 27</span>     <span style="color: #008000">#</span><span style="color: #008000">开始相关操作</span>
<span style="color: #008080"> 28</span>     <span style="color: #0000ff">def</span> openatin(self):<span style="color: #008000">#</span><span style="color: #008000">开始相关操作</span>
<span style="color: #008080"> 29</span>         <span style="color: #0000ff">while</span><span style="color: #000000"> True:
</span><span style="color: #008080"> 30</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">\033[35;1m讲师界面\033[0m</span><span style="color: #800000">'</span>.center(60,<span style="color: #800000">'</span><span style="color: #800000">=</span><span style="color: #800000">'</span><span style="color: #000000">))
</span><span style="color: #008080"> 31</span>             <span style="color: #0000ff">for</span> index,i <span style="color: #0000ff">in</span><span style="color: #000000"> enumerate(config.TEACH_OPEN):
</span><span style="color: #008080"> 32</span>                 <span style="color: #0000ff">print</span>(index,<span style="color: #800000">'</span><span style="color: #800000">:</span><span style="color: #800000">'</span><span style="color: #000000">,i[0])
</span><span style="color: #008080"> 33</span>             id=input(<span style="color: #800000">'</span><span style="color: #800000">请选择>>:</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080"> 34</span>             <span style="color: #0000ff">if</span><span style="color: #000000"> id.isdigit():
</span><span style="color: #008080"> 35</span>                 <span style="color: #0000ff">if</span> int(id)>=len(config.TEACH_OPEN):<span style="color: #0000ff">continue</span>
<span style="color: #008080"> 36</span>                 s=config.TEACH_OPEN[int(id)][1<span style="color: #000000">]
</span><span style="color: #008080"> 37</span>             <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080"> 38</span>                 <span style="color: #0000ff">continue</span>
<span style="color: #008080"> 39</span>             <span style="color: #0000ff">if</span> hasattr(self,s):<span style="color: #008000">#</span><span style="color: #008000">是反射否存在</span>
<span style="color: #008080"> 40</span>                 func=getattr(self,s)<span style="color: #008000">#</span><span style="color: #008000">调用</span>
<span style="color: #008080"> 41</span>                 func()<span style="color: #008000">#</span><span style="color: #008000">执行</span>
<span style="color: #008080"> 42</span> 
<span style="color: #008080"> 43</span>     <span style="color: #008000">#</span><span style="color: #008000">查看班级</span>
<span style="color: #008080"> 44</span>     <span style="color: #0000ff">def</span> show_class(self):<span style="color: #008000">#</span><span style="color: #008000">查看班级</span>
<span style="color: #008080"> 45</span>         <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">\033[32;1m查看班级(可管理)\033[0m</span><span style="color: #800000">'</span>.center(60,<span style="color: #800000">'</span><span style="color: #800000">=</span><span style="color: #800000">'</span><span style="color: #000000">))
</span><span style="color: #008080"> 46</span>         <span style="color: #008000">#</span><span style="color: #008000">show_class=self.Session.query(admin_class.Class_name).filter(admin_class.Class_name.teach_name==self.teach_name)</span>
<span style="color: #008080"> 47</span>         <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">\033[31;1m全部班级\033[0m</span><span style="color: #800000">'</span>.center(45,<span style="color: #800000">'</span><span style="color: #800000">-</span><span style="color: #800000">'</span>))<span style="color: #008000">#</span><span style="color: #008000">所有班级</span>
<span style="color: #008080"> 48</span>         <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span><span style="color: #000000"> self.class_list:
</span><span style="color: #008080"> 49</span>             <span style="color: #0000ff">print</span><span style="color: #000000">(i)
</span><span style="color: #008080"> 50</span>         <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">\033[35;1m可管理班级\033[0m</span><span style="color: #800000">'</span>.center(45,<span style="color: #800000">'</span><span style="color: #800000">-</span><span style="color: #800000">'</span><span style="color: #000000">))
</span><span style="color: #008080"> 51</span>         cla_id=self.class_l()<span style="color: #008000">#</span><span style="color: #008000">调用查看班级</span>
<span style="color: #008080"> 52</span>         class_obj=self.Session.query(admin_class.Class_name).filter(admin_class.Class_name.id==<span style="color: #000000">cla_id).first()
</span><span style="color: #008080"> 53</span>         <span style="color: #0000ff">if</span> class_obj:<span style="color: #008000">#</span><span style="color: #008000">获取班级对象成功 有内容</span>
<span style="color: #008080"> 54</span>             <span style="color: #0000ff">print</span><span style="color: #000000">(class_obj,class_obj.name,class_obj.id)
</span><span style="color: #008080"> 55</span>             self.student_l(class_obj.name)<span style="color: #008000">#</span><span style="color: #008000">调用查看学员 得到班级对象</span>
<span style="color: #008080"> 56</span>             <span style="color: #008000">#</span><span style="color: #008000"> print('[%s] 班 学员列表'.center(60,'=')%c)</span>
<span style="color: #008080"> 57</span>             <span style="color: #008000">#</span><span style="color: #008000"> for i in c.students:</span>
<span style="color: #008080"> 58</span>             <span style="color: #008000">#</span><span style="color: #008000">     print(i.id,'姓名:',i.name,'QQ:',i.qq)</span>
<span style="color: #008080"> 59</span>             <span style="color: #008000">#</span><span style="color: #008000"> print('end'.center(60,'='))</span>
<span style="color: #008080"> 60</span>             <span style="color: #0000ff">return</span>
<span style="color: #008080"> 61</span>         <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080"> 62</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">选择有误!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080"> 63</span>             <span style="color: #0000ff">return</span>
<span style="color: #008080"> 64</span> 
<span style="color: #008080"> 65</span>     <span style="color: #008000">#</span><span style="color: #008000">查看班级选择</span>
<span style="color: #008080"> 66</span>     <span style="color: #0000ff">def</span> class_l(self):<span style="color: #008000">#</span><span style="color: #008000">查看班级</span>
<span style="color: #008080"> 67</span>         <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span><span style="color: #000000"> self.teach_obj.class_n:
</span><span style="color: #008080"> 68</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">编号</span><span style="color: #800000">'</span>,i.id,<span style="color: #800000">'</span><span style="color: #800000">班级:</span><span style="color: #800000">'</span><span style="color: #000000">,i.name)
</span><span style="color: #008080"> 69</span>         class_id=input(<span style="color: #800000">'</span><span style="color: #800000">请按编号选择班级>>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080"> 70</span>         <span style="color: #0000ff">if</span>  class_id.isdigit() :<span style="color: #008000">#</span><span style="color: #008000">判断是否是整数</span>
<span style="color: #008080"> 71</span>             <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span> self.teach_obj.class_n:<span style="color: #008000">#</span><span style="color: #008000">是否在讲师的班级中</span>
<span style="color: #008080"> 72</span>                 <span style="color: #0000ff">if</span> int(class_id)==<span style="color: #000000">i.id:
</span><span style="color: #008080"> 73</span>                     <span style="color: #0000ff">return</span> int(class_id)<span style="color: #008000">#</span><span style="color: #008000">返回班级ID</span>
<span style="color: #008080"> 74</span>             <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080"> 75</span>                 <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">选择班级有误!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080"> 76</span>                 <span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080"> 77</span>         <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080"> 78</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">选择班级有误!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080"> 79</span>             <span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080"> 80</span> 
<span style="color: #008080"> 81</span>     <span style="color: #008000">#</span><span style="color: #008000">查看班级学员</span>
<span style="color: #008080"> 82</span>     <span style="color: #0000ff">def</span> student_l(self,class_name):<span style="color: #008000">#</span><span style="color: #008000">查看班级学员</span>
<span style="color: #008080"> 83</span>         stu_l=self.Session.query(admin_class.Class_name).filter(admin_class.Class_name.name==str(class_name)).first()<span style="color: #008000">#</span><span style="color: #008000">所选班级对象</span>
<span style="color: #008080"> 84</span>         <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">[%s] 班 学员列表</span><span style="color: #800000">'</span>.center(60,<span style="color: #800000">'</span><span style="color: #800000">=</span><span style="color: #800000">'</span>)%<span style="color: #000000">stu_l)
</span><span style="color: #008080"> 85</span>         <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span><span style="color: #000000"> stu_l.students:
</span><span style="color: #008080"> 86</span>             <span style="color: #0000ff">print</span>(i.id,<span style="color: #800000">'</span><span style="color: #800000">姓名:</span><span style="color: #800000">'</span>,i.name,<span style="color: #800000">'</span><span style="color: #800000">QQ:</span><span style="color: #800000">'</span><span style="color: #000000">,i.qq)
</span><span style="color: #008080"> 87</span>         <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">end</span><span style="color: #800000">'</span>.center(60,<span style="color: #800000">'</span><span style="color: #800000">=</span><span style="color: #800000">'</span><span style="color: #000000">))
</span><span style="color: #008080"> 88</span>         <span style="color: #0000ff">return</span> stu_l<span style="color: #008000">#</span><span style="color: #008000">返回所选班级对象</span>
<span style="color: #008080"> 89</span> 
<span style="color: #008080"> 90</span>     <span style="color: #008000">#</span><span style="color: #008000">查看课节</span>
<span style="color: #008080"> 91</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> less_cher(self):
</span><span style="color: #008080"> 92</span>         les=self.Session.query(admin_class.Lesson).all()<span style="color: #008000">#</span><span style="color: #008000">取课节名列表</span>
<span style="color: #008080"> 93</span>         <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span><span style="color: #000000"> les:
</span><span style="color: #008080"> 94</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">编号</span><span style="color: #800000">'</span>,i.id,<span style="color: #800000">'</span><span style="color: #800000">课节名>>:</span><span style="color: #800000">'</span><span style="color: #000000">,i)
</span><span style="color: #008080"> 95</span>         <span style="color: #0000ff">return</span><span style="color: #000000"> les
</span><span style="color: #008080"> 96</span>     <span style="color: #008000">#</span><span style="color: #008000">查看课节 选择</span>
<span style="color: #008080"> 97</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> lesson_l(self):
</span><span style="color: #008080"> 98</span>         les=self.less_cher()<span style="color: #008000">#</span><span style="color: #008000">取课节名列表</span>
<span style="color: #008080"> 99</span>         <span style="color: #008000">#</span><span style="color: #008000"> for i in les:</span>
<span style="color: #008080">100</span>         <span style="color: #008000">#</span><span style="color: #008000">     print('编号',i.id,'课节名>>:',i)</span>
<span style="color: #008080">101</span>         les_id=input(<span style="color: #800000">'</span><span style="color: #800000">请按编号选择课节 >>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080">102</span>         <span style="color: #0000ff">if</span><span style="color: #000000"> les_id.isdigit():
</span><span style="color: #008080">103</span>             <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span><span style="color: #000000"> les:
</span><span style="color: #008080">104</span>                 <span style="color: #0000ff">if</span> int(les_id)==<span style="color: #000000">i.id:
</span><span style="color: #008080">105</span>                     <span style="color: #0000ff">return</span> int(les_id)<span style="color: #008000">#</span><span style="color: #008000">返回课节ID</span>
<span style="color: #008080">106</span>             <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">107</span>                 <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">选择课节有误!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">108</span>                 <span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080">109</span>         <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">110</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">选择课节有误!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">111</span>             <span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080">112</span> 
<span style="color: #008080">113</span>     <span style="color: #008000">#</span><span style="color: #008000">创建班级</span>
<span style="color: #008080">114</span>     <span style="color: #0000ff">def</span> add_class(self):<span style="color: #008000">#</span><span style="color: #008000">创建班级</span>
<span style="color: #008080">115</span>         <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">\033[35;1m创建班级界面\033[0m</span><span style="color: #800000">'</span>.center(60,<span style="color: #800000">'</span><span style="color: #800000">=</span><span style="color: #800000">'</span><span style="color: #000000">))
</span><span style="color: #008080">116</span>         attr=input(<span style="color: #800000">"</span><span style="color: #800000">输入班级名>>:</span><span style="color: #800000">"</span><span style="color: #000000">).strip()
</span><span style="color: #008080">117</span>         <span style="color: #0000ff">if</span> attr <span style="color: #0000ff">in</span> self.class_list:<span style="color: #008000">#</span><span style="color: #008000">如果存在</span>
<span style="color: #008080">118</span>             <span style="color: #0000ff">return</span> <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">班级名重复!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">119</span>         c=admin_class.Class_name(name=attr)<span style="color: #008000">#</span><span style="color: #008000">创建新班级</span>
<span style="color: #008080">120</span>         self.teach_obj.class_n.append(c)<span style="color: #008000">#</span><span style="color: #008000">关联讲师与班级</span>
<span style="color: #008080">121</span>         <span style="color: #0000ff">if</span> self.add_all(c):<span style="color: #008000">#</span><span style="color: #008000">进行调用添加</span>
<span style="color: #008080">122</span> <span style="color: #000000">            self.Session.add_all([c])
</span><span style="color: #008080">123</span> <span style="color: #000000">            self.Session.commit()
</span><span style="color: #008080">124</span>         <span style="color: #0000ff">return</span>
<span style="color: #008080">125</span> 
<span style="color: #008080">126</span>     <span style="color: #008000">#</span><span style="color: #008000">班级增加学员</span>
<span style="color: #008080">127</span>     <span style="color: #0000ff">def</span> add_student(self):<span style="color: #008000">#</span><span style="color: #008000">班级增加学员</span>
<span style="color: #008080">128</span>         <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">\033[35;1m增加学员界面\033[0m</span><span style="color: #800000">'</span>.center(60,<span style="color: #800000">'</span><span style="color: #800000">=</span><span style="color: #800000">'</span><span style="color: #000000">))
</span><span style="color: #008080">129</span>         cla_id=self.class_l()<span style="color: #008000">#</span><span style="color: #008000">调用查看班级</span>
<span style="color: #008080">130</span>         <span style="color: #0000ff">if</span> <span style="color: #0000ff">not</span> cla_id:<span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080">131</span>         <span style="color: #008000">#</span><span style="color: #008000">获取班级对象</span>
<span style="color: #008080">132</span>         c=self.Session.query(admin_class.Class_name).filter(admin_class.Class_name.id==<span style="color: #000000">cla_id).first()
</span><span style="color: #008080">133</span>         <span style="color: #0000ff">if</span> <span style="color: #0000ff">not</span> c:<span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080">134</span>         stu_l=self.student_l(c.name)<span style="color: #008000">#</span><span style="color: #008000">查看班级学员</span>
<span style="color: #008080">135</span>         student_qq=input(<span style="color: #800000">'</span><span style="color: #800000">请输入学生QQ号码>>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080">136</span>         s_qq=self.Session.query(admin_class.Student).filter(admin_class.Student.qq==int(student_qq)).first()<span style="color: #008000">#</span><span style="color: #008000">学员qq对象</span>
<span style="color: #008080">137</span>         <span style="color: #0000ff">if</span> s_qq:<span style="color: #008000">#</span><span style="color: #008000">如果有这个qq</span>
<span style="color: #008080">138</span>             c.students.append(s_qq)<span style="color: #008000">#</span><span style="color: #008000">加入班级</span>
<span style="color: #008080">139</span> <span style="color: #000000">            self.Session.commit()
</span><span style="color: #008080">140</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">加入班级成功!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">141</span>         <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">142</span>             <span style="color: #0000ff">return</span> <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">QQ对应的学员不存在</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">143</span> 
<span style="color: #008080">144</span>     <span style="color: #008000">#</span><span style="color: #008000">添加课节</span>
<span style="color: #008080">145</span>     <span style="color: #0000ff">def</span> add_lesson(self):<span style="color: #008000">#</span><span style="color: #008000">添加课节</span>
<span style="color: #008080">146</span>         <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">现有课节</span><span style="color: #800000">'</span>.center(40,<span style="color: #800000">'</span><span style="color: #800000">=</span><span style="color: #800000">'</span><span style="color: #000000">))
</span><span style="color: #008080">147</span>         les=self.less_cher()<span style="color: #008000">#</span><span style="color: #008000">取课节名列表</span>
<span style="color: #008080">148</span>         day_name=input(<span style="color: #800000">'</span><span style="color: #800000">输入课节名>>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080">149</span>         d1=admin_class.Lesson(name=<span style="color: #000000">day_name)
</span><span style="color: #008080">150</span> <span style="color: #000000">        self.add_all(d1)
</span><span style="color: #008080">151</span> 
<span style="color: #008080">152</span>     <span style="color: #008000">#</span><span style="color: #008000">获取课程ID</span>
<span style="color: #008080">153</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> class_less(self,cla_id,les_id):
</span><span style="color: #008080">154</span> 
<span style="color: #008080">155</span>         cl_dayid=self.Session.query(admin_class.Class_Day).filter(admin_class.Class_Day.class_id==<span style="color: #000000">cla_id).\
</span><span style="color: #008080">156</span>             filter(admin_class.Class_Day.lesson_id==les_id).first()<span style="color: #008000">#</span><span style="color: #008000">获取班级课程表id</span>
<span style="color: #008080">157</span>         <span style="color: #0000ff">if</span><span style="color: #000000"> cl_dayid:
</span><span style="color: #008080">158</span>             <span style="color: #0000ff">return</span><span style="color: #000000"> cl_dayid
</span><span style="color: #008080">159</span>         <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">160</span>             <span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080">161</span> 
<span style="color: #008080">162</span>     <span style="color: #008000">#</span><span style="color: #008000">获取班级对象</span>
<span style="color: #008080">163</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> class_obj(self,cla_id):
</span><span style="color: #008080">164</span>         clas_obj=self.Session.query(admin_class.Class_name).filter(admin_class.Class_name.id==cla_id).first()<span style="color: #008000">#</span><span style="color: #008000">获取班级对象</span>
<span style="color: #008080">165</span>         <span style="color: #0000ff">return</span><span style="color: #000000"> clas_obj
</span><span style="color: #008080">166</span> 
<span style="color: #008080">167</span>     <span style="color: #008000">#</span><span style="color: #008000">开始上课</span>
<span style="color: #008080">168</span>     <span style="color: #0000ff">def</span> add_cla_day(self):<span style="color: #008000">#</span><span style="color: #008000">开始上课</span>
<span style="color: #008080">169</span>         <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">\033[32;1m班级上课\033[0m</span><span style="color: #800000">'</span>.center(60,<span style="color: #800000">'</span><span style="color: #800000">=</span><span style="color: #800000">'</span><span style="color: #000000">))
</span><span style="color: #008080">170</span>         cla_id=self.class_l()<span style="color: #008000">#</span><span style="color: #008000">#获取班级id</span>
<span style="color: #008080">171</span>         <span style="color: #0000ff">if</span> <span style="color: #0000ff">not</span> cla_id:<span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080">172</span>         les_id=self.lesson_l()<span style="color: #008000">#</span><span style="color: #008000">获取课节id</span>
<span style="color: #008080">173</span>         <span style="color: #0000ff">if</span> <span style="color: #0000ff">not</span> les_id:<span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080">174</span>         clas_obj=self.class_obj(cla_id)<span style="color: #008000">#</span><span style="color: #008000">获取班级对象</span>
<span style="color: #008080">175</span>         <span style="color: #0000ff">print</span>(clas_obj,clas_obj.id)<span style="color: #008000">#</span><span style="color: #008000">班级名,ID</span>
<span style="color: #008080">176</span>         cl_dayid=self.class_less(cla_id,les_id)<span style="color: #008000">#</span><span style="color: #008000">获取课程表对象</span>
<span style="color: #008080">177</span>         <span style="color: #0000ff">if</span> cl_dayid:<span style="color: #008000">#</span><span style="color: #008000">如果课程表存在</span>
<span style="color: #008080">178</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">当前班级该节课已经上过!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">179</span>             <span style="color: #0000ff">return</span>
<span style="color: #008080">180</span>         clas_day=admin_class.Class_Day(class_id=cla_id,lesson_id=les_id)<span style="color: #008000">#</span><span style="color: #008000">创建上课课程记录</span>
<span style="color: #008080">181</span>         self.Session.add(clas_day)<span style="color: #008000">#</span><span style="color: #008000">添加记录</span>
<span style="color: #008080">182</span>         cl_day_id=self.class_less(cla_id,les_id)<span style="color: #008000">#</span><span style="color: #008000">获取当前班级课程对象</span>
<span style="color: #008080">183</span>         c_obj=self.student_l(cl_day_id.class_n)<span style="color: #008000">#</span><span style="color: #008000">获取班级   学员对象</span>
<span style="color: #008080">184</span>         <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span><span style="color: #000000"> c_obj.students:
</span><span style="color: #008080">185</span>             stu_work=admin_class.Student_work(students_id=i.id,class_id=cl_day_id.id,status=<span style="color: #800000">'</span><span style="color: #800000">not</span><span style="color: #800000">'</span>)<span style="color: #008000">#</span><span style="color: #008000">创建上课记录</span>
<span style="color: #008080">186</span>             self.Session.add(stu_work)<span style="color: #008000">#</span><span style="color: #008000">添加记录</span>
<span style="color: #008080">187</span> <span style="color: #000000">        self.Session.commit()
</span><span style="color: #008080">188</span>         <span style="color: #0000ff">return</span> <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">上课记录添加完成</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">189</span> 
<span style="color: #008080">190</span>     <span style="color: #008000">#</span><span style="color: #008000">批改作业</span>
<span style="color: #008080">191</span>     <span style="color: #0000ff">def</span> set_results(self):<span style="color: #008000">#</span><span style="color: #008000">批改作业</span>
<span style="color: #008080">192</span>         <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">\033[32;1m批改作业\033[0m</span><span style="color: #800000">'</span>.center(60,<span style="color: #800000">'</span><span style="color: #800000">=</span><span style="color: #800000">'</span><span style="color: #000000">))
</span><span style="color: #008080">193</span>         cla_id=self.class_l()<span style="color: #008000">#</span><span style="color: #008000">#获取班级id</span>
<span style="color: #008080">194</span>         <span style="color: #0000ff">if</span> <span style="color: #0000ff">not</span> cla_id:<span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080">195</span>         les_id=self.lesson_l()<span style="color: #008000">#</span><span style="color: #008000">获取课节id</span>
<span style="color: #008080">196</span>         <span style="color: #0000ff">if</span> <span style="color: #0000ff">not</span> les_id:<span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080">197</span>         cl_day_id=self.class_less(cla_id,les_id)<span style="color: #008000">#</span><span style="color: #008000">获取课程表对象</span>
<span style="color: #008080">198</span>         <span style="color: #0000ff">if</span> <span style="color: #0000ff">not</span> cl_day_id:<span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">本节课未上!</span><span style="color: #800000">'</span>);<span style="color: #0000ff">return</span><span style="color: #000000"> None
</span><span style="color: #008080">199</span>         <span style="color: #008000">#</span><span style="color: #008000">获取当前班级中,</span>
<span style="color: #008080">200</span>         stude_day=self.Session.query(admin_class.Student_work).filter(admin_class.Student_work.class_id==<span style="color: #000000">cl_day_id.id).all()
</span><span style="color: #008080">201</span>         <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">\033[36;1m开始批改作业\033[0m</span><span style="color: #800000">'</span>.center(60,<span style="color: #800000">'</span><span style="color: #800000">=</span><span style="color: #800000">'</span><span style="color: #000000">))
</span><span style="color: #008080">202</span>         <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">\033[31;1m作业未提交则不显示\033[0m</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">203</span>         <span style="color: #0000ff">for</span> i <span style="color: #0000ff">in</span><span style="color: #000000"> stude_day:
</span><span style="color: #008080">204</span>             <span style="color: #0000ff">if</span> i.status==<span style="color: #800000">'</span><span style="color: #800000">yes</span><span style="color: #800000">'</span> <span style="color: #0000ff">and</span> <span style="color: #0000ff">not</span><span style="color: #000000"> i.results:
</span><span style="color: #008080">205</span>                 <span style="color: #0000ff">print</span>(i.id,<span style="color: #800000">'</span><span style="color: #800000">姓名:</span><span style="color: #800000">'</span>,i.students_w.name,<span style="color: #800000">'</span><span style="color: #800000">成绩:</span><span style="color: #800000">'</span><span style="color: #000000">,i.results)
</span><span style="color: #008080">206</span>                 resu=input(<span style="color: #800000">'</span><span style="color: #800000">请输入成绩>>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080">207</span>                 <span style="color: #0000ff">if</span><span style="color: #000000"> resu.isdigit():
</span><span style="color: #008080">208</span>                     self.Session.query(admin_class.Student_work).filter(admin_class.Student_work.id==i.id).update({<span style="color: #800000">"</span><span style="color: #800000">results</span><span style="color: #800000">"</span><span style="color: #000000">:resu})
</span><span style="color: #008080">209</span>             <span style="color: #0000ff">elif</span> i.status==<span style="color: #800000">'</span><span style="color: #800000">yes</span><span style="color: #800000">'</span> <span style="color: #0000ff">and</span><span style="color: #000000"> i.results:
</span><span style="color: #008080">210</span>                 <span style="color: #0000ff">print</span>(i.id,<span style="color: #800000">'</span><span style="color: #800000">姓名:</span><span style="color: #800000">'</span>,i.students_w.name,<span style="color: #800000">'</span><span style="color: #800000">成绩:</span><span style="color: #800000">'</span><span style="color: #000000">,i.results)
</span><span style="color: #008080">211</span>                 resu=input(<span style="color: #800000">'</span><span style="color: #800000">是否修改成绩? N/n 跳过,输入新成绩</span><span style="color: #800000">'</span><span style="color: #000000">).upper().strip()
</span><span style="color: #008080">212</span>                 <span style="color: #0000ff">if</span> resu==<span style="color: #800000">'</span><span style="color: #800000">N</span><span style="color: #800000">'</span><span style="color: #000000">:
</span><span style="color: #008080">213</span>                     <span style="color: #0000ff">continue</span>
<span style="color: #008080">214</span>                 <span style="color: #0000ff">if</span><span style="color: #000000"> resu.isdigit():
</span><span style="color: #008080">215</span>                     self.Session.query(admin_class.Student_work).filter(admin_class.Student_work.id==i.id).update({<span style="color: #800000">"</span><span style="color: #800000">results</span><span style="color: #800000">"</span><span style="color: #000000">:resu})
</span><span style="color: #008080">216</span> 
<span style="color: #008080">217</span>         <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">218</span> <span style="color: #000000">            self.Session.commit()
</span><span style="color: #008080">219</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">"</span><span style="color: #800000">已提交的作业全部批改完毕!</span><span style="color: #800000">"</span><span style="color: #000000">)
</span><span style="color: #008080">220</span> 
<span style="color: #008080">221</span>     <span style="color: #008000">#</span><span style="color: #008000">增加函数</span>
<span style="color: #008080">222</span>     <span style="color: #0000ff">def</span> add_all(self,lists):<span style="color: #008000">#</span><span style="color: #008000">增加函数</span>
<span style="color: #008080">223</span> <span style="color: #000000">        self.Session.add_all([lists])
</span><span style="color: #008080">224</span>         confirm=input(<span style="color: #800000">'</span><span style="color: #800000">请进行确认: 按\033[31;1mN\033[0m回滚操作,其他键确认!</span><span style="color: #800000">'</span><span style="color: #000000"> ).upper().strip()
</span><span style="color: #008080">225</span>         <span style="color: #0000ff">if</span> confirm==<span style="color: #800000">"</span><span style="color: #800000">N</span><span style="color: #800000">"</span><span style="color: #000000">:
</span><span style="color: #008080">226</span>             self.Session.rollback()<span style="color: #008000">#
</span><span style="color: #008080">227</span>             <span style="color: #0000ff">return</span><span style="color: #000000"> False
</span><span style="color: #008080">228</span>         <span style="color: #0000ff">try</span><span style="color: #000000">:
</span><span style="color: #008080">229</span> <span style="color: #000000">            self.Session.commit()
</span><span style="color: #008080">230</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">操作成功</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">231</span>             <span style="color: #0000ff">return</span><span style="color: #000000"> lists
</span><span style="color: #008080">232</span>         <span style="color: #0000ff">except</span><span style="color: #000000"> Exception as e:
</span><span style="color: #008080">233</span>             self.Session.rollback()<span style="color: #008000">#
</span><span style="color: #008080">234</span>             <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">操作失败!,可能该信息已经存在!</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">235</span>             <span style="color: #0000ff">return</span>
<span style="color: #008080">236</span> 
<span style="color: #008080">237</span>     <span style="color: #008000">#</span><span style="color: #008000">退出</span>
<span style="color: #008080">238</span>     <span style="color: #0000ff">def</span><span style="color: #000000"> tech_exit(self):
</span><span style="color: #008080">239</span>         <span style="color: #0000ff">return</span><span style="color: #000000">  exit()
</span><span style="color: #008080">240</span>     <span style="color: #008000">#</span><span style="color: #008000">登陆</span>
<span style="color: #008080">241</span>     <span style="color: #0000ff">def</span> user_log(self):<span style="color: #008000">#</span><span style="color: #008000">登陆</span>
<span style="color: #008080">242</span>             user_n=input(<span style="color: #800000">'</span><span style="color: #800000">请输入用户名>>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080">243</span>             aut_obj=self.Session.query(admin_class.Teacher).filter(admin_class.Teacher.user==<span style="color: #000000">user_n).first()
</span><span style="color: #008080">244</span>             <span style="color: #0000ff">if</span><span style="color: #000000"> aut_obj:
</span><span style="color: #008080">245</span>                 <span style="color: #008000">#</span><span style="color: #008000">print(self.aut_obj_1.pwd)#用户对应密码</span>
<span style="color: #008080">246</span>                 pwds=input(<span style="color: #800000">'</span><span style="color: #800000">请输入密码>>:</span><span style="color: #800000">'</span><span style="color: #000000">).strip()
</span><span style="color: #008080">247</span>                 <span style="color: #0000ff">if</span> pwds ==<span style="color: #000000"> aut_obj.pwd:
</span><span style="color: #008080">248</span>                     self.teach_name=<span style="color: #000000">aut_obj.name
</span><span style="color: #008080">249</span>                     <span style="color: #008000">#</span><span style="color: #008000">print(self.teach_name)#当前讲师姓名</span>
<span style="color: #008080">250</span>                     self.teach_obj = self.Session.query(admin_class.Teacher).filter(admin_class.Teacher.name==self.teach_name).first()<span style="color: #008000">#</span><span style="color: #008000">取当前讲课对象实例</span>
<span style="color: #008080">251</span>                     self.class_list=self.Session.query(admin_class.Class_name).all()<span style="color: #008000">#</span><span style="color: #008000">获取班级名列表</span>
<span style="color: #008080">252</span>                     <span style="color: #008000">#</span><span style="color: #008000">self.les=self.Session.query(admin_class.Lesson).all()#取课节名列表</span>
<span style="color: #008080">253</span>                     <span style="color: #008000">#</span><span style="color: #008000">print(self.s_name_list[2])</span>
<span style="color: #008080">254</span> <span style="color: #000000">                    self.openatin()
</span><span style="color: #008080">255</span>                 <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">256</span>                     <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">密码有误</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">257</span>                     <span style="color: #0000ff">return</span>
<span style="color: #008080">258</span>             <span style="color: #0000ff">else</span><span style="color: #000000">:
</span><span style="color: #008080">259</span>                 <span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">输入的用户名不存</span><span style="color: #800000">'</span><span style="color: #000000">)
</span><span style="color: #008080">260</span>                 <span style="color: #0000ff">return</span>
<span style="color: #008080">261</span> 
<span style="color: #008080">262</span> <span style="color: #008000">#</span><span style="color: #008000">Session.query()</span>
<span style="color: #008080">263</span> <span style="color: #0000ff">while</span><span style="color: #000000"> True:
</span><span style="color: #008080">264</span>     teach=<span style="color: #000000">Teach_Mag()
</span><span style="color: #008080">265</span>     <span style="color: #008000">#</span><span style="color: #008000">teach.add_teach()</span>
<span style="color: #008080">266</span>     <span style="color: #008000">#</span><span style="color: #008000">teach.add_stu()</span>
<span style="color: #008080">267</span> 
<span style="color: #008080">268</span>     teach.user_log()
View Code

 

<br><br>

 

Atas ialah kandungan terperinci python第六十八天--第十二周作业. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel sebelumnya:推荐几本关于的Python好书Artikel seterusnya:编写登录接口实例详解