>  기사  >  백엔드 개발  >  파이썬 68일차--12주차 숙제

파이썬 68일차--12주차 숙제

PHP中文网
PHP中文网원래의
2017-07-10 18:13:061548검색

테마:

요구 사항:

사용자 역할, 강사\학생. 로그인 후 사용자는 다음과 같이 다양한 역할에 따라 다양한 작업을 수행할 수 있습니다.
강사 보기
수업을 관리하고, 수업을 생성하고, 학생의 QQ 번호에 따라 수업에 학생을 추가할 수 있습니다. 특정 수업에 대한 수업 기록을 생성할 수 있습니다. 하나의 수업 기록은 여러 학생의 수업 기록에 해당합니다. 즉, 각 수업에는 전체 학생의 수업 기록이 기록됩니다. 각 수업 기록을 생성하는 동시에 수업의 각 학생에 대한 수업 기록을 생성하는 데 필요합니다. Linux와 Python에 동시에 등록하는 것처럼 학생은 동시에 여러 수업에 속할 수 있습니다. 따라서 숙제를 제출할 때 먼저 수업을 선택한 다음 특정 수업 수를 선택해야 합니다
추가: 학생들의 수업 성적 순위를 확인할 수 있습니다


으아악


먼저 테이블 구조 다이어그램으로 가보겠습니다

여기 아름다운 과정 사진이 있습니다:

으아악 으아악

으아악

코드 보기
으아악
으아악
코드 보기
으아악
으아악
코드 보기
으아악
으아악
코드 보기
으아악
으아악

코드 보기
으아악
으아악
코드 보기
|      |- - -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>

 

위 내용은 파이썬 68일차--12주차 숙제의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.