コード例 #1
0
def editanswer():
    '''edit answers from bulletin board'''
    try:
        now = utils.bb_dt()
        payload = json.loads(request.data)

        if user.email != payload.pop('studentid'):
            msg = 'you can\'t edit answers that aren\'t yours.'
            return jsonify({'status': msg})

        payload['modified'] = now
        bulletin.edit_answer(**payload)
        return jsonify({'status': 'answer has been modified'})
    except Exception as e:
        return jsonify({'error': e.message})
コード例 #2
0
def postanswer():
    '''post answer to bulletin board'''
    try:
        now = utils.bb_dt()
        payload = json.loads(request.data)
        payload['modified'] = now
        payload['posted'] = now
        payload['studentid'] = user.email
        payload['name'] = user.full_name
        payload['rating'] = 0
        question = bulletin.report_questions(id=payload['questionid'])
        answers = question['bodies'][0]['answers']
        bulletin.post_answer(**payload)
        bulletin.edit_question(**{'answers': answers+1,
                                  'id': payload['questionid']})
        return jsonify({'status': 'answer posted'})
    except Exception as e:
        return jsonify({'error': e.message})
コード例 #3
0
def postquestion():
    '''post question to bulletin board'''
    try:
        now = utils.bb_dt()
        payload = {
            x: y[0] for x, y in dict(request.form.copy()).iteritems()
        }

        payload['modified'] = now
        payload['posted'] = now
        payload['answers'] = 0
        payload['studentid'] = user.email
        payload['name'] = user.full_name
        print payload
        bulletin.post_question(**payload)
        return jsonify({'status': 'question posted'})
    except Error as e:
        return jsonify({'error': e.message})