Example #1
0
def teacher_detail(t_id, school):
    app.config['SQLALCHEMY_DATABASE_URI'] = app.config['SQLALCHEMY_DATABASE_URI_BASE'] + school
    model = Model()
    timestamp = datetime.now()
    if request.method == 'GET':
        teacher = model.get_teacher_detail(t_id)
        ip = request.remote_addr
        if not teacher:
            return render_template('404.html', timestamp=timestamp)
        cmts = model.get_teacher_cmts(teacher.id)
        pop_cmts = order_cmts_by_up_vote(cmts) if cmts else []
        new_cmts = order_cmts_by_time(cmts) if cmts else []
        pop_cmts = get_unique_cmts(pop_cmts)
        new_cmts = get_unique_cmts(new_cmts)
        pop_cmts_methods = [model.get_vote_method(ip, cmt.id) for cmt in pop_cmts]
        new_cmts_methods = [model.get_vote_method(ip, cmt.id) for cmt in new_cmts]
        return render_template('info.html', teacher=teacher, pop_cmts=pop_cmts,
                               new_cmts=new_cmts, pop_cmts_methods=pop_cmts_methods,
                               new_cmts_methods=new_cmts_methods, timestamp=timestamp)

    if request.method == 'POST':
        # 添加关于这个教师的评论
        ip = request.remote_addr
        content = request.form['content'].strip(' ')
        if len(content) > 340:
            return 'long'  # content longer than 340
        point = request.form['point']
        point = int(point)
        current_time = datetime.now()
        res = model.add_cmt(content, current_time, point, t_id, ip)
        if not res:
            return 'not exist'  # teacher not exist
        return 'ok'
Example #2
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)