Esempio n. 1
0
def cmt_detail(cmt_id, school):
    app.config['SQLALCHEMY_DATABASE_URI'] = app.config['SQLALCHEMY_DATABASE_URI_BASE'] + school
    model = Model()
    timestamp = datetime.now()
    ip = request.remote_addr
    cmt = model.get_cmt_by_id(cmt_id)
    if not cmt:
        abort(404)
    method = model.get_vote_method(ip, cmt_id)
    teacher_id = model.get_teacher_by_cmt_id(cmt_id)
    return render_template('comment.html', cmt=cmt, method=method, teacher_id=teacher_id, timestamp=timestamp)
Esempio n. 2
0
def vote_cmt(school):
    app.config['SQLALCHEMY_DATABASE_URI'] = app.config['SQLALCHEMY_DATABASE_URI_BASE'] + school
    cmt_id = request.args.get("cmt_id", 0)
    method = request.args.get("method", "error")
    # 获取用户ip,每个ip只能投一票
    ip = request.remote_addr
    model = Model()
    if model.ip_exist(ip, cmt_id):
        return 'already voted'
    model.add_ip(ip, cmt_id, method)
    cmt = model.get_cmt_by_id(cmt_id)
    if not cmt:
        return 'comment not exist'
    model.change_vote(method, cmt)
    return "ok"