예제 #1
0
파일: main.py 프로젝트: MiaoXia0/DataBase
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)
예제 #2
0
파일: main.py 프로젝트: MiaoXia0/DataBase
def load_user(user_id):
    usr = SQL.select('select * from accounts where account=\'%s\'' % user_id)
    if len(usr) > 0:
        curr_user = User()
        curr_user.type = user.gettype(user_id)
        curr_user.id = user_id
        return curr_user
예제 #3
0
파일: main.py 프로젝트: MiaoXia0/DataBase
def delete():
    if user.gettype(current_user.id) == 'student':
        return render_template('return.html', message='学生不能清除成绩!')
    else:
        num = request.form['num']
        user.delstu(num)
        return render_template('return.html', message='删除成功')
예제 #4
0
파일: main.py 프로젝트: MiaoXia0/DataBase
def status():
    table = []

    if user.gettype(current_user.id) == 'student':
        table = SQL.select('''select * 
        from students 
        where account = '%s'
        ''' % current_user.id)
    elif user.gettype(current_user.id) == 'teacher':
        table = SQL.select('''select * 
                from teachers 
                where account = '%s'
                ''' % current_user.id)
    return render_template('status.html',
                           StatusTable=table,
                           typ=user.gettype(current_user.id))
예제 #5
0
파일: main.py 프로젝트: MiaoXia0/DataBase
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)
예제 #6
0
파일: main.py 프로젝트: MiaoXia0/DataBase
def courseng():
    if user.gettype(current_user.id) == 'student':
        return render_template('return.html', message='学生不能添加课程')
    Cnum = int(
        SQL.selectone('select top 1 num from courses order by num desc')['num']
        [4:]) + 1
    return render_template('coursenew.html', Cnum=Cnum)
예제 #7
0
파일: main.py 프로젝트: MiaoXia0/DataBase
def log():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        nxt = request.form['next']
        if user.verify(username, password):
            curr_user = User()
            curr_user.id = username
            curr_user.type = user.gettype(username)
            login_user(curr_user)
            if nxt != '':
                return render_template('loginsucceed.html',
                                       username=username,
                                       usertype=current_user.type,
                                       next=nxt)
            else:
                return render_template('loginsucceed.html',
                                       username=username,
                                       usertype=current_user.type,
                                       next='/')

        else:
            return render_template('login.html', fail='登陆失败')

    elif request.method == 'GET':
        try:
            nxt = request.args['next']
        except Exception:
            nxt = ''
        return render_template('login.html', next=nxt)
예제 #8
0
파일: main.py 프로젝트: MiaoXia0/DataBase
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='学生不存在!')
예제 #9
0
파일: main.py 프로젝트: MiaoXia0/DataBase
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)
예제 #10
0
파일: main.py 프로젝트: MiaoXia0/DataBase
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)
예제 #11
0
파일: main.py 프로젝트: MiaoXia0/DataBase
def index():
    if not current_user.is_anonymous:
        table = []

        if user.gettype(current_user.id) == 'student':
            table = SQL.select('''select * 
                from students 
                where account = '%s'
                ''' % current_user.id)
        elif user.gettype(current_user.id) == 'teacher':
            table = SQL.select('''select * 
                        from teachers 
                        where account = '%s'
                        ''' % current_user.id)
        return render_template('index.html',
                               login=1,
                               username=current_user.id,
                               type=user.gettype(current_user.id),
                               StatusTable=table,
                               typ=user.gettype(current_user.id))
    else:
        return render_template('index.html', login=0, username='', type='')
예제 #12
0
파일: main.py 프로젝트: MiaoXia0/DataBase
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)
예제 #13
0
파일: main.py 프로젝트: MiaoXia0/DataBase
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='修改成功')
예제 #14
0
파일: main.py 프로젝트: MiaoXia0/DataBase
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)
예제 #15
0
파일: main.py 프로젝트: MiaoXia0/DataBase
def deletenump():
    if user.gettype(current_user.id) == 'student':
        return render_template('return.html', message='学生不能清除成绩!')
    else:
        num = 'stu' + request.form['num']
        if user.isExistStu(num):
            usr = SQL.select('select account from students where Num=\'%s\'' %
                             num)[0]['account']
            scores = SQL.select('select * from score where Snum=\'%s\'' % num)

            return render_template('delete.html',
                                   num=num,
                                   username=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),
                                   scores=scores)
        else:
            return render_template('deletenum.html', fail='找不到用户')
예제 #16
0
파일: main.py 프로젝트: MiaoXia0/DataBase
def courseset():
    if user.gettype(current_user.id) == 'student':
        return render_template('return.html', message='学生不能开课')
    CTable = SQL.select('select * from courses')
    return render_template('courseset.html', CTable=CTable)
예제 #17
0
파일: main.py 프로젝트: MiaoXia0/DataBase
def statusSelectG():
    if user.gettype(current_user.id) == 'student':
        return render_template('return.html', message='学生无权查询他人信息')
    else:
        return render_template('statusSelect.html')
예제 #18
0
파일: main.py 프로젝트: MiaoXia0/DataBase
def deletenum():
    if user.gettype(current_user.id) == 'student':
        return render_template('return.html', message='学生不能清除成绩!')
    else:
        return render_template('deletenum.html')
예제 #19
0
파일: main.py 프로젝트: MiaoXia0/DataBase
def statusSelectP():
    if user.gettype(current_user.id) == 'student':
        return render_template('return.html', message='学生无权查询他人信息')
    else:
        if request.form['via'] == 'num':
            num = 'stu' + request.form['num']
            if user.isExistStu(num):
                StatusTable = SQL.select(
                    'select * from students where Num = \'%s\'' % num)
                STable = SQL.select('select * from score where Snum = \'%s\'' %
                                    num)
                Sum = 0.0
                for item in STable:
                    Sum += item['score']
                if len(STable) == 0:
                    avg = 0
                else:
                    avg = Sum / len(STable)
                ScoreTable = [STable]
                avgs = {num: avg}
                return render_template('statusscore.html',
                                       currtype='teacher',
                                       StatusTable=StatusTable,
                                       ScoreTable=ScoreTable,
                                       avgs=avgs)
            else:
                return render_template('statusSelect.html', fail='找不到学生')
        elif request.form['via'] == 'nam':
            try:
                nam = request.form['nam']
                StatusTable = SQL.select(
                    'select * from students where Name = \'%s\'' % nam)
                ScoreTable = []
                avgs = {}
                for i in StatusTable:
                    STable = SQL.select(
                        'select * from score where Snum = \'%s\'' % i['Num'])
                    ScoreTable.append(STable)
                    Sum = 0.0
                    for item in STable:
                        Sum += item['score']
                        if len(ScoreTable) == 0:
                            avg = 0
                        else:
                            avg = Sum / len(STable)
                        avgs[i['Num']] = avg
                return render_template('statusscore.html',
                                       currtype='teacher',
                                       StatusTable=StatusTable,
                                       ScoreTable=ScoreTable,
                                       avgs=avgs)
            except Exception:
                return render_template('statusSelect.html', fail='找不到学生')
        elif request.form['via'] == 'cla':
            try:
                gra = int(request.form['gra'])
                dep = request.form['dep']
                cla = int(request.form['cla'])
                StatusTable = SQL.select(
                    'select * from students where Grade = \'%d\' and Class = \'%d\' and Dept = \'%s\''
                    % (gra, cla, dep))
                ScoreTable = []
                avgs = {}
                for i in StatusTable:
                    STable = SQL.select(
                        'select * from score where Snum = \'%s\'' % i['Num'])
                    ScoreTable.append(STable)
                    Sum = 0.0
                    for item in STable:
                        Sum += item['score']
                        if len(ScoreTable) == 0:
                            avg = 0
                        else:
                            avg = Sum / len(STable)
                        avgs[i['Num']] = avg
                return render_template('statusscore.html',
                                       currtype='teacher',
                                       StatusTable=StatusTable,
                                       ScoreTable=ScoreTable,
                                       avgs=avgs)
            except Exception:
                return render_template('statusSelect.html', fail='找不到学生')
예제 #20
0
파일: main.py 프로젝트: MiaoXia0/DataBase
def alternum():
    if user.gettype(current_user.id) == 'student':
        return render_template('return.html', message='教师才能修改其他学生的信息')
    return render_template('alter.html')