Exemplo n.º 1
0
def filter_sales(update, context):
    if 'filter' not in context.user_data:
        context.user_data['filter'] = {
            'raw': {},
            'display': {},
        }
    button_list = [
        InlineKeyboardButton(text="По марке/модели автомобиля",
                             callback_data=f'{Options.BRAND.value}'),
        # InlineKeyboardButton(text="По радиусу поиска объявления", callback_data=f'{Options.DISTANCE.value}'),
        # InlineKeyboardButton(text="По цене автомобиля", callback_data=f'{Options.PRICE.value}'),
        InlineKeyboardButton(text="Отмена",
                             callback_data=f'{Options.CANCEL.value}'),
    ]
    if update.message:
        reply_markup = InlineKeyboardMarkup(build_menu(button_list, n_cols=1),
                                            one_time_keyboard=True)
        update.message.reply_text(text="Выберите фильтр",
                                  reply_markup=reply_markup)
    else:
        button_list.append(
            InlineKeyboardButton(
                text="Готово", callback_data=f'{Options.FINISH_FILTER.value}'))
        reply_markup = InlineKeyboardMarkup(build_menu(button_list, n_cols=1),
                                            one_time_keyboard=True)
        filter_text = get_filter_display(
            context.user_data['filter']['display'])
        update.callback_query.edit_message_text(
            text=
            f"Текущий фильтр:\n{filter_text}\n\nПродолжите настройку фильтра, либо закончите нажав Финиш"
        )
        update.callback_query.edit_message_reply_markup(
            reply_markup=reply_markup)

    return Options.PROCESS_FILTER_SELECT.value
Exemplo n.º 2
0
def filter_by_model(update, context):
    logger.info('by model')
    callback_data = get_callback_data(update, t=str)
    if callback_data:
        context.user_data['filter']['raw']['brand_id'] = callback_data.split(
            ':')[0]
        context.user_data['filter']['display']['Марка'] = get_brand_display(
            callback_data)
        models = R.hgetall(callback_data).items()
        models = sorted(models, key=lambda item: item[1])
        button_list = [
            InlineKeyboardButton(text=model.decode('utf-8'),
                                 callback_data=f'{model_id.decode("utf-8")}')
            for model_id, model in models
        ]
        button_list.append(
            InlineKeyboardButton(text='Любая',
                                 callback_data=str(Options.ANY_MODEL.value)))
        button_list.append(
            InlineKeyboardButton(text="Отмена",
                                 callback_data=f'{Options.CANCEL.value}'))
        reply_markup = InlineKeyboardMarkup(build_menu(button_list, n_cols=1),
                                            one_time_keyboard=True)
        update.callback_query.edit_message_text(
            text=f"Выберите модель {get_brand_display(callback_data)}")
        update.callback_query.edit_message_reply_markup(
            reply_markup=reply_markup)
        return Options.MODEL_SELECTED.value
Exemplo n.º 3
0
def process_distance_filter(update, context):
    cities = R.hgetall('1:cities').items()
    cities = sorted(cities, key=lambda item: item[1])
    button_list = [
        KeyboardButton(text=name.decode('utf-8')) for _, name in cities
    ]
    reply_markup = ReplyKeyboardMarkup(build_menu(button_list, n_cols=1),
                                       one_time_keyboard=True)
    context.bot.send_message(update.effective_chat.id,
                             'Выберите ваш город',
                             reply_markup=reply_markup)
Exemplo n.º 4
0
def process_brand_filter(update, context):
    brands = R.hgetall('brands').items()
    brands = sorted(brands, key=lambda item: item[1])
    button_list = [
        InlineKeyboardButton(
            text=brand.decode('utf-8'),
            callback_data=f'{brand_id.decode("utf-8")}:models')
        for brand_id, brand in brands
    ]
    button_list.append(
        InlineKeyboardButton(text="Отмена",
                             callback_data=f'{Options.CANCEL.value}'))
    reply_markup = InlineKeyboardMarkup(build_menu(button_list, n_cols=1),
                                        one_time_keyboard=True)
    update.callback_query.edit_message_text(text="Выберите брэнд")
    update.callback_query.edit_message_reply_markup(reply_markup=reply_markup)
Exemplo n.º 5
0
def model_selected(update, context):
    model_id = get_callback_data(update)
    if model_id and model_id != Options.ANY_MODEL.value:
        context.user_data['filter']['raw']['model_id'] = model_id
        model_display = get_model_display(
            context.user_data['filter']['raw']['brand_id'], model_id)
    else:
        model_display = 'Любая'
    context.user_data['filter']['display']['Модель'] = model_display
    button_list = [
        InlineKeyboardButton(text='Далее', callback_data='next'),
    ]
    reply_markup = InlineKeyboardMarkup(build_menu(button_list, n_cols=1),
                                        one_time_keyboard=True)
    update.callback_query.edit_message_text(
        text=f"Вы выбрали модель: {model_display}")
    update.callback_query.edit_message_reply_markup(reply_markup=reply_markup)
    return Options.SELECT_FILTER.value