def get_question(id): uid = request.cookies.get(cookie_name) uid = db.refresh_user_id(r, uid) q = db.get_question(r, uid, id) resp = make_response(json.dumps(q)) resp.set_cookie(cookie_name, uid) return resp
import db db.drop_collection2() db.drop_collection1() db.add_form("How do you do?","Text", ['good'] , False ) db.add_form("How do you do?","mc",['hood'], False) db.add_form("How is the weather?","mc",['good','great'], True) id = db.get_question_id("How do you do?") q = db.get_question(id) #db.send_question("This should not exsist",["allo","*****@*****.**"]) db.send_question("How is the weather?",["*****@*****.**","Patrick"]) #db.send_question("What?",['*****@*****.**']) #x = db.get_results() #print db.get_recipient(x[0]) print db.get_recipient_questions("*****@*****.**") print db.get_recipient_questions("Patrick") #print "answer id" #print x #print x[0] #print "ready" #db.set_answer(x[0],'3') #print db.get_answer(x[0]) #print db.get_recipient_questions("*****@*****.**")
def showData(): data = request.get_json() #bytes # print("data_receive\n") # print(data) choose_result = db.get_choose_info(data) choose = [] for i in choose_result: choose.append({"num": i['num'], "question": i['question']}) # print(type(choose)) # print(type(choose[0])) #[{'num': 1, 'question': {'Q1': '选项一', 'Q2': ['选项二', '选项三'], 'Q3': '猪猪傻逼'}}, #{'num': 1, 'question': {'Q1': '选项二', 'Q2': ['选项一', '选项二', '选项三'], 'Q3': '我也觉得'}}, #{'num': 1, 'question': {'Q1': '选项一', 'Q2': ['选项二', '选项三', '选项一', '选项四'], 'Q3': '我不认可'}}] result = db.get_question(data) ques = [] for i in result: ques.append({"num": i['num'], "question": i['question']}) ques = ques[0] # print(ques['question']) # [{'num': 'Q1', 'title': '单选题', 'type': 'radio', 'isNeed': True, 'options': ['选项一', '选项二']}, # {'num': 'Q2', 'title': '多选题', 'type': 'checkbox', 'isNeed': True, 'options': ['选项一', '选项二', '选项三', '选项四']}, # {'num': 'Q3', 'title': '文本题', 'type': 'textarea', 'isNeed': True}] res = [] for q in ques['question']: if q['type'] != 'textarea': # print("q = \n") # print(q) q_dict = dict() chos = q['options'] # print("chos = \n") # print(chos) for cho in chos: q_dict[cho] = 0 count_dict = {q['num']: q_dict} # print("count_dict = \n") # print(count_dict) for c in choose: # print("c = \n") # print(c) # print(c['question'][q['num']]) if (type(c['question'][q['num']]) == str): ans = c['question'][q['num']] # print(ans) count_dict[q['num']][ans] = count_dict[q['num']][ans] + 1 else: for ans in c['question'][q['num']]: # print(ans) count_dict[ q['num']][ans] = count_dict[q['num']][ans] + 1 # print("count_dict = \n") # print(count_dict) # print("res = \n") res.append(count_dict) else: pass print("res\n") print(res) # [{'Q1': {'选项一': 2, '选项二': 1}}, # {'Q2': {'选项一': 2, '选项二': 3, '选项三': 3, '选项四': 1}}] return json.dumps(res)
def get_question(rowid): question = db.get_question(rowid) return flask.render_template('question.html', question=question, rowid=rowid)