Exemple #1
0
def addp():
    if user.gettype(current_user.id) == 'student':
        return render_template('return.html', message='学生不能录入成绩!')
    else:
        myct = []
        Tnum = user.getnum(current_user.id)
        Snum = request.form['Snum']
        ct = SQL.select('''select *
            from courses
            where num in(
                select Cnum
                from cs
                where Snum in(
                    select Snum
                    from cs
                    where Cnum in(
                        select Cnum
                        from ct
                        where Tnum='%s'
                    )
                )
            )''' % Tnum)
        for t in ct:
            t['Lnum'] = SQL.select('select Lnum from ct where Cnum=\'%s\'' %
                                   t['num'])
            myct = SQL.select('''select * from ct where Tnum='%s'
                        ''' % Tnum)
            for i in myct:
                i['Cname'] = SQL.selectone(
                    'select name from courses where num=\'%s\'' %
                    i['Cnum'])['name']
        numt = SQL.select('''select Snum
            from cs
            where Cnum in(
                    select Cnum
                    from ct
                    where Tnum='%s'
                )''' % Tnum)
        if user.isExistStu(Snum):
            Cnum = request.form['Cnum']
            Lnum = int(request.form['Lnum'])
            Cname = SQL.selectone('select name from courses where num=\'%s\'' %
                                  Cnum)['name']
            Score = int(request.form['score'])
            grade = SQL.selectone('select grade from cs where Cnum=\'%s\'' %
                                  Cnum)['grade']
            user.scorein(Snum, Cname, Score, grade, Cnum, Lnum)
            return render_template('add.html',
                                   Tnum=Tnum,
                                   ct=ct,
                                   myct=myct,
                                   numt=numt,
                                   message='录入成功!')
        else:
            return render_template('add.html',
                                   Tnum=Tnum,
                                   ct=ct,
                                   myct=myct,
                                   numt=numt,
                                   message='学生不存在!')
Exemple #2
0
def leavemanagep():
    if user.gettype(current_user.id) == 'student':
        return render_template('return.html', message='学生不能管理请假')
    Snum = request.form['Snum']
    Tnum = user.getnum(current_user.id)

    try:
        act = request.form['act']
    except Exception:
        act = ''
    stats = request.form['status']
    if stats == '未批准':
        if act == '准假':
            SQL.cur.execute(
                'update leave set status=\'未销假\' where status=\'未批准\' and Tnum=\'%s\' and Snum=\'%s\''
                % (Tnum, Snum))
            SQL.conn.commit()
        elif act == '驳回':
            SQL.cur.execute(
                'update leave set status=\'已驳回\' where status=\'未批准\' and Tnum=\'%s\' and Snum=\'%s\''
                % (Tnum, Snum))
            SQL.conn.commit()
    elif stats == '未销假':
        SQL.cur.execute(
            'update leave set status=\'已销假\' where status=\'未销假\' and Tnum=\'%s\' and Snum=\'%s\''
            % (Tnum, Snum))
        SQL.conn.commit()
    LeaveTable = SQL.select('select * from leave where Tnum = \'%s\'' % Tnum)
    Sname = ''
    for table in LeaveTable:
        Sname = user.getname(user.getaccount(table['Snum']))
        table['Sname'] = Sname
    return render_template('leavemanage.html',
                           LeaveTable=LeaveTable,
                           Sname=Sname)
Exemple #3
0
def alter():
    usr = ''
    num = request.form['num']
    currtype = current_user.type
    if num[:3] == 'stu' and user.isExistStu(num):
        usr = SQL.select('select account from students where Num=\'%s\'' %
                         num)[0]['account']
    elif num[:3] == 'tch' and user.isExistTch(num):
        usr = SQL.select('select account from teachers where num=\'%s\'' %
                         num)[0]['account']
    if not user.isExist(usr):
        return render_template('alter.html', fail='找不到用户')
    if user.gettype(current_user.id) == 'student':
        return render_template('return.html', message='教师才能修改其他学生的信息')
    elif user.gettype(usr) == 'teacher' and current_user.id != usr:
        return render_template('return.html', message='教师不能修改其他教师的信息')
    else:
        return render_template('alterone.html',
                               username=usr,
                               type=user.gettype(usr),
                               num=user.getnum(usr),
                               name=user.getname(usr),
                               sex=user.getsex(usr),
                               grade=user.getgrade(usr),
                               classs=user.getclass(usr),
                               age=user.getage(usr),
                               dept=user.getdept(usr),
                               currtype=currtype)
Exemple #4
0
def courses():
    Snum = user.getnum(current_user.id)
    ct = SQL.select('select * from cs where Snum=\'%s\'' % Snum)
    for t in ct:
        Cname = SQL.selectone('select name from courses where num=\'%s\'' %
                              t['Cnum'])['name']
        t['Cname'] = Cname
    return render_template('courses.html', ct=ct)
Exemple #5
0
def mycourse():
    if user.gettype(current_user.id) == 'student':
        return render_template('return.html', message='学生不能开课')
    Tnum = user.getnum(current_user.id)
    ct = SQL.select('select * from ct where Tnum=\'%s\'' % Tnum)
    for i in ct:
        i['Cname'] = SQL.selectone(
            'select name from courses where num=\'%s\'' % i['Cnum'])['name']
    return render_template('mycourse.html', ct=ct)
Exemple #6
0
def leavemanage():
    if user.gettype(current_user.id) == 'student':
        return render_template('return.html', message='学生不能管理请假')
    Tnum = user.getnum(current_user.id)
    LeaveTable = SQL.select('select * from leave where Tnum = \'%s\'' % Tnum)
    if len(LeaveTable) > 0:
        for table in LeaveTable:
            Sname = user.getname(user.getaccount(table['Snum']))
            table['Sname'] = Sname
    return render_template('leavemanage.html', LeaveTable=LeaveTable)
Exemple #7
0
def currleave():
    Sname = user.getname(current_user.id)
    Snum = user.getnum(current_user.id)
    LeaveTable = SQL.select('select * from leave where Snum = \'%s\'' % Snum)
    for table in LeaveTable:
        Tname = user.getname(user.getaccount(table['Tnum']))
        table['Tname'] = Tname
    return render_template('currleave.html',
                           LeaveTable=LeaveTable,
                           Sname=Sname)
Exemple #8
0
def leave():
    tchs = SQL.select('select num from teachers')
    lst = SQL.select('select * from leave where Snum=\'%s\'' %
                     user.getnum(current_user.id))
    for item in lst:
        if item['status'] == '未批准':
            return render_template('return.html', message='当前有未批准请假!')
        if item['status'] == '未销假':
            return render_template('return.html', message='当前有未销假请假!')
    return render_template('leave.html', tchs=tchs)
Exemple #9
0
def addg():
    if user.gettype(current_user.id) == 'student':
        return render_template('return.html', message='学生不能录入成绩!')
    else:
        Tnum = user.getnum(current_user.id)
        numt = SQL.select('''select Snum
            from cs
            where Cnum in(
                    select Cnum
                    from ct
                    where Tnum='%s'
                )''' % Tnum)
        myct = SQL.select('''select * from ct where Tnum='%s'
            ''' % Tnum)
        for i in myct:
            i['Cname'] = SQL.selectone(
                'select name from courses where num=\'%s\'' %
                i['Cnum'])['name']
        ct = SQL.select('''select *
            from courses
            where num in(
                select Cnum
                from cs
                where Snum in(
                    select Snum
                    from cs
                    where Cnum in(
                        select Cnum
                        from ct
                        where Tnum='%s'
                    )
                )
            )''' % Tnum)
        for t in ct:
            t['Lnum'] = SQL.select('select Lnum from ct where Cnum=\'%s\'' %
                                   t['num'])
        return render_template('add.html',
                               Tnum=user.getnum(current_user.id),
                               myct=myct,
                               ct=ct,
                               numt=numt)
Exemple #10
0
def coursesetp():
    if current_user.type == 'teacher':
        Cnum = request.form['Cnum']
        Lnum = int(request.form['Lnum'])
        Tnum = user.getnum(current_user.id)
        SQL.cur.execute(
            'insert into ct (Cnum, Tnum, Lnum) values (\'%s\', \'%s\', \'%d\')'
            % (Cnum, Tnum, Lnum))
        SQL.conn.commit()
        CTable = SQL.select('select * from courses')
        return render_template('courseset.html', message='开课成功', CTable=CTable)
    else:
        return render_template('return.html', message='学生不能开课')
Exemple #11
0
def coursesdel():
    Snum = user.getnum(current_user.id)
    Cnum = request.form['Cnum']
    Lnum = int(request.form['Lnum'])
    SQL.cur.execute('''delete from cs
    where Snum='%s' and Lnum='%d' and Cnum='%s' 
    ''' % (Snum, Lnum, Cnum))
    SQL.conn.commit()
    ct = SQL.select('select * from cs where Snum=\'%s\'' % Snum)
    for t in ct:
        Cname = SQL.selectone('select name from courses where num=\'%s\'' %
                              t['Cnum'])['name']
        t['Cname'] = Cname
    return render_template('courses.html', ct=ct)
Exemple #12
0
def courseg():
    Snum = user.getnum(current_user.id)
    myct = SQL.select('select * from cs where Snum=\'%s\'' % Snum)
    for t in myct:
        Cname = SQL.selectone('select name from courses where num=\'%s\'' %
                              t['Cnum'])['name']
        t['Cname'] = Cname
    ct = SQL.select('select * from ct')
    for t in ct:
        t['Tname'] = user.getname(user.getaccount(t['Tnum']))
        t['Cname'] = SQL.selectone(
            'select name from courses where num=\'%s\'' % t['Cnum'])['name']

    return render_template('course.html', ct=ct, myct=myct)
Exemple #13
0
def mycoursedel():
    if user.gettype(current_user.id) == 'student':
        return render_template('return.html', message='学生不能删课')
    Cnum = request.form['Cnum']
    Lnum = int(request.form['Lnum'])
    SQL.cur.execute('''delete from ct
        where Cnum='%s' and Lnum='%d'
    ''' % (Cnum, Lnum))
    SQL.conn.commit()
    Tnum = user.getnum(current_user.id)
    ct = SQL.select('select * from ct where Tnum=\'%s\'' % Tnum)
    for i in ct:
        i['Cname'] = SQL.selectone(
            'select name from courses where num=\'%s\'' % i['Cnum'])['name']
    return render_template('mycourse.html', ct=ct)
Exemple #14
0
def alterself():
    if request.method == 'GET':
        return render_template('alterone.html',
                               currtype='student',
                               username=current_user.id,
                               type=user.gettype(current_user.id),
                               num=user.getnum(current_user.id),
                               name=user.getname(current_user.id),
                               sex=user.getsex(current_user.id),
                               grade=user.getgrade(current_user.id),
                               classs=user.getclass(current_user.id),
                               age=user.getage(current_user.id),
                               dept=user.getdept(current_user.id))
    elif request.method == 'POST':
        usr = request.form['username']
        pswnew = request.form['pswnew']
        name = request.form['name']
        sex = request.form['sex']
        age = int(request.form['age'])
        dept = request.form['dept']
        try:
            grade = int(request.form['grade'])
            classs = int(request.form['class'])
        except Exception:
            grade = 0
            classs = 0
        if usr != '':
            user.setStatus(pswnew=pswnew,
                           name=name,
                           sex=sex,
                           age=age,
                           dept=dept,
                           grade=grade,
                           classs=classs,
                           user=usr)
        else:
            user.setStatus(pswnew=pswnew,
                           name=name,
                           sex=sex,
                           age=age,
                           dept=dept,
                           grade=grade,
                           classs=classs,
                           user=current_user.id)
        return render_template('return.html', message='修改成功')
Exemple #15
0
def coursep():
    Snum = user.getnum(current_user.id)
    myct = SQL.select('select * from cs where Snum=\'%s\'' % Snum)
    Cnum = request.form['Cnum']
    Lnum = int(request.form['Lnum'])
    for t in myct:
        if Cnum == t['Cnum']:
            SQL.cur.execute(
                'delete from cs where Cnum=\'%s\' and Lnum=\'%d\'' %
                (Cnum, Lnum))
            SQL.conn.commit()
            ct = SQL.select('select * from ct')
            for tct in ct:
                tct['Tname'] = user.getname(user.getaccount(tct['Tnum']))
                tct['Cname'] = SQL.selectone(
                    'select name from courses where num=\'%s\'' %
                    tct['Cnum'])['name']
            myct = SQL.select('select * from cs where Snum=\'%s\'' % Snum)
            for myt in myct:
                Cname = SQL.selectone(
                    'select name from courses where num=\'%s\'' %
                    myt['Cnum'])['name']
                myt['Cname'] = Cname
            return render_template('course.html', ct=ct, myct=myct)
    grade = int(user.getgrade(current_user.id))
    SQL.cur.execute('''insert into cs (Cnum, Snum, grade, Lnum)
    values ('%s', '%s', '%d', '%d')
    ''' % (Cnum, Snum, grade, Lnum))
    SQL.conn.commit()
    ct = SQL.select('select * from ct')
    for tct in ct:
        tct['Tname'] = user.getname(user.getaccount(tct['Tnum']))
        tct['Cname'] = SQL.selectone(
            'select name from courses where num=\'%s\'' % tct['Cnum'])['name']
    myct = SQL.select('select * from cs where Snum=\'%s\'' % Snum)
    for myt in myct:
        Cname = SQL.selectone('select name from courses where num=\'%s\'' %
                              myt['Cnum'])['name']
        myt['Cname'] = Cname
    return render_template('course.html', ct=ct, myct=myct)
Exemple #16
0
def leavep():
    reason = request.form['reason']
    Tnum = request.form['Tnum']
    timestart = request.form['timestart']
    timestop = request.form['timestop']
    if user.isExistTch(Tnum):
        start = datetime.strptime(timestart, '%Y-%m-%dT%H:%M')
        stop = datetime.strptime(timestop, '%Y-%m-%dT%H:%M')
        if stop - start > timedelta(0):
            SQL.cur.execute(
                '''insert into leave (Snum, Tnum, reason, timestart, timestop, status)
                values ('%s', '%s', '%s', '%s', '%s', '未批准')
                ''' % (user.getnum(
                    current_user.id), Tnum, reason, timestart, timestop))
            SQL.conn.commit()
            return render_template('return.html', message='提交成功!')
        else:
            tchs = SQL.select('select num from teachers')
            return render_template('leave.html',
                                   tchs=tchs,
                                   message='停止时间不能比开始时间早')
    else:
        tchs = SQL.select('select num from teachers')
        return render_template('leave.html', tchs=tchs, message='无此教师')