Example #1
0
def grade_list():
    print g.user.priv
    if g.user.priv == 'student':
        q = Grade.getByUserId(g.user.id)
    else:
        q = Grade.getByTeacherId(g.user.id)
        print q.count()
    subj = request.args.get('subject', None)
    if subj:
        grades = q.filter(
            or_(Grade.subject.like("%" + subj + "%"),
                Grade.name.like("%" + subj + "%"))).all()
    else:
        grades = q.all()
    resp = []
    for grade in grades:
        res = {}
        res['id'] = grade.student_id
        res['teacher'] = u'无'
        res['name'] = u'数据缺失'
        u = User.getById(grade.student_id)
        if u:
            res['name'] = u.name
        else:
            print grade.student_id
        u = User.getById(grade.teacher_id)
        if u:
            res['teacher'] = u.name
        res['subject'] = grade.subject
        res['contest_time'] = str(grade.contest_time)
        res['semester'] = grade.semester
        res['score'] = grade.score
        resp.append(res)
    return render_template('grade.html',
                           user=g.user,
                           grades=resp,
                           cur_page='grade')