Ejemplo n.º 1
0
    async def get(self):
        query_params = {'record_flag': 1}
        kw_name = self.get_argument('kw_name', '')
        kw_category = self.get_argument('kw_category', '')
        if kw_name:
            query_params['title'] = {'$regex': kw_name, '$options': 'i'}
        if kw_category:
            query_params['needless.category'] = {
                '$regex': kw_category,
                '$options': 'i'
            }
        # 分页 START
        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_vehicle_list"), per_page_quantity)
        paging = Paging(page_url,
                        Vehicle,
                        current_page=to_page_num,
                        items_per_page=per_page_quantity,
                        sort=['-updated_dt'],
                        **query_params)
        await paging.pager()
        # 分页 END

        return locals()
Ejemplo n.º 2
0
    async def get(self):
        race_cid = self.get_argument('race_cid', '')
        menu_list = await get_menu(self, 'config', race_cid)
        if race_cid:
            r_look_stage = LookupStage(RaceSubjectRefer, 'cid', 'subject_cid', 'race_subject_list')
            #  已经引用过的题目,在引用页面中不展示
            race_refer_cid_list = await RaceSubjectRefer.distinct('subject_cid', filtered={'race_cid': race_cid})
            query_params = {'cid': {'$nin': race_refer_cid_list}}
            kw_name = self.get_argument('kw_name', '')
            kw_difficulty = self.get_argument('kw_difficulty', '')
            category_use = self.get_argument('category_use', '')
            query_params['status'] = STATUS_SUBJECT_ACTIVE
            if kw_name:
                query_params['$or'] = [
                    {"custom_code": {'$regex': kw_name, '$options': 'i'}},
                    {"title": {'$regex': kw_name, '$options': 'i'}},
                    {"code": {'$regex': kw_name, '$options': 'i'}}
                ]
            if kw_difficulty:
                query_params['difficulty'] = int(kw_difficulty)
            if category_use:
                query_params['category'] = int(category_use)

            # 分页 START
            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&race_cid=%s&kw_name=%s&kw_difficulty=%s&category_use=%s' % (
                self.reverse_url("backoffice_race_subject_refer_list"), per_page_quantity, race_cid, kw_name,
                kw_difficulty, category_use)
            paging = Paging(page_url, Subject, current_page=to_page_num,
                            items_per_page=per_page_quantity,
                            sort=['custom_code'], **query_params)
            await paging.pager()
            # 分页 END
        return locals()
Ejemplo n.º 3
0
    async def get(self):
        race_cid = self.get_argument('race_cid', '')
        menu_list = await get_menu(self, 'config', race_cid)
        title = self.get_argument('title', '')
        code = self.get_argument('code', '')

        query_params = {'race_cid': race_cid}
        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&code=%s&title=%s' % (
            self.reverse_url("backoffice_race_redpkt_rule_list"),
            per_page_quantity, code, title)

        paging = Paging(page_url,
                        RedPacketRule,
                        current_page=to_page_num,
                        items_per_page=per_page_quantity,
                        left_pipeline_stages=[
                            LookupStage(RedPacketItemSetting, 'cid',
                                        'rule_cid', 'lottery_setting'),
                            LookupStage(RedPacketConf, 'cid', 'rule_cid',
                                        'redpacket_conf')
                        ],
                        sort=['-updated_dt'],
                        **query_params)

        await paging.pager()
        return locals()
Ejemplo n.º 4
0
    async def get(self):
        search_activity_title = self.get_argument('search_activity_title', '')
        search_questionnaire_title = self.get_argument('search_questionnaire_title', '')

        query_param = {}
        and_query_param = [{'record_flag': 1, 'code': {'$ne': None}}]
        if search_questionnaire_title:
            and_query_param.append({'title': {'$regex': search_questionnaire_title}})
        if and_query_param:
            query_param['$and'] = and_query_param

        q_cid_list = await Questionnaire.distinct('cid', filtered=query_param)
        activity_query_param = {'record_flag': 1, 'q_cid': {'$in': q_cid_list}}
        if search_activity_title:
            activity_query_param['title'] = {'$regex': search_activity_title}

        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&search_activity_title=%s&search_questionnaire_title=%s' % \
                   (self.reverse_url("backoffice_activity_list"), per_page_quantity, search_activity_title,
                    search_questionnaire_title)
        paging = Paging(page_url, SurveyActivity, current_page=to_page_num, items_per_page=per_page_quantity,
                        sort=['-updated_dt'], **activity_query_param)
        await paging.pager()

        return locals()
Ejemplo n.º 5
0
 async def get(self):
     race_cid = self.get_argument('race_cid', '')
     menu_list = await get_menu(self, 'config', race_cid)
     if race_cid:
         query_params = {'record_flag': 1, 'race_cid': race_cid}
         index = self.get_argument('index', '')
         refer_index = index  # index在前端可能是个关键字,模板语言解析不了
         if index:
             query_params['$or'] = [{"index": int(index)}]
         r_look_stage = LookupStage(RaceSubjectChoiceRules, 'rule_cid',
                                    'cid', 'rule_list')
         # 分页 START
         per_page_quantity = int(self.get_argument('per_page_quantity', 10))
         to_page_num = int(self.get_argument('page', 1))
         page_url = '%s?race_cid=%s&page=$page&per_page_quantity=%s&index=%s' % (
             self.reverse_url("backoffice_race_game_checkpoint_list"),
             race_cid, per_page_quantity, index)
         paging = Paging(page_url,
                         RaceGameCheckPoint,
                         pipeline_stages=[r_look_stage],
                         current_page=to_page_num,
                         items_per_page=per_page_quantity,
                         sort=['index'],
                         **query_params)
         await paging.pager()
         # 分页 END
     return locals()
Ejemplo n.º 6
0
    async def get(self):
        member_id = self.get_argument('member_id')
        search_source = self.get_argument('search_source', '')
        search_datetime = self.get_argument('search_datetime', '')

        member = await Member.get_by_id(member_id)
        query_param = {'member_cid': member.cid}
        if search_source:
            query_param['source'] = int(search_source)
        if search_datetime:
            start = datetime.datetime.strptime(search_datetime,
                                               '%Y-%m-%d').replace(hour=0,
                                                                   minute=0,
                                                                   second=0)
            end = datetime.datetime.strptime(search_datetime,
                                             '%Y-%m-%d').replace(hour=23,
                                                                 minute=59,
                                                                 second=59)
            query_param['reward_datetime'] = {'$lt': end, '$gt': start}

        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&search_source=%s&search_datetime=%s&member_id=%s' % \
                   (self.reverse_url("backoffice_diamond_detail"), per_page_quantity, search_source, search_datetime,
                    member_id)
        paging = Paging(page_url,
                        MemberDiamondDetail,
                        current_page=to_page_num,
                        items_per_page=per_page_quantity,
                        sort=['-updated_dt'],
                        **query_param)
        await paging.pager()

        return locals()
Ejemplo n.º 7
0
    async def get(self):

        search_account = self.get_argument('search_account', '')
        search_nickname = self.get_argument('search_nickname', '')

        query_param = {}
        and_query_param = [{'record_flag': 1}]
        if search_nickname:
            and_query_param.append({'nick_name': {'$regex': search_nickname}})
        if search_account:
            and_query_param.append(
                {'$or': [{
                    'code': {
                        '$regex': search_account
                    }
                }]})

        if and_query_param:
            query_param['$and'] = and_query_param

        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&search_account=%s&search_nickname=%s' % \
                   (self.reverse_url("backoffice_integral_list"), per_page_quantity, search_account, search_nickname)
        paging = Paging(page_url,
                        Member,
                        current_page=to_page_num,
                        items_per_page=per_page_quantity,
                        sort=['-updated_dt'],
                        **query_param)
        await paging.pager()

        return locals()
Ejemplo n.º 8
0
    async def get(self):

        # 上下架礼品数量
        active_amount = await Present.count(filtered={'record_flag': 1, 'status': STATUS_PRESENT_ACTIVE})
        inactive_amount = await Present.count(filtered={'record_flag': 1, 'status': STATUS_PRESENT_INACTIVE})
        all_amount = await Present.count(filtered={'record_flag': 1})

        search_title = self.get_argument('search_title', '')
        search_category = self.get_argument('search_category', '')
        search_status = self.get_argument('search_status', '')

        query_param = {}
        and_query_param = [{'record_flag': 1}]
        if search_title:
            and_query_param.append({'title': {'$regex': search_title}})
        if search_category:
            and_query_param.append({'category': int(search_category)})
        if search_status:
            and_query_param.append({'status': int(search_status)})

        if and_query_param:
            query_param['$and'] = and_query_param

        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&search_source=%s&search_datetime=%s' % \
                   (self.reverse_url("backoffice_present_list"), per_page_quantity, search_title, search_category)
        paging = Paging(page_url, Present, current_page=to_page_num, items_per_page=per_page_quantity,
                        sort=['-sort', '-updated_dt'], **query_param)

        await paging.pager()

        return locals()
Ejemplo n.º 9
0
    async def get(self):
        subject_dimension_list = await SubjectDimension.find(
            dict(status=STATUS_SUBJECT_DIMENSION_ACTIVE, parent_cid=None)).sort('created_dt').to_list(None)
        for subject_dimension in subject_dimension_list:
            sub_subject_dimension = await  SubjectDimension.find(
                dict(status=STATUS_SUBJECT_DIMENSION_ACTIVE, parent_cid=subject_dimension.cid)).sort(
                'created_dt').to_list(None)
            subject_dimension.sub_subject_dimension_list = []
            if sub_subject_dimension:
                subject_dimension.sub_subject_dimension_list = sub_subject_dimension
        dimension_dict = {}
        query_params = {'record_flag': 1}

        subject_dimension_cid_str = self.get_argument('subject_dimension_cid_list', '')

        subject_dimension_cid_list = subject_dimension_cid_str.split(',')
        kw_name = self.get_argument('kw_name', '')
        kw_difficulty = self.get_argument('kw_difficulty', '')
        kw_category = self.get_argument('kw_category', '')
        kw_status = self.get_argument('kw_status', '')
        category_use = self.get_argument('category_use', '')
        if subject_dimension_cid_list:
            for temp in subject_dimension_cid_list:
                if temp:
                    dimension_cid, sub_dimension_cid = temp.split('_')
                    dimension_dict[dimension_cid] = sub_dimension_cid
                    if dimension_cid and sub_dimension_cid:
                        query_params['dimension_dict.%s' % dimension_cid] = sub_dimension_cid
        if kw_name:
            query_params['$or'] = [
                {"custom_code": {'$regex': kw_name, '$options': 'i'}},
                {"title": {'$regex': kw_name, '$options': 'i'}},
                {"code": {'$regex': kw_name, '$options': 'i'}}
            ]
        # if kw_difficulty:
        #     query_params['difficulty'] = int(kw_difficulty)
        # if kw_category:
        #     query_params['category'] = int(kw_category)
        if kw_status:
            query_params['status'] = int(kw_status)

        if category_use:
            if category_use == '1':
                query_params['category_use'] = {'$nin': [CATEGORY_SUBJECT_BENCHMARK, CATEGORY_SUBJECT_GRADUATION]}
            else:
                query_params['category_use'] = int(category_use)

        # 分页 START
        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&subject_dimension_cid_list=%s&kw_name=%s&kw_status=%s&category_use=%s' % (
            self.reverse_url("backoffice_subject_list"), per_page_quantity, subject_dimension_cid_str, kw_name,
            kw_status, category_use)
        paging = Paging(page_url, Subject, current_page=to_page_num, items_per_page=per_page_quantity,
                        sort=['custom_code'], **query_params)
        await paging.pager()
        # 分页 END
        return locals()
Ejemplo n.º 10
0
    async def get(self):
        search_name = self.get_argument('search_name', '')

        query_param = {}
        and_query_param = [{
            'db_mark': {
                '$ne': ''
            }
        }, {
            'release_time': {
                '$ne': ''
            }
        }]

        if search_name:
            and_query_param.append({
                '$or': [
                    {
                        'name': {
                            '$regex': search_name
                        }
                    },
                    {
                        'actor': {
                            '$regex': search_name
                        }
                    },
                    {
                        'director': {
                            '$regex': search_name
                        }
                    },
                    {
                        'label': {
                            '$regex': search_name
                        }
                    },
                ]
            })

        if and_query_param:
            query_param['$and'] = and_query_param

        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&search_name=%s' % \
                   (self.reverse_url("backoffice_film_list"), per_page_quantity, search_name)
        paging = Paging(page_url,
                        Films,
                        current_page=to_page_num,
                        items_per_page=per_page_quantity,
                        **query_param)
        await paging.pager()

        return locals()
Ejemplo n.º 11
0
 async def get(self):
     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_source_list'), per_page_quantity)
     paging = Paging(page_url,
                     GameMemberSource,
                     current_page=to_page_num,
                     items_per_page=per_page_quantity,
                     sort=['-updated_dt'])
     await paging.pager()
     return locals()
Ejemplo n.º 12
0
    async def get(self):
        search_code = self.get_argument('search_code', '')
        search_member = self.get_argument('search_member', '')
        search_datetime = self.get_argument('search_datetime', '')

        query_param = {}
        and_query_param = [{'record_flag': 1}]
        if search_code:
            and_query_param.append({'code': {'$regex': search_code}})
        if search_datetime:
            start = datetime.strptime(search_datetime,
                                      '%Y-%m-%d').replace(hour=0,
                                                          minute=0,
                                                          second=0)
            end = datetime.strptime(search_datetime,
                                    '%Y-%m-%d').replace(hour=23,
                                                        minute=59,
                                                        second=59)
            query_param['order_datetime'] = {
                '$lt': end,
                '$gt': start,
            }
        if search_member:
            and_query_param.append({
                '$or': [{
                    'receiver_name': {
                        '$regex': search_member
                    }
                }, {
                    'receiver_mobile': {
                        '$regex': search_member
                    }
                }]
            })

        if and_query_param:
            query_param['$and'] = and_query_param

        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&search_source=%s&search_datetime=%s&search_datetime=%s' % \
                   (self.reverse_url("backoffice_order_list"), per_page_quantity, search_code, search_member,
                    search_datetime)
        paging = Paging(page_url,
                        ExchangeOrder,
                        current_page=to_page_num,
                        items_per_page=per_page_quantity,
                        sort=['-updated_dt'],
                        **query_param)

        await paging.pager()

        return locals()
Ejemplo n.º 13
0
    async def get(self):
        query_params = {'record_flag': 1}

        # 分页 START
        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_role_list"), per_page_quantity)
        paging = Paging(page_url,
                        Role,
                        current_page=to_page_num,
                        items_per_page=per_page_quantity,
                        sort=['-updated_dt'],
                        **query_params)
        await paging.pager()
        # 分页 END

        return locals()
Ejemplo n.º 14
0
    async def get(self):
        search_account = self.get_argument('search_account', '')
        search_nickname = self.get_argument('search_nickname', '')
        search_register_time = self.get_argument('search_register_time', '')

        query_param = {}
        and_query_param = [{'record_flag': 1}]
        if search_nickname:
            and_query_param.append({'nick_name': {'$regex': search_nickname}})
        if search_account:
            and_query_param.append({'code': {'$regex': search_account}})
        if search_register_time:
            start = datetime.strptime(search_register_time,
                                      '%Y-%m-%d').replace(hour=0,
                                                          minute=0,
                                                          second=0)
            end = datetime.strptime(search_register_time,
                                    '%Y-%m-%d').replace(hour=23,
                                                        minute=59,
                                                        second=59)
            and_query_param.append(
                {'register_datetime': {
                    '$lt': end,
                    '$gt': start
                }})

        if and_query_param:
            query_param['$and'] = and_query_param

        # 分页
        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&search_account=%s&search_nickname=%s&search_register_time=%s' % \
                   (self.reverse_url("backoffice_member_list"), per_page_quantity, search_account, search_nickname,
                    search_register_time)
        paging = Paging(page_url,
                        Member,
                        current_page=to_page_num,
                        items_per_page=per_page_quantity,
                        sort=['-updated_dt'],
                        **query_param)
        await paging.pager()

        return locals()
Ejemplo n.º 15
0
    async def get(self):
        search_name = self.get_argument('search_name', '')

        query_param = {}
        if search_name:
            query_param = {'name': {'$regex': search_name}}

        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&search_name=%s' % \
                   (self.reverse_url("backoffice_hot_search_list"), per_page_quantity, search_name)
        paging = Paging(page_url,
                        HotSearch,
                        current_page=to_page_num,
                        items_per_page=per_page_quantity,
                        **query_param)
        await paging.pager()

        return locals()
Ejemplo n.º 16
0
    async def get(self):
        h_lookup_stage = LookupStage(Subject, 'subject_cid', 'cid', 'subject_list')
        race_cid = self.get_argument('race_cid', '')
        menu_list = await get_menu(self, 'config', race_cid)
        if race_cid:
            query_params = {'race_cid': race_cid}
            kw_name = self.get_argument('kw_name', '')
            kw_difficulty = self.get_argument('kw_difficulty', '')
            category_use = self.get_argument('category_use', '')
            query_subject_params = {}
            if kw_name:
                query_subject_params['$or'] = [
                    {"custom_code": {'$regex': kw_name, '$options': 'i'}},
                    {"title": {'$regex': kw_name, '$options': 'i'}},
                ]
                subject_cid_list = await Subject.distinct('cid', filtered=query_subject_params)
                query_params['$and'] = [
                    {'subject_cid': {'$in': subject_cid_list}}
                ]
            if kw_difficulty:
                query_subject_params['difficulty'] = int(kw_difficulty)
                subject_cid_list = await Subject.distinct('cid', filtered=query_subject_params)
                query_params['$and'] = [
                    {'subject_cid': {'$in': subject_cid_list}}
                ]
            if category_use:
                query_subject_params['category'] = int(category_use)
                subject_cid_list = await Subject.distinct('cid', filtered=query_subject_params)
                query_params['$and'] = [
                    {'subject_cid': {'$in': subject_cid_list}}
                ]

            # 分页 START
            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&race_cid=%s&kw_name=%s&kw_difficulty=%s&category_use=%s' % (
                self.reverse_url("backoffice_race_subject_list"), per_page_quantity, race_cid, kw_name,
                kw_difficulty, category_use)
            paging = Paging(page_url, RaceSubjectRefer, current_page=to_page_num, pipeline_stages=[h_lookup_stage],
                            items_per_page=per_page_quantity, **query_params)
            await paging.pager()
            # 分页 END
        return locals()
Ejemplo n.º 17
0
    async def get(self):
        search_name = self.get_argument('search_name', '')
        search_phone = self.get_argument('search_phone', '')
        lang = self.get_argument('lang', '')
        if lang == 'en':
            lang = 'en'
        else:
            lang = 'cn'
        query_param = {}
        and_query_param = [{'record_flag': 1}]
        if search_phone:
            and_query_param.append({'mobile': {'$regex': search_phone}})
        if search_name:
            and_query_param.append({
                '$or': [{
                    'name': {
                        '$regex': search_name
                    }
                }, {
                    'user_name': {
                        '$regex': search_name
                    }
                }]
            })

        if and_query_param:
            query_param['$and'] = and_query_param

        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&search_name=%s&search_phone=%s&lang=%s' % \
                   (self.reverse_url("backoffice_user_list"), per_page_quantity, search_name, search_phone, lang)
        paging = Paging(page_url,
                        User,
                        current_page=to_page_num,
                        items_per_page=per_page_quantity,
                        sort=['-updated_dt'],
                        **query_param)
        await paging.pager()

        ad_data = await get_administrative_division()

        return locals()
Ejemplo n.º 18
0
    async def get(self):
        query_params = {'record_flag': 1}

        sd_title = self.get_argument('sd_title', '')
        if sd_title:
            query_params['title'] = {'$regex': sd_title, '$options': 'i'}
        # 分页 START
        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_difficulty_list"), per_page_quantity)
        paging = Paging(page_url,
                        SubjectDifficulty,
                        current_page=to_page_num,
                        items_per_page=per_page_quantity,
                        sort=['-updated_dt'],
                        **query_params)
        await paging.pager()
        return locals()
Ejemplo n.º 19
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()
Ejemplo n.º 20
0
    async def get(self):
        search_push_time = self.get_argument('search_push_time')
        activity_cid = self.get_argument('activity_cid')
        push_result = self.get_argument('push_result', '')

        survey_activity = await SurveyActivity.find_one({'cid': activity_cid, 'record_flag': 1})
        # 推送总人数
        push_member_amount = survey_activity.pushed_amount if survey_activity.pushed_amount else 0
        # 样本回收数
        all_sample_amount = survey_activity.sample_amount if survey_activity.sample_amount else 0
        # 样本回收率
        sample_rate = '%.2f' % (all_sample_amount * 100 / push_member_amount) if push_member_amount else 0.00
        # 推送数量
        all_push_amount = await SurveyPushAction.count(filtered={'activity_cid': activity_cid, 'record_flag': 1})
        # 推送成功数
        success_push_amount = await SurveyPushAction.count(filtered={'activity_cid': activity_cid, 'record_flag': 1,
                                                                     'status': STATUS_PULL_ACTION_PUSHED_SUCCESS})
        # 推送失败数
        fail_push_amount = await SurveyPushAction.count(filtered={'activity_cid': activity_cid, 'record_flag': 1,
                                                                  'status': STATUS_PULL_ACTION_PUSHED_FAIL})

        push_query_param = {'record_flag': 1, 'activity_cid': activity_cid}
        if push_result:
            push_query_param['status'] = int(push_result)
        if search_push_time:
            push_time = datetime.strptime(search_push_time, '%Y-%m-%d')
            push_query_param['push_datetime'] = {
                '$gte': push_time.replace(hour=0, minute=0, second=0),
                '$lte': push_time.replace(hour=23, minute=59, second=59),
            }

        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&search_push_time=%s' % \
                   (self.reverse_url("backoffice_activity_push_list"), per_page_quantity, search_push_time)
        paging = Paging(page_url, SurveyPushAction, current_page=to_page_num, items_per_page=per_page_quantity,
                        sort=['-updated_dt'], **push_query_param)
        await paging.pager()

        return locals()
Ejemplo n.º 21
0
    async def get(self, dimension_id):
        cid_list = await SubjectDimension.distinct(
            'cid', {'_id': ObjectId(dimension_id)})
        query_params = {'record_flag': 1, 'parent_cid': {'$in': cid_list}}

        sd_title = self.get_argument('sd_title', '')
        if sd_title:
            query_params['title'] = {'$regex': sd_title, '$options': 'i'}
        # 分页 START
        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_sub_dimensions_list",
            dimension_id), per_page_quantity)
        paging = Paging(page_url,
                        SubjectDimension,
                        current_page=to_page_num,
                        items_per_page=per_page_quantity,
                        sort=['ordered'],
                        **query_params)
        await paging.pager()
        return locals()
Ejemplo n.º 22
0
    async def get(self):
        search_member_code = self.get_argument('search_member_code', '')
        search_member_name = self.get_argument('search_member_name', '')
        search_survey_status = self.get_argument('search_survey_status', '')
        activity_cid = self.get_argument('activity_cid', '')
        push_cid = self.get_argument('push_cid', '')

        # 判断推送状态
        activity = await SurveyActivity.get_by_cid(activity_cid)
        push = await SurveyPushAction.get_by_cid(push_cid)

        all_member_cid_list = push.all_member_cid_list if push.all_member_cid_list else []

        # 判断答卷状态
        survey_history_query_param = {'record_flag': 1, 'action_cid': push_cid}
        member_survey_history = await MemberSurveyHistory.find(survey_history_query_param).to_list(None)
        survey_member_cid_list = await MemberSurveyHistory.distinct('member_cid', survey_history_query_param)

        member_query_param = {'record_flag': 1, 'cid': {'$in': all_member_cid_list}}
        if search_member_code:
            member_query_param['code']['$regex'] = search_member_code
        if search_member_name:
            member_query_param['name'] = {'$regex': search_member_name}
        if search_survey_status == '1':
            member_query_param.setdefault('cid', {})['$in'] = survey_member_cid_list
        if search_survey_status == '0':
            member_query_param.setdefault('cid', {})['$nin'] = survey_member_cid_list

        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&search_member_code=%s&search_member_name=%s' \
                   '&search_survey_status=%s' % (
                       self.reverse_url("backoffice_activity_push_detail"), per_page_quantity, search_member_code,
                       search_member_name, search_survey_status)
        paging = Paging(page_url, Member, current_page=to_page_num, items_per_page=per_page_quantity,
                        sort=['-updated_dt'], **member_query_param)
        await paging.pager()

        return locals()
Ejemplo n.º 23
0
 async def get(self):
     query_params = {'record_flag': 1}
     dan_grade_name = self.get_argument('dan_grade_name', '')
     if dan_grade_name:
         query_params['$or'] = [{
             "title": {
                 '$regex': dan_grade_name,
                 '$options': 'i'
             }
         }]
     # 分页 START
     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&dan_grade_name=%s' % (
         self.reverse_url("backoffice_dan_grade_list"), per_page_quantity,
         dan_grade_name)
     paging = Paging(page_url,
                     GameDanGrade,
                     pipeline_stages=[
                         LookupStage(UploadFiles, 'thumbnail', 'cid',
                                     'image_list')
                     ],
                     current_page=to_page_num,
                     items_per_page=per_page_quantity,
                     sort=['index'],
                     **query_params)
     await paging.pager()
     # 分页 END
     #  段位缩略图的字典 在第几个位置有图片
     thumbnail_dict = dict()
     for index, thumbnail in enumerate(paging.page_items):
         if thumbnail.image_list:
             title_img_url = '%s://%s%s%s%s' % (
                 SERVER_PROTOCOL, SERVER_HOST, STATIC_URL_PREFIX, 'files/',
                 thumbnail.image_list[0].title)
             thumbnail_dict[index] = title_img_url
     print(thumbnail_dict)
     return locals()
Ejemplo n.º 24
0
    async def get(self):
        query_params = {'record_flag': 1}

        kw_name = self.get_argument('kw_name', '')
        kw_nickname = self.get_argument('kw_nickname', '')
        if kw_name:
            query_params['$or'] = [{
                "code": {
                    '$regex': kw_name,
                    '$options': 'i'
                }
            }, {
                "name": {
                    '$regex': kw_name,
                    '$options': 'i'
                }
            }]
        if kw_nickname:
            query_params['nick_name'] = {
                '$regex': kw_nickname,
                '$options': 'i'
            }
        # 分页 START
        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&kw_name=%s&kw_nickname=%s' % (
            self.reverse_url("backoffice_diamond_list"), per_page_quantity,
            kw_name, kw_nickname)
        paging = Paging(page_url,
                        Member,
                        current_page=to_page_num,
                        items_per_page=per_page_quantity,
                        sort=['-updated_dt'],
                        **query_params)
        await paging.pager()
        # 分页 END
        return locals()
Ejemplo n.º 25
0
    async def get(self):
        race_cid = self.get_argument('race_cid', '')
        menu_list = await get_menu(self, 'config', race_cid)
        query_params = {'record_flag': 1, 'race_cid': race_cid}
        title = self.get_argument('title', '')
        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?race_cid=%s&page=$page&per_page_quantity=%s&title=%s&code=%s' % (
            self.reverse_url("backoffice_race_unit_manager_list"), race_cid,
            per_page_quantity, title, code)
        paging = Paging(page_url,
                        Company,
                        current_page=to_page_num,
                        items_per_page=per_page_quantity,
                        sort=['created_dt'],
                        **query_params)
        await paging.pager()
        return locals()
Ejemplo n.º 26
0
    async def get(self):
        search_title = self.get_argument('search_title', '')

        query_param = {}
        and_query_param = [{'record_flag': 1}]
        if search_title:
            and_query_param.append({'title': {'$regex': search_title}})
        if and_query_param:
            query_param['$and'] = and_query_param

        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&search_title=%s' % (
            self.reverse_url("backoffice_questionnaire_list"),
            per_page_quantity, search_title)
        paging = Paging(page_url,
                        Questionnaire,
                        current_page=to_page_num,
                        items_per_page=per_page_quantity,
                        sort=['-updated_dt'],
                        **query_param)
        await paging.pager()

        return locals()
Ejemplo n.º 27
0
    async def get(self):
        race_cid = self.get_argument('race_cid', '')
        menu_list = await get_menu(self, 'config', race_cid)
        put_out_form = self.get_argument('put_out_form', '')
        red_packet_item = self.get_argument('red_packet_item', '')
        if race_cid:
            # 抽奖总览
            race = await Race.find_one({'cid': race_cid, 'record_flag': 1})
            #  找到该活动下面的所有rule_cid
            #  已经发放的红包个数
            already_put_red_packet_amount_list = await RedPacketBox.aggregate([
                MatchStage({
                    'race_cid': race_cid,
                    'draw_status': STATUS_REDPACKET_AWARDED,
                    'member_cid': {
                        '$ne': None
                    },
                    'award_cid': {
                        '$ne': None
                    },
                    'record_flag': 1
                }),
                GroupStage(None,
                           sum={'$sum': '$award_amount'},
                           quantity={'$sum': 1})
            ]).to_list(None)
            #  抽奖详情
            kw_word = self.get_argument('kw_word', '')
            #  奖项标题
            item_title = self.get_argument('item_title', '')
            stage_list = [
                LookupStage(Member, 'member_cid', 'cid', 'member_list'),
                LookupStage(RaceGameCheckPoint, 'checkpoint_cid', 'cid',
                            'checkpoint_list'),
                LookupStage(RedPacketItemSetting, 'award_cid', 'cid',
                            'setting_list'),
                LookupStage(RedPacketConf, 'award_cid', 'cid', 'conf_list'),
                ProjectStage(
                    **{
                        'member_cid': '$member_cid',
                        'nick_name': {
                            '$arrayElemAt': ['$member_list.nick_name', 0]
                        },
                        'checkpoint': {
                            '$arrayElemAt': ['$checkpoint_list.alias', 0]
                        },
                        'category': {
                            '$cond': {
                                'if': {
                                    '$ne': ['$setting_list',
                                            list()]
                                },
                                'then': '抽奖形式',
                                'else': '直接发放'
                            }
                        },
                        'detail': {
                            '$cond': {
                                'if': {
                                    '$ne': ['$setting_list',
                                            list()]
                                },
                                'then': {
                                    '$arrayElemAt': ['$setting_list.title', 0]
                                },
                                'else': {
                                    '$arrayElemAt': ['$conf_list.category', 0]
                                }
                            }
                        },
                        'award_amount': '$award_amount',
                        'draw_dt': '$draw_dt',
                        'award_cid': '$award_cid'
                    }),
            ]
            query_dict = {}
            if kw_word:
                query_dict['$or'] = [
                    {
                        'nick_name': {
                            '$regex': kw_word,
                            '$options': 'i'
                        }
                    },
                    {
                        'member_cid': {
                            '$regex': kw_word,
                            '$options': 'i'
                        }
                    },
                    {
                        'checkpoint': {
                            '$regex': kw_word,
                            '$options': 'i'
                        }
                    },
                ]
            if put_out_form:
                query_dict['category'] = put_out_form
            if red_packet_item and put_out_form != CATEGORY_REDPACKET_RULE_DICT.get(
                    CATEGORY_REDPACKET_RULE_DIRECT):
                query_dict['detail'] = red_packet_item
            query = MatchStage(query_dict)
            stage_list.append(query)
            query_match_dict = {
                "race_cid": race_cid,
                'draw_status': STATUS_REDPACKET_AWARDED,
                'member_cid': {
                    '$ne': None
                },
                'award_cid': {
                    '$ne': None
                },
                'record_flag': 1
            }
            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&race_cid=%s&kw_name=%s&put_out_form=%s' % (
                self.reverse_url("backoffice_race_redpkt_rule_see_result"),
                per_page_quantity, race_cid, kw_word, put_out_form)
            paging = Paging(page_url,
                            RedPacketBox,
                            current_page=to_page_num,
                            pipeline_stages=stage_list,
                            sort=['award_amount'],
                            items_per_page=per_page_quantity,
                            **query_match_dict)
            await paging.pager()

            #  抽奖形式的奖项列表
            lottery_item_list = await RedPacketItemSetting.distinct(
                'title', {
                    'race_cid': race_cid,
                    'record_flag': 1
                })
        return locals()
Ejemplo n.º 28
0
    async def do_paging_from_member_subject_statistics(self, match_dict, query_params, dimension_dict,
                                                       search_arguments):
        """

        :param match_dict:
        :param query_params:
        :param dimension_dict:
        :param search_arguments:
        :return:
        """
        subject_dimension_list = await SubjectDimension.aggregate([
            MatchStage({'parent_cid': None}),
            SortStage([('ordered', ASC)]),
            LookupStage(SubjectDimension, 'cid', 'parent_cid', 'sub_list')
        ]).to_list(None)

        match_dict = {}
        search_arguments = {}

        # 地方科协不会开放此权限,因此显示全部省份数据
        # m_province_code_list, m_city_code_list, _ = await do_different_administrative_division2(
        #     self.current_user.manage_region_code_list)
        # if m_province_code_list:
        #     match_dict['province_code'] = {'$in': m_province_code_list}
        # if m_city_code_list:
        #     match_dict['city_code'] = {'$in': m_city_code_list}

        # 维度信息
        dimension_dict = {}
        for dimension in subject_dimension_list:
            t_dimension = self.get_argument(dimension.cid, '')
            if t_dimension:
                dimension_dict['%s' % dimension.cid] = t_dimension
            search_arguments[dimension.cid] = t_dimension

        # 默认只显示,状态启用,并且不是基准测试或毕业测试的题目
        match_dimension = {'$and': [
            {'status': STATUS_SUBJECT_ACTIVE},
            {'category_use': {
                '$nin': [CATEGORY_SUBJECT_BENCHMARK, CATEGORY_SUBJECT_GRADUATION]}}
        ]}
        if dimension_dict:
            match_dimension['$and'].extend([{'dimension_dict.%s' % k: v} for k, v in dimension_dict.items()])

        subject_cid_list = await Subject.distinct('cid', match_dimension)
        if subject_cid_list:
            match_dict['subject_cid'] = {'$in': subject_cid_list}

        query_params = {}
        s_province = self.get_argument('province', '')
        if s_province:
            query_params['province_code'] = s_province
        search_arguments['province'] = s_province

        s_city = self.get_argument('city', '')
        if s_city:
            query_params['city_code'] = s_city
        search_arguments['city'] = s_city

        s_age_group = self.get_argument('age_group', '')
        if s_age_group:
            query_params['age_group'] = int(s_age_group)
        search_arguments['age_group'] = s_age_group

        s_gender = self.get_argument('gender', '')
        if s_gender:
            query_params['gender'] = int(s_gender)
        search_arguments['gender'] = s_gender

        s_education = self.get_argument('education', '')
        if s_education:
            query_params['education'] = int(s_education)
        search_arguments['education'] = s_education

        manage_stage = MatchStage(match_dict)
        query_stage = MatchStage(query_params)
        group_stage = GroupStage('subject_cid', t_total={'$sum': '$total'}, t_correct={'$sum': '$correct'})
        project_stage = ProjectStage(
            total='$t_total', correct='$t_correct',
            percent={
                '$cond': {
                    'if': {'$eq': ['$t_total', 0]},
                    'then': 0,
                    'else': {
                        '$divide': ['$t_correct', '$t_total']
                    }
                }
            }
        )

        s_lookup_stage = LookupStage(Subject, '_id', 'cid', 'subject_list')
        so_lookup_stage = LookupStage(SubjectOption, '_id', 'subject_cid', 'subject_option_list')

        not_null_match = MatchStage({
            'subject_list': {'$ne': []},
            'subject_option_list': {'$ne': []}
        })

        final_project = ProjectStage(**{
            'custom_code': {'$arrayElemAt': ['$subject_list.custom_code', 0]},
            'code': {'$arrayElemAt': ['$subject_list.code', 0]},
            'title': {'$arrayElemAt': ['$subject_list.title', 0]},
            'subject_list': '$subject_list',
            'subject_option_list': '$subject_option_list',
            'dimension': {'$arrayElemAt': ['$subject_list.dimension_dict', 0]},
            'total': '$total',
            'correct': '$correct',
            'percent': '$percent'
        })

        sort_list = []
        sort = self.get_argument('sort')
        if sort:
            sort = int(sort)
        else:
            sort = 1

        search_arguments['sort'] = sort
        if sort == 1:
            sort_list.append('-percent')
        elif sort == 2:
            sort_list.append('percent')
        elif sort == 3:
            sort_list.append('-total')
        elif sort == 4:
            sort_list.append('total')
        elif sort == 5:
            sort_list.append('-code')
        elif sort == 6:
            sort_list.append('code')
        # 分页 START
        per_page_quantity = int(self.get_argument('per_page_quantity', 50))
        to_page_num = int(self.get_argument('page', 1))

        page_url = '%s?page=$page&per_page_quantity=%s' % (
            self.reverse_url("backoffice_reports_subject_analysis_list"),
            per_page_quantity) + '&sort=%s&' % sort + '&'.join(
            ['='.join((key, str(search_arguments.get(key)))) for key in sorted(search_arguments.keys())])
        paging = Paging(
            page_url, MemberSubjectStatistics, current_page=to_page_num, items_per_page=per_page_quantity,
            pipeline_stages=[manage_stage, query_stage, group_stage, project_stage, s_lookup_stage, so_lookup_stage,
                             not_null_match, final_project],
            sort=sort_list)
        await paging.pager()
        for temp_item in paging.page_items:
            option_dict = dict()
            if not temp_item.subject_option_list:
                pass
            else:
                for opt in temp_item.subject_option_list:
                    option_dict[opt.sort] = {'title': opt.title, 'correct': opt.correct}

            setattr(temp_item, 'option_dict', option_dict)

        return locals()
Ejemplo n.º 29
0
    async def do_paging_from_report_subject_statistics_middle(self, category, match_dict: dict, query_params: dict,
                                                              dimension_dict: dict, search_arguments: dict):
        """

        :param category:
        :param match_dict:
        :param query_params:
        :param dimension_dict:
        :param search_arguments:
        :return:
        """

        # 默认只显示,状态启用,并且不是基准测试或毕业测试的题目
        match_dimension = {'$and': [
            {'status': STATUS_SUBJECT_ACTIVE},
            {'category_use': {
                '$nin': [CATEGORY_SUBJECT_BENCHMARK, CATEGORY_SUBJECT_GRADUATION]}}
        ]}
        if dimension_dict:
            match_dimension['$and'].extend([{'dimension_dict.%s' % k: v} for k, v in dimension_dict.items()])

        subject_cid_list = await Subject.distinct('cid', match_dimension)
        if subject_cid_list:
            match_dict['subject_cid'] = {'$in': subject_cid_list}

        region_match = {}
        for k, v in match_dict.items():
            region_match['condition.%s' % k] = v

        query_dict = {'category': category}
        for k, v in query_params.items():
            query_dict['condition.%s' % k] = v

        if dimension_dict:
            for k, v in dimension_dict.items():
                query_dict['dimension.%s' % k] = v

        match_region = MatchStage(region_match)
        query_stage = MatchStage(query_dict)
        group_stage = GroupStage('condition.subject_cid',
                                 custom_code={'$first': '$custom_code'},
                                 code={'$first': '$code'},
                                 title={'$first': '$title'},
                                 task_dt={'$first': '$task_dt'},
                                 option_dict={'$first': '$option_dict'},
                                 dimension={'$first': '$dimension'},
                                 total={'$sum': '$total'},
                                 correct={'$sum': '$correct'}
                                 )

        final_project = ProjectStage(**{
            'custom_code': 1,
            'code': 1,
            'title': 1,
            'task_dt': 1,
            'option_dict': 1,
            'dimension': 1,
            'total': 1,
            'correct': 1,
            'percent': {
                '$cond': {
                    'if': {'$eq': ['$total', 0]},
                    'then': 0,
                    'else': {
                        '$divide': ['$correct', '$total']
                    }
                }
            }
        })

        sort_list = list()
        sort = int(self.get_argument('sort', 1))
        if sort == 1:
            sort_list.append('-percent')
        elif sort == 2:
            sort_list.append('percent')
        elif sort == 3:
            sort_list.append('-total')
        elif sort == 4:
            sort_list.append('total')
        elif sort == 5:
            sort_list.append('-code')
        elif sort == 6:
            sort_list.append('code')

        per_page_quantity = int(self.get_argument('per_page_quantity', 50))
        to_page_num = int(self.get_argument('page', 1))

        page_url = '%s?page=$page&per_page_quantity=%s' % (
            self.reverse_url("backoffice_reports_subject_analysis_list"), per_page_quantity) + '&sort=%s&' % sort + \
                   '&'.join(
                       ['='.join((key, str(search_arguments.get(key)))) for key in sorted(search_arguments.keys())])
        paging = Paging(
            page_url, ReportSubjectStatisticsMiddle, current_page=to_page_num, items_per_page=per_page_quantity,
            pipeline_stages=[match_region, query_stage, group_stage, final_project], sort=sort_list)
        await paging.pager()

        return locals()
Ejemplo n.º 30
0
    async def get(self):
        pipelines = list()
        #  展示当前用户可看的竞赛活动
        user = self.current_user
        #  隐藏了筛选条件,编辑,状态变更等按钮,不是超级管理员的情况下
        button_hide = False
        #  不是超管的情况
        if not user.superuser:
            if PERMISSION_TYPE_MINIAPP_RACE_ADD_OR_EDIT_MANAGEMENT not in user.permission_code_list:
                button_hide = True
            city_title = user.city
            #  省级账号可以看到该省和该省下面所有的市的活动
            province_title = user.province
            try:
                if province_title and not city_title:
                    province = await AdministrativeDivision.find_one({
                        'title':
                        province_title,
                        'record_flag':
                        1
                    })
                    if province:
                        #  该省下面的所有市
                        city_list = await AdministrativeDivision.find({
                            'parent_code':
                            province.code
                        }).to_list(None)
                        city_code_list = [
                            city.code for city in city_list if city_list
                        ]
                        pipelines.append(
                            MatchStage({
                                "$or": [{
                                    "city_code": {
                                        '$in': city_code_list
                                    }
                                }, {
                                    'province_code': province.code
                                }]
                            }))
                #  市级账号只能看到该市的活动
                elif city_title:
                    city = await AdministrativeDivision.find_one({
                        'title': {
                            '$regex': city_title
                        },
                        'record_flag':
                        1
                    })
                    if city:
                        pipelines.append(MatchStage({"city_code": city.code}))
            except Exception as e:
                logger.error(traceback.format_exc())
        search_keywords = self.get_argument('search_keywords', '')
        search_date = self.get_argument('search_date', '')
        sort_type = int(self.get_argument('sort_type', 1))
        search_province = self.get_argument('search_province', '')
        search_city = self.get_argument('search_city', '')

        page = int(self.get_argument('page', 1))
        per_page_quantity = int(self.get_argument('per_page_quantity', 10))

        if search_keywords:
            pipelines.append(
                MatchStage({
                    '$or': [{
                        'code': {
                            '$regex': search_keywords
                        }
                    }, {
                        'title': {
                            '$regex': search_keywords
                        }
                    }]
                }))

        if search_date:
            try:
                start_date_str, end_date_str = search_date.split(' - ')
                start_datetime = str2datetime(start_date_str)
                end_datetime = str2datetime(end_date_str)
                pipelines.append(
                    MatchStage({
                        'start_datetime': {
                            '$gte': start_datetime
                        },
                        'end_datetime': {
                            '$lte': end_datetime
                        }
                    }))
            except ValueError or TypeError:
                logger.error(traceback.format_exc())
                search_date = ''
        sort_list = []
        if sort_type:
            if int(sort_type) == 1:
                sort_list.append('-start_datetime')

            if int(sort_type) == 2:
                sort_list.append('start_datetime')

        left_pipes = [
            LookupStage(AdministrativeDivision, 'province_code', 'code',
                        'province_list'),
            LookupStage(AdministrativeDivision, 'city_code', 'code',
                        'city_list'),
        ]

        try:
            query_param = {'record_flag': 1}
            if search_province:
                query_param['province_code'] = search_province

            if search_city:
                query_param['city_code'] = search_city

            page_url = '%s?page=$page&per_page_quantity=%s&search_keywords=%s&search_date=%s&sort_type=%s&' \
                       'search_province=%s&search_city=%s' % (
                           self.reverse_url("backoffice_race_list"), per_page_quantity, search_keywords, search_date,
                           sort_type, search_province, search_city)
            paging = Paging(page_url,
                            Race,
                            current_page=page,
                            items_per_page=per_page_quantity,
                            pipeline_stages=pipelines,
                            left_pipeline_stages=left_pipes,
                            sort=sort_list,
                            **query_param)
            await paging.pager()

            city_list = None
            if search_province:
                city_list = await AdministrativeDivision.find(
                    dict(parent_code=search_province)).to_list(None)

            province_list = await AdministrativeDivision.find(
                dict(parent_code=None)).to_list(None)

            now = datetime.now()
        except Exception:
            logger.error(traceback.format_exc())
        return locals()