Example #1
0
def inline_button_handler(bot: Bot, update: Update):
    callback_data = update.callback_query.data
    if callback_data == 'ru_':
        return functions.set_ru(bot, update)
    if callback_data == 'uz_':
        return functions.set_uz(bot, update)
    if callback_data == 'first_name':
        return functions.get_first_name(bot, update)
    if callback_data == 'last_name':
        return functions.get_last_name(bot, update)
    if callback_data == 'middle_name':
        return functions.get_middle_name(bot, update)
    if callback_data == 'back_to_main':
        return functions.main_menu(bot, update, edit=True)
    if callback_data == 'back_to_request':
        return functions.request_menu(bot, update, edit=True)
    if callback_data == 'region':
        return functions.get_region(bot, update)
    if callback_data == 'address':
        return functions.get_address(bot, update)
    if callback_data == 'organization':
        return functions.get_org(bot, update)
    if callback_data == 'application_type':
        return functions.get_application_type(bot, update)
    if callback_data == 'application_text':
        return functions.get_application_text(bot, update)
    if callback_data == 'correct':
        return functions.save_user(bot, update)
    if callback_data == 'back_to_application_menu':
        return functions.user_application_menu(bot, update)
    if callback_data == 'save_application':
        return functions.save_application(bot, update)
    if callback_data == 'cancel':
        return functions.cancel_application(bot, update)

    menu = {
        'start_request': functions.request_menu,
        'uz': functions.set_uz,
        'ru': functions.set_ru,
        'correct': functions.save_user,
        'cancel': functions.cancel,
        'set_first_name': functions.get_first_name,
        'set_last_name': functions.get_last_name,
        'set_middle_name': functions.get_middle_name,
        'set_region': functions.get_region,
        'set_district': functions.get_district,
        'set_gathering': functions.get_gathering,
        'set_address': functions.get_address,
        'set_org': functions.get_org,
        'set_application_type': functions.get_application_type,
        'set_application_text': functions.get_application_text,
    }

    state = 0
    for item in menu:
        if callback_data.find(item) != -1:
            data = callback_data.split(item)[1]
            state = menu[item](bot, update, data)

    return state
Example #2
0
def set_org(bot: Bot, update: Update):
    user_model = apps.get_model('main', 'TelegramProfile')
    user = user_model.objects.get(external_id=update.effective_chat.id)
    callback_data = update.callback_query.data
    err_text = "Siz allaqachon ushbu tashkilotga murojaat yo'llagansiz. " \
               "Sizning murojaatingiz ko'rib chiqilmoqda. " \
               "Iltimos, avval jo'natgan murojaatingiz statusi yakunlashini kuting." if user.lang == 'uz' \
        else 'Вы уже подали заявку в эту организацию. ' \
             'Ваше обращение находится на рассмотрении. ' \
             'Пожалуйста, дождитесь завершения статуса заявки, которую вы отправили ранее.'
    if callback_data == 'back_to_application_menu':
        return functions.user_application_menu(bot, update, edit=True)
    organization = Organization.objects.get(callback_data=callback_data)
    if UserApplication.objects.filter(
            user_profile__telegram_id__external_id=update.effective_chat.id,
            organization=organization,
            status=1).exists():
        bot.send_message(chat_id=update.effective_chat.id, text=err_text)
        bot.delete_message(chat_id=update.effective_chat.id,
                           message_id=update.callback_query.message.message_id)
        return functions.get_org(bot, update, edit=False)
    request = cache.get(f'application_{update.effective_chat.id}')
    request['organization'] = organization
    cache.set(f'application_{update.effective_chat.id}', request)
    cache.set(f'application_auto_{update.effective_chat.id}', True)
    return functions.get_application_type(bot, update, edit=True)
def set_application_type(bot: Bot, update: Update):
    callback_data = update.callback_query.data
    if callback_data == 'back_to_application_menu':
        return functions.user_application_menu(bot, update, edit=True)
    application_type = ActivityType.objects.get(callback_data=callback_data)
    request = cache.get(f'application_{update.effective_chat.id}')
    request['application_type'] = application_type
    cache.set(f'application_{update.effective_chat.id}', request)
    cache.set(f'application_auto_{update.effective_chat.id}', True)
    return functions.get_application_text(bot, update)
def set_application_text(bot: Bot, update: Update):
    user_model = apps.get_model('main', 'TelegramProfile')
    user = user_model.objects.get(external_id=update.effective_chat.id)
    application_text = update.message.text
    request = cache.get(f'application_{update.effective_chat.id}')
    request['application_text'] = application_text
    cache.set(f'application_{update.effective_chat.id}', request)

    if user.lang == 'uz':
        text = 'Saqlandi'
    else:
        text = 'Сохранено'

    bot.send_message(chat_id=update.effective_chat.id,
                     text=text,
                     reply_markup=ReplyKeyboardRemove())
    cache.set(f'application_auto_{update.effective_chat.id}', True)

    return functions.user_application_menu(bot, update, edit=False)
def go_to_application_menu(bot: Bot, update: Update):
    return functions.user_application_menu(bot, update, data=None, edit=False)