Пример #1
0
def get_subject_extract_tip_show_status():
    """
    获取题库更新提示状态
    :return:
    """
    cached_extract_dict = RedisCache.hgetall(KEY_EXTRACTING_SUBJECT_RULE)
    for status in cached_extract_dict.values():
        if status in [1, b'1']:
            return True
    return False
Пример #2
0
    async def get(self):
        query_params = {'record_flag': 1, 'parent_cid': {'$in': [None, '']}}

        title = self.get_argument('title', '')
        code = self.get_argument('code', '')
        if title:
            query_params['title'] = {'$regex': title, '$options': 'i'}
        code = self.get_argument('code', '')
        if code:
            query_params['code'] = {'$regex': code, '$options': 'i'}

        per_page_quantity = int(self.get_argument('per_page_quantity', 10))
        to_page_num = int(self.get_argument('page', 1))
        page_url = '%s?page=$page&per_page_quantity=%s' % (
            self.reverse_url("backoffice_subject_choice_rule_list"), per_page_quantity)
        paging = Paging(page_url, SubjectChoiceRules, current_page=to_page_num, items_per_page=per_page_quantity,
                        sort=['-updated_dt'], **query_params)
        await paging.pager()

        # 检查抽题状态
        cached_extract_dict = RedisCache.hgetall(KEY_EXTRACTING_SUBJECT_RULE)
        cached_process_dict = RedisCache.hgetall(KEY_PREFIX_EXTRACTING_SUBJECT_RULE)
        cached_quantity_dict = RedisCache.hgetall(KEY_EXTRACTING_SUBJECT_QUANTITY)
        for rule in paging.page_items:
            setattr(rule, 'standby', True if cached_extract_dict.get(rule.cid.encode('utf-8')) == b'1' else False)
            in_process = True if cached_process_dict.get(rule.cid.encode('utf-8')) == b'1' else False
            setattr(rule, 'in_process', in_process)

            quantity = cached_quantity_dict.get(rule.cid.encode('utf-8'))
            if in_process:
                setattr(rule, 'quantity', int(quantity) if quantity else 0)
            else:
                if quantity is None:
                    quantity = await SubjectBanks.count(dict(rule_cid=rule.cid), read_preference=ReadPreference.PRIMARY)
                    RedisCache.hset(KEY_EXTRACTING_SUBJECT_QUANTITY, rule.cid, quantity)
                    setattr(rule, 'quantity', quantity)
                else:
                    setattr(rule, 'quantity', int(quantity))

        return locals()