def editquestion(): '''edit questions from bulletin board''' try: now = utils.bb_dt() payload = json.loads(request.database) if user.email != payload.pop('studentid'): msg = 'you can\'t edit questions that aren\'t yours.' return jsonify({'status': msg}) payload['modified'] = now bulletin.edit_question(**payload) return jsonify({'status': 'question has been modified'}) except Exception as e: return jsonify({'error': e.message})
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})