Пример #1
0
def newmessage():
    if request.method == 'GET':
        return render_template('mailbox.html')
    else:
        receiver = request.form['receiver']
        content = request.form['content']
        if current_user.utype == 1:
            cursor.execute(
                'select sID '
                'from coursefilemanagement.student '
                'where account=%s', (current_user.get_id()))
            sid = cursor.fetchall()
            messageID = time.strftime("%m%d%H%M%S", time.localtime()) + str(
                random.randint(1, 99))
            cursor.execute(
                'insert into coursefilemanagement.message(sID, tID, messageID, content, direction) '
                'values (%s,%s,%s,%s,%s)',
                (sid[0][0], receiver, messageID, content, 0))
            conn.commit()
            return 'success!'
        elif current_user.utype == 2:
            cursor.execute(
                'select tID '
                'from coursefilemanagement.teacher '
                'where account=%s', (current_user.get_id()))
            tid = cursor.fetchall()
            messageID = time.strftime("%m%d%H%M%S", time.localtime()) + str(
                random.randint(1, 99))
            cursor.execute(
                'insert into coursefilemanagement.message(sID, tID, messageID, content, direction) '
                'values (%s,%s,%s,%s,%s)',
                (receiver, tid[0][0], messageID, content, 1))
            conn.commit()
            return 'success!'
Пример #2
0
def tmodify():
    if request.method == 'GET':
        return render_template('tmodify.html')
    else:
        try:
            teacherName = request.form['teacherName']
            tID = request.form['tID']
            cursor.execute(
                'DELETE FROM coursefilemanagement.teacher '
                'WHERE account =%s', (current_user.get_id()))
            cursor.execute(
                'insert into coursefilemanagement.teacher(teacherName, tID, account) values (%s,%s,%s)',
                (teacherName, tID, current_user.get_id()))
        except:
            print('no teacher modified')

        try:
            buildingName = request.form['buildingName']
            buildingID = request.form['buildingID']
            cursor.execute(
                'insert into coursefilemanagement.building(buildingName, buildingID) VALUES (%s,%s)',
                (buildingName, buildingID))
        except:
            print('no building modified')

        try:
            courseName = request.form['courseName']
            courseID = request.form['courseID']
            tID = request.form['tID']
            buildingID = request.form['buildingID']
            cursor.execute(
                'insert into coursefilemanagement.course VALUES (%s,%s,%s,%s)',
                (courseName, courseID, tID, buildingID))
        except:
            print('no course modified')

        try:
            majorName = request.form['majorName']
            majorID = request.form['majorID']
            cursor.execute(
                'insert into coursefilemanagement.major VALUES (%s,%s)',
                (majorName, majorID))
        except:
            print('no major modified')

        try:
            courseID = request.form['courseID']
            sID = request.form['sID']
            cursor.execute(
                'insert into coursefilemanagement.student_course VALUES (%s,%s)',
                (courseID, sID))
        except:
            print('no course_student modified')

        conn.commit()
        return redirect(url_for('.perinfo'))
Пример #3
0
def register():
    if request.method == 'GET':
        return render_template('register.html')
    else:
        usertype = request.form['usertype']
        account = request.form['account']
        password = request.form['password']
        if len(account) == 0:
            return render_template('error.html', err=0)

        cursor.execute(
            'insert into coursefilemanagement.user(usertype, account, password) values (%s,%s,%s)',
            (usertype, account, password))

        conn.commit()
        return '<h>注册成功!请登录。</h><form action="/login" method="get"><p><button type="submit">返回登录</button></p></form>'
Пример #4
0
def smodify():
    if request.method == 'GET':
        return render_template('smodify.html')
    else:
        studentName = request.form['studentName']
        sID = request.form['sID']
        majorID = request.form['majorID']

        cursor.execute(
            'DELETE FROM coursefilemanagement.student '
            'WHERE account =%s', (current_user.get_id()))

        cursor.execute(
            'insert into coursefilemanagement.student(studentName, sID, account, majorID) values (%s,%s,%s,%s)',
            (studentName, sID, current_user.get_id(), majorID))

        conn.commit()
        return redirect(url_for('.perinfo'))
Пример #5
0
def upload_file():
    if request.method == 'GET':
        return render_template('uploadfile.html')
    else:
        f = request.files['file']
        filename = secure_filename(f.filename)
        if os.path.exists('../files'):
            print('base folder exists')
        else:
            os.mkdir('../files')
        filepath = 'files/' + current_user.get_id()
        if os.path.exists(filepath):
            print('filepath exists')
        else:
            os.mkdir(filepath)
        f.save(os.path.join(filepath, filename))
        print(current_user.get_id())
        fileID = time.strftime("%m%d%H%M%S", time.localtime()) + str(
            random.randint(1, 99))
        cursor.execute(
            'insert into coursefilemanagement.file(fileName, fileID, account) values (%s,%s,%s)',
            (filename, fileID, current_user.get_id()))
        conn.commit()
        return render_template('uploadfile.html')