示例#1
0
 def delete_user_tariffs(self, data, session, curs=None):
     f = UserTariffFilter(session, {
         'user_id': data['user_id'],
         'tariff_ids': data['tariff_ids']
     }, {}, ['id'])
     mapping.delete_objects(curs, f.filter_objs(curs, for_update=True))
     return response_ok()
示例#2
0
    def get_user_tariffs(self, data, session, curs=None):
        ut_f = UserTariffFilter(session, data['filter_params'],
            data['paging_params'], data.get('ordering_params'))
        uts = ut_f.filter_objs(curs)

        uts_data = {}
        for ut in uts:
            if ut.user_id not in uts_data:
                uts_data[ut.user_id] = []
            uts_data[ut.user_id].append(ut.tariff_id)
        uts_info = [{'user_id': k, 'tariff_ids': v} for k, v in uts_data.items()]
        uts_info.sort(key=lambda x: x['user_id'])
        return response_ok(user_tariffs=uts_info, total=len(uts_info))
示例#3
0
    def get_user_tariffs(self, data, session, curs=None):
        ut_f = UserTariffFilter(session, data['filter_params'],
                                data['paging_params'],
                                data.get('ordering_params'))
        uts = ut_f.filter_objs(curs)

        uts_data = {}
        for ut in uts:
            if ut.user_id not in uts_data:
                uts_data[ut.user_id] = []
            uts_data[ut.user_id].append(ut.tariff_id)
        uts_info = [{
            'user_id': k,
            'tariff_ids': v
        } for k, v in uts_data.items()]
        uts_info.sort(key=lambda x: x['user_id'])
        return response_ok(user_tariffs=uts_info, total=len(uts_info))
示例#4
0
    def get_tariffs_prices(self, data, session, curs=None):
        f_params = data['filter_params']
        if 'user_id' in f_params:
            user_id = f_params['user_id']
            ts_ids = f_params['ids']
            ut_f = UserTariffFilter(session, {
                'user_id': user_id,
                'tariff_ids': ts_ids
            }, {}, None)
            uts = ut_f.filter_objs(curs)
            uts_tariff_ids = [ut.tariff_id for ut in uts]
            ts_ids = filter(lambda x: x in uts_tariff_ids, ts_ids)
            f_params['ids'] = ts_ids

        t_f = TariffFilter(session, data['filter_params'],
                           data['paging_params'], data.get('ordering_params'))
        ts, total = t_f.filter_counted(curs)
        ts_idx = build_index(ts)
        ts_ids = filter(lambda x: x in ts_idx, data['filter_params']['ids'])

        all_tos_f = TarifficationObjectFilter(session, {}, {}, None)
        all_tos = all_tos_f.filter_objs(curs)
        all_tos_idx = build_index(all_tos)

        all_ts_f = TariffFilter(session, {}, {}, None)
        all_ts = all_ts_f.filter_objs(curs)
        all_ts_idx = build_index(all_ts)

        active_r_f = RuleFilter(session, {}, {}, None)
        active_rs = active_r_f.filter_objs(curs)
        active_rs_to_t_idx = build_complex_index(
            active_rs, ('tariffication_object_id', 'tariff_id'))

        tariffs_prices = []
        calculation_ctxs = data['calculation_contexts']
        for t_id in ts_ids:
            tariff_price_info = self._tariff_price_info(
                session, curs, ts_idx[t_id], all_tos_idx, all_ts_idx,
                active_rs_to_t_idx, calculation_ctxs)
            tariffs_prices.append(tariff_price_info)

        return response_ok(tariffs=tariffs_prices, total=total)
示例#5
0
    def get_tariffs_prices(self, data, session, curs=None):
        f_params = data['filter_params']
        if 'user_id' in f_params:
            user_id = f_params['user_id']
            ts_ids = f_params['ids']
            ut_f = UserTariffFilter(session, {'user_id': user_id,
                'tariff_ids': ts_ids}, {}, None)
            uts = ut_f.filter_objs(curs)
            uts_tariff_ids = [ut.tariff_id for ut in uts]
            ts_ids = filter(lambda x: x in uts_tariff_ids, ts_ids)
            f_params['ids'] = ts_ids


        t_f = TariffFilter(session, data['filter_params'],
            data['paging_params'], data.get('ordering_params'))
        ts, total = t_f.filter_counted(curs)
        ts_idx = build_index(ts)
        ts_ids = filter(lambda x: x in ts_idx, data['filter_params']['ids'])

        all_tos_f = TarifficationObjectFilter(session, {}, {}, None)
        all_tos = all_tos_f.filter_objs(curs)
        all_tos_idx = build_index(all_tos)

        all_ts_f = TariffFilter(session, {}, {}, None)
        all_ts = all_ts_f.filter_objs(curs)
        all_ts_idx = build_index(all_ts)

        active_r_f = RuleFilter(session, {}, {}, None)
        active_rs = active_r_f.filter_objs(curs)
        active_rs_to_t_idx = build_complex_index(active_rs,
            ('tariffication_object_id', 'tariff_id'))

        tariffs_prices = []
        calculation_ctxs = data['calculation_contexts']
        for t_id in ts_ids:
            tariff_price_info = self._tariff_price_info(session, curs, ts_idx[t_id],
                all_tos_idx, all_ts_idx, active_rs_to_t_idx, calculation_ctxs)
            tariffs_prices.append(tariff_price_info)

        return response_ok(tariffs=tariffs_prices, total=total)
示例#6
0
 def delete_user_tariffs(self, data, session, curs=None):
     f = UserTariffFilter(session, {'user_id': data['user_id'],
         'tariff_ids': data['tariff_ids']}, {}, ['id'])
     mapping.delete_objects(curs, f.filter_objs(curs, for_update=True))
     return response_ok()