Esempio n. 1
0
def addmessage():
    if g.user.priv == User.STUDENT:
        return render_template('error.html', user=g.user, error=u'haha')
    m = Message()
    m.title = request.form.get('title', None)
    m.desc = request.form.get('content', None)
    try:
        user_id = int(request.form.get('user_id', 0))
    except Exception, ex:
        user_id = 0
Esempio n. 2
0
    group_id = request.form.get('group_id', None)
    m.author_id = g.user.id
    m.status = 0
    resp = make_response()
    resp.headers['Access-Control-Allow-Origin'] = '*'
    resp.headers['Access-Control-Allow-Methods'] = 'POST'
    resp.headers[
        'Access-Control-Allow-Headers'] = 'x-requested-with,content-type'
    print "hahahah", group_id
    group = User.getByGroupId(group_id)
    print "~~~~", len(group)
    try:
        for u in group:
            mm = Message()
            mm.title = m.title
            mm.desc = m.desc
            mm.user_id = u.id
            mm.status = 0
            mm.author_id = g.user.id
            sess.add(mm)
        if m.user_id != 0:
            sess.add(m)
        sess.commit()
        resp.data = json.dumps({'code': 0, 'msg': u'发布成功'})
    except Exception, ex:
        resp.data = json.dumps({'code': -1, 'reason': ex})
        print ex
    return resp


@bbs_app.route('/grade/', methods=['GET'])