def new_question(): user = auth.get_logged_in_user() description = request.form['description'] typ = request.form['type'] presented = request.form.get('presented', False) public_id = request.form['public_id'] options = request.form.getlist('options[]') try: # Find questionnaire qaire = Questionnaire.select().join(Category).where(Category.teacher == user).where(Questionnaire.public_id == public_id).get() # Create question if qtype2str(typ) is None: return response_error('unknown_question_type') question = Question.create(description=description, typ=typ, presented=presented, questionnaire=qaire) # Create option for option_text in options: option = Option.create(question=question, text=option_text) ret = response_success(False) ret['question_id'] = question.id return json.dumps(ret) except Questionnaire.DoesNotExist: return response_error('public_id_not_found')
def new_question(): user = auth.get_logged_in_user() description = request.form['description'] typ = request.form['type'] presented = request.form.get('presented', False) public_id = request.form['public_id'] options = request.form.getlist('options[]') try: # Find questionnaire qaire = Questionnaire.select().join(Category).where( Category.teacher == user).where( Questionnaire.public_id == public_id).get() # Create question if qtype2str(typ) is None: return response_error('unknown_question_type') question = Question.create(description=description, typ=typ, presented=presented, questionnaire=qaire) # Create option for option_text in options: option = Option.create(question=question, text=option_text) ret = response_success(False) ret['question_id'] = question.id return json.dumps(ret) except Questionnaire.DoesNotExist: return response_error('public_id_not_found')
def new_option(): user = auth.get_logged_in_user() question_id = request.form['question_id'] text = request.form['text'] qions = Question.select().join(Questionnaire).join(Category).where(Category.teacher == user).where(Question.id == question_id) for qion in qions: typ = qtype2str(qion.typ) if typ == 'single' or typ == 'multi': option = Option.create(text=text, question=qion) ret = response_success(False) ret['option_id'] = option.id return json.dumps(ret) else: return response_error('options_not_supported') return response_error('question_not_found')