def _get_question(question_ids): """ get question :param question_ids: :return: """ if not isinstance(question_ids, (list, tuple)): return [] questions = db.tbkt_yw.yw_question.select( "content", "video", "image", "type", "show_parse", "category", "id", "article_text").filter(id__in=question_ids)[:] if not questions: return [] out = [] ask_map = get_ask(question_ids) for k, i in enumerate(questions): d = Struct() d.article_title = "" d.article_text = "" d.content = "" if i.type == 8: # 阅读理解 d.article_title = format_content(i.content) d.article_text = i.article_text else: # 不是阅读理解 d.content = i.content d.video = get_absurl(i.video).replace("//", "/") d.image = get_absurl(i.image).replace("//", "/") d.type = i.type d.category = i.category d.no = num_to_ch(k + 1) d.num = k + 1 d.asks = ask_map.get(i.id, []) d.id = i.id out.append(d) return out
def get_question_by_type(object_id, paper_id, scan_type): """ 根据试卷题目类型 返回题目信息 :param scan_type: 扫描类型 1:整张试卷 2:题目类型 3:题目ID :param object_id: 1:paper_id, 2:paper_type_id(试卷类型ID), 3:question_id(题目ID) :param paper_id: 试卷ID :return: """ sql = """ select a.id ask_id, a.question_id, d.paper_type_id from sx2_paper_question_number n inner join sx2_paper_detail d on n.paper_id = %s and n.paper_id = d.paper_id and n.type = 2 and n.object_id = d.question_id inner join sx2_question_ask a on a.question_id = d.question_id """ % paper_id rows = db.ziyuan_slave.fetchall_dict(sql) if not rows: return # 试卷题目类型去重 paper_type = db.ziyuan_slave.sx2_paper_question_number.select( "object_id").filter(paper_id=paper_id, type=1).flat("object_id")[:] if scan_type == 2: # 按试卷题目类型查询 ask_ids = [i for i in rows if i.paper_type_id == object_id] elif scan_type == 3: # 按照题目ID查询 ask_ids = [i for i in rows if i.question_id == object_id] else: ask_ids = [i for i in rows] print ask_ids # 获取举一反三试题详情 out = Struct() out.title = get_paper_title(paper_id) out.paper_id = paper_id out.list = [] paper_number = get_paper_number(paper_id) n = 0 # 初始化小题号 for k, p in enumerate(paper_type): ask_info = Struct() ask_info.q_num = num_to_ch(k + 1) ask_info.paper_type_id = p asks = [] for a in ask_ids: if a.paper_type_id == p: n += 1 info = Struct() # 题号 (1) info.num = paper_number.get(a.ask_id, Struct()).a_num or "" # 题目ID info.aid = a.ask_id asks.append(info) else: # 重新赋值 避免返回整张试卷问题 n = 0 ask_info.asks = asks out.list.append(ask_info) out.list = [i for i in out.list if i.asks] return out