예제 #1
0
파일: lab2.py 프로젝트: SovietSword/BUAA_DB
def ad_tec():
    if request.method == 'GET':
        return render_template('ad_tec.html', tinfo=database.query('Teacher'))
    op = request.form.get('op')
    if op == 'new':
        attrib = {x: request.form.get(x) for x in ['tno', 'tid', 'tname', 'tsex', 'tdept', 'ttel', 'tmail']}
        attrib['tpwd'] = DFT_PWD
        database.new_cell('Teacher', **attrib)
        flash('添加成功')
        return redirect(url_for('ad_tec'))
    elif op == 'delete':
        database.delete_cell('Teacher', tno=request.form.get('tno'))
        flash('删除成功')
        return redirect(url_for('ad_tec'))
    elif op == 'tno':
        tinfo = database.query('Teacher', tno=request.form.get('tno'))
        flash('检索成功')
        return render_template('ad_tec.html', tinfo=tinfo)
    elif op == 'tname':
        tinfo = database.query('Teacher', tname=request.form.get('tname'))
        flash('检索成功')
        return render_template('ad_tec.html', tinfo=tinfo)
    elif op == 'pwd':
        database.modify_cell('Teacher', tno=request.form.get('tno'), tpwd=request.form.get('pwd'))
        flash('修改成功')
        return redirect(url_for('ad_tec'))
    else:
        raise Exception('非法操作')
예제 #2
0
파일: lab2.py 프로젝트: SovietSword/BUAA_DB
def ad_jw():
    if request.method == 'GET':
        return render_template('ad_jw.html', tinfo=database.query('Teacher'))
    op = request.form.get('op')
    if op == 'new':
        attrib = {x: request.form.get(x) for x in ['jno', 'jid', 'jname', 'jtel', 'jmail']}
        attrib['jpwd'] = DFT_PWD
        database.new_cell('Jiaowu', **attrib)
        flash('添加成功')
        return redirect(url_for('ad_jw'))
    elif op == 'delete':
        database.delete_cell('Jiaowu', jno=request.form.get('jno'))
        flash('删除成功')
        return redirect(url_for('ad_jw'))
    elif op == 'jno':
        jinfo = database.query('Jiaowu', jno=request.form.get('jno'))
        flash('检索成功')
        return render_template('ad_jw.html', jinfo=jinfo)
    elif op == 'jname':
        jinfo = database.query('Jiaowu', jname=request.form.get('jname'))
        flash('检索成功')
        return render_template('ad_jw.html', jinfo=jinfo)
    elif op == 'pwd':
        database.modify_cell('Jiaowu', jno=request.form.get('jno'), jpwd=request.form.get('pwd'))
        flash('修改成功')
        return redirect(url_for('ad_jw'))
    else:
        raise Exception('非法操作')
예제 #3
0
파일: lab2.py 프로젝트: SovietSword/BUAA_DB
def ad_stu():
    if request.method == 'GET':
        return render_template('ad_stu.html', sinfo=database.query('Student'))
    op = request.form.get('op')
    if op == 'new':
        attrib = {x: request.form.get(x) for x in ['sno', 'sid', 'sname', 'ssex', 'sdept', 'stel']}
        attrib['spwd'] = DFT_PWD
        database.new_cell('Student', **attrib)
        flash('添加成功')
        return redirect(url_for('ad_stu'))
    elif op == 'delete':
        database.delete_cell('Student', sno=request.form.get('sno'))
        flash('删除成功')
        return redirect(url_for('ad_stu'))
    elif op == 'sno':
        sinfo = database.query('Student', sno=request.form.get('sno'))
        flash('检索成功')
        return render_template('ad_stu.html', sinfo=sinfo)
    elif op == 'sname':
        sinfo = database.query('Student', sname=request.form.get('sname'))
        flash('检索成功')
        return render_template('ad_stu.html', sinfo=sinfo)
    elif op == 'pwd':
        database.modify_cell('Student', sno=request.form.get('sno'), spwd=DFT_PWD)
        flash('修改成功')
        return redirect(url_for('ad_stu'))
    else:
        raise Exception('非法操作')
예제 #4
0
파일: lab2.py 프로젝트: SovietSword/BUAA_DB
def tec_course(tno):
    if request.method == 'GET':
        return render_template('tec_course.html', tno=tno, cinfo=database.tec_query_course(tno))
    try:
        op = request.form.get('op')
    except Exception:
        flash('非法课程操作')
        return redirect(url_for('tec_course', tno=tno))
    if op == 'new':
        try:
            attrib = {x: request.form.get(x) for x in ['cname', 'cdept', 'ccap', 'ccredit', 'cdate']}
            for x in ['ccap', 'ccredit']:
                attrib[x] = to_int(attrib[x])
            database.new_cell('Course', **attrib)
            flash('开课成功')
        except Exception as e:
            info = str(e) if len(str(e)) < 8 or DEBUG else '未知错误'
            flash('开课失败,' + info)
        return redirect(url_for('tec_course', tno=tno))
    elif op == 'delete':
        try:
            database.delete_cell('Course', cno=to_int(request.form.get('cno')))
            flash('消课成功')
        except Exception as e:
            info = str(e) if len(str(e)) < 8 or DEBUG else '未知错误'
            flash('消课失败,' + info)
        return redirect(url_for('tec_course', tno=tno))
    else:
        flash('非法课程操作')
        return redirect(url_for('tec_course', tno=tno))
예제 #5
0
파일: lab2.py 프로젝트: SovietSword/BUAA_DB
def ad_dept():
    if request.method == 'GET':
        return render_template('ad_dept.html', dinfo=database.query('Department'))
    op = request.form.get('op')
    if op == 'new':
        attrib = {x: request.form.get(x) for x in ['dno', 'dname', 'dhead']}
        database.new_cell('Department', **attrib)
        flash('添加成功')
        return redirect(url_for('ad_dept'))
    elif op == 'delete':
        database.delete_cell('Department', dno=request.form.get('dno'))
        flash('删除成功')
        return redirect(url_for('ad_dept'))
    else:
        raise Exception('非法操作')
예제 #6
0
파일: lab2.py 프로젝트: SovietSword/BUAA_DB
def ad_room():
    if request.method == 'GET':
        return render_template('ad_room.html', rinfo=database.query('Room'))
    op = request.form.get('op')
    if op == 'new':
        attrib = {x: request.form.get(x) for x in ['rname', 'rcap']}
        attrib['rcap'] = to_int(attrib['rcap'])
        database.new_cell('Room', **attrib)
        flash('添加成功')
        return redirect(url_for('ad_room'))
    elif op == 'delete':
        database.delete_cell('Room', rname=request.form.get('rname'))
        flash('删除成功')
        return redirect(url_for('ad_room'))
    else:
        raise Exception('非法操作')
예제 #7
0
def ad_everything():
    if request.method == 'GET':
        return render_template('ad_everything.html', info=[])
    op = request.form.get('op')
    table = request.form.get('table')
    assert table in [
        'Student', 'Teacher', 'Jiaowu', 'Course', 'Book', 'Room', 'Department',
        'CPS', 'CB', 'CR', 'SC', 'TC', 'CTA'
    ]
    attrib = request.form.get('attrib')
    attrib.replace(' ', '')
    attrib = attrib.split(',')
    dic = {}
    for x in attrib:
        if x:
            x = x.split('=')
            n, v = x[0], x[1]
            if n in ['ccap', 'ccredit', 'bstore', 'rcap', 'grade']:
                v = to_int(v)
            dic[n] = v
    try:
        if op == 'new':
            database.new_cell(table, **dic)
            flash('插入成功')
            return redirect(url_for('ad_everything'))
        elif op == 'delete':
            database.delete_cell(table, **dic)
            flash('删除成功')
            return redirect(url_for('ad_everything'))
        elif op == 'modify':
            database.modify_cell(table, **dic)
            flash('修改成功')
            return redirect(url_for('ad_everything'))
        elif op == 'query':
            info = database.query(table, **dic)
            flash('查询成功')
            return render_template('ad_everything.html', info=info)
        else:
            raise Exception('非法操作')
    except Exception as e:
        info = str(e) if len(str(e)) < 8 or DEBUG else '未知错误'
        flash('操作失败,' + info)
        return redirect(url_for('ad_everything'))
예제 #8
0
파일: lab2.py 프로젝트: SovietSword/BUAA_DB
def ad_book():
    if request.method == 'GET':
        return render_template('ad_book.html', binfo=database.query('Book'))
    op = request.form.get('op')
    if op == 'new':
        attrib = {x: request.form.get(x) for x in ['bno', 'bname']}
        attrib['bstore'] = 0
        database.new_cell('Book', **attrib)
        flash('添加成功')
        return redirect(url_for('ad_book'))
    elif op == 'delete':
        database.delete_cell('Book', bno=request.form.get('bno'))
        flash('删除成功')
        return redirect(url_for('ad_book'))
    elif op == 'update':
        database.modify_cell('Book', bno=request.form.get('bno'), bstore=to_int(request.form.get('bstore')))
        flash('修改库存成功')
        return redirect(url_for('ad_book'))
    else:
        raise Exception('非法操作')
예제 #9
0
파일: lab2.py 프로젝트: SovietSword/BUAA_DB
def tec_course_info(tno, cno):
    cno=to_int(cno)
    print(cno)
    print(database.query('CB', cno=cno))
    if request.method == 'GET':
        cinfo = None
        for x in database.tec_query_course(tno):
            if x['cno'] == cno:
                cinfo = x
        return render_template('tec_course_info.html', tno=tno, cno=cno, cinfo=cinfo, binfo=database.query('CB', cno=cno), tainfo=database.query_course_ta(cno))
    try:
        op = request.form.get('op')
    except Exception:
        flash('非法课程操作')
        return redirect(url_for('tec_course_info', tno=tno, cno=cno))
    if op == 'update':
        try:
            attrib = {x: request.form.get(x) for x in ['ccap', 'ccredit', 'cdate']}
            attrib['cno'] = cno
            for x in ['ccap', 'ccredit']:
                attrib[x] = to_int(attrib[x])
            database.modify_cell('Course', **attrib)
            flash('修改信息成功')
        except Exception as e:
            info = str(e) if len(str(e)) < 8 or DEBUG else '未知错误'
            flash('修改信息失败,' + info)
        return redirect(url_for('tec_course_info', tno=tno, cno=cno))
    elif op == 'newco':
        try:
            database.new_cell('TC', tno=request.form.get('tno'), cno=cno)
            flash('添加合作教师成功')
        except Exception as e:
            info = str(e) if len(str(e)) < 8 or DEBUG else '未知错误'
            flash('添加合作教师失败,' + info)
        return redirect(url_for('tec_course_info', tno=tno, cno=cno))
    elif op == 'newbook':
        try:
            database.new_course_book(cno, request.form.get('bno'), request.form.get('bname'))
            flash('添加参考书成功')
        except Exception as e:
            info = str(e) if len(str(e)) < 8 or DEBUG else '未知错误'
            flash('添加参考书失败,' + info)
        return redirect(url_for('tec_course_info', tno=tno, cno=cno))
    elif op == 'agree':
        try:
            database.modify_cell('CTA', cno=cno, sno=request.form.get('sno'), agree='Y')
            flash('添加助教成功')
        except Exception as e:
            info = str(e) if len(str(e)) < 8 or DEBUG else '未知错误'
            flash('添加助教失败,' + info)
        return redirect(url_for('tec_course_info', tno=tno, cno=cno))
    elif op == 'deny':
        try:
            database.delete_cell('CTA', cno=cno, sno=request.form.get('sno'))
            flash('拒绝助教成功')
        except Exception as e:
            info = str(e) if len(str(e)) < 8 or DEBUG else '未知错误'
            flash('拒绝助教失败,' + info)
        return redirect(url_for('tec_course_info', tno=tno, cno=cno))
    elif op == 'deletebook':
        try:
            database.delete_course_book(cno, request.form.get('bno'))
            flash('删除参考书成功')
        except Exception as e:
            info = str(e) if len(str(e)) < 8 or DEBUG else '未知错误'
            flash('删除参考书失败,' + info)
        return redirect(url_for('tec_course_info', tno=tno, cno=cno))
    else:
        flash('非法课程操作')
        return redirect(url_for('tec_course_info', tno=tno, cno=cno))
예제 #10
0
파일: lab2.py 프로젝트: SovietSword/BUAA_DB
def stu_course(sno):
    if request.method == 'GET':
        return render_template('stu_course.html', sno=sno, cinfo=database.stu_query_course(sno))
    try:
        op = request.form.get('op')
    except Exception:
        flash('非法课程操作')
        return redirect(url_for('stu_course', sno=sno))
    if op == 'picked':
        try:
            cinfo = [x for x in database.stu_query_course(sno) if x['pick']]
            flash('筛选成功')
            return render_template('stu_course.html', sno=sno, cinfo=cinfo)
        except Exception as e:
            info = str(e) if len(str(e)) < 8 or DEBUG else '未知错误'
            flash('筛选失败,' + info)
            return redirect(url_for('stu_course', sno=sno))
    elif op == 'unpicked':
        try:
            cinfo = [x for x in database.stu_query_course(sno) if not x['pick']]
            flash('筛选成功')
            return render_template('stu_course.html', sno=sno, cinfo=cinfo)
        except Exception as e:
            info = str(e) if len(str(e)) < 8 or DEBUG else '未知错误'
            flash('筛选失败,' + info)
            return redirect(url_for('stu_course', sno=sno))
    elif op == 'cno':
        try:
            cinfo = database.stu_query_course(sno, cno=to_int(request.form.get('cno')))
            flash('检索成功')
            return render_template('stu_course.html', sno=sno, cinfo=cinfo)
        except Exception as e:
            info = str(e) if len(str(e)) < 8 or DEBUG else '未知错误'
            flash('检索失败,' + info)
            return redirect(url_for('stu_course', sno=sno))
    elif op == 'cname':
        try:
            cinfo = database.stu_query_course(sno, cname=request.form.get('cname'))
            flash('检索成功')
            return render_template('stu_course.html', sno=sno, cinfo=cinfo)
        except Exception as e:
            info = str(e) if len(str(e)) < 8 or DEBUG else '未知错误'
            flash('检索失败,' + info)
            return redirect(url_for('stu_course', sno=sno))
    elif op == 'pick':
        try:
            database.stu_pick_course(sno=sno, cno=to_int(request.form.get('cno')))
            flash('选课成功')
        except Exception as e:
            info = str(e) if len(str(e)) < 8 or DEBUG else '未知错误'
            flash('选课失败,' + info)
        return redirect(url_for('stu_course', sno=sno))
    elif op == 'exit':
        try:
            database.delete_cell('SC', sno=sno, cno=to_int(request.form.get('cno')))
            flash('退课成功')
        except Exception as e:
            info = str(e) if len(str(e)) < 8 or DEBUG else '未知错误'
            flash('退课失败,' + info)
        return redirect(url_for('stu_course', sno=sno))
    elif op == 'apply':
        try:
            database.new_cell('CTA', sno=sno, cno=to_int(request.form.get('cno')), agree='N')
            flash('申请成功')
        except Exception as e:
            info = str(e) if len(str(e)) < 8 or DEBUG else '未知错误'
            flash('申请失败,' + info)
        return redirect(url_for('stu_course', sno=sno))
    elif op == 'cancel':
        try:
            database.delete_cell('CTA', sno=sno, cno=to_int(request.form.get('cno')))
            flash('取消申请成功')
        except Exception as e:
            info = str(e) if len(str(e)) < 8 or DEBUG else '未知错误'
            flash('取消申请失败,' + info)
        return redirect(url_for('stu_course', sno=sno))
    else:
        flash('非法课程操作')
        return redirect(url_for('stu_course', sno=sno))