Ejemplo n.º 1
0
 def callback(self, bot, update):
     user = bot_models.TelegramUser.get_user(
         update.effective_message.from_user)
     basket = bot_models.Basket.get_basket_user(user)
     list_basket = basket.get_list_basket()
     if not list_basket.exists():
         update.effective_message.reply_text(
             'Корзина пуста, додайте книжку в корзинку',
             reply_markup=keyboards.main_keyboard())
         return False
     keyboards_markup = []
     text = 'Ваша корзина (сума - {} грн.): \n'.format(
         list_basket[0].basket_id.total_price)
     for index, item in enumerate(list_basket):
         text += '{}. {} - {} грн.\n'.format(index + 1, item.book_id.name,
                                             item.price)
         keyboards_markup.append(
             InlineKeyboardButton(
                 item.book_id.name,
                 callback_data=BookInfoCallback.set_callback_data(
                     id=item.book_id.id)))
     keyboards_markup = keyboards.build_menu(keyboards_markup, cols=1)
     keyboards_markup.append(keyboards.basket_button(user, basket))
     reply_markup = InlineKeyboardMarkup(keyboards_markup)
     update.effective_message.reply_text(text, reply_markup=reply_markup)
     return True
Ejemplo n.º 2
0
 def get_reply_markup(self, data, books, paginator, page):
     keyboards_markup = keyboards.build_menu([
         InlineKeyboardButton(
             book['name'],
             callback_data=BookInfoCallback.set_callback_data(
                 id=book['id'])) for book in books
     ],
                                             cols=1)
     paginator_data = {'id': data['id']}
     keyboards_markup.append(
         keyboards.build_paginator(paginator, page, CatalogsCallback,
                                   paginator_data))
     return InlineKeyboardMarkup(keyboards_markup, resize_keyboard=True)
Ejemplo n.º 3
0
 def get_reply_markup(cls, books, paginator, page):
     keyboards_markup = keyboards.build_menu([
         InlineKeyboardButton(
             book['name'],
             callback_data=BookInfoCallback.set_callback_data(
                 id=book['id'])) for book in books.values('id', 'name')
     ],
                                             cols=1)
     paginator_data = {}
     keyboards_markup.append(
         keyboards.build_paginator(paginator, page, UserBooksCallback,
                                   paginator_data))
     return InlineKeyboardMarkup(keyboards_markup, resize_keyboard=True)
Ejemplo n.º 4
0
 def callback(self, bot, update):
     top_books = bot_models.Book.get_new_books(limit=6)
     if not top_books.exists():
         update.effective_message.reply_text(
             'Нажаль немає нових книг.',
             reply_markup=keyboards.main_keyboard())
         return False
     keyboards_markup = [
         InlineKeyboardButton(
             book['name'],
             callback_data=BookInfoCallback.set_callback_data(
                 id=book['id'])) for book in top_books.values('id', 'name')
     ]
     reply_markup = InlineKeyboardMarkup(
         keyboards.build_menu(keyboards_markup))
     update.effective_message.reply_text('Виберіть цікаву вам книжку.',
                                         reply_markup=reply_markup)
     return True
Ejemplo n.º 5
0
 def callback(self, bot, update):
     catalogs = bot_models.TypeBook.objects.exclude(hidden=True)
     if not catalogs.exists():
         update.effective_message.reply_text(
             'Нажаль немає каталогів',
             reply_markup=keyboards.main_keyboard())
         return False
     keyboards_markup = [
         InlineKeyboardButton(
             catalog['name'],
             callback_data=CatalogsCallback.set_callback_data(
                 id=catalog['id']))
         for catalog in catalogs.values('id', 'name')
     ]
     reply_markup = InlineKeyboardMarkup(
         keyboards.build_menu(keyboards_markup))
     update.effective_message.reply_text('Виберіть цікавий вам каталог.',
                                         reply_markup=reply_markup)
     return True
Ejemplo n.º 6
0
 def callback(self, bot, update):
     query = update.callback_query
     user = bot_models.TelegramUser.get_user(query.from_user)
     data = self.get_callback_data(query.data)
     book = bot_models.Book.objects.get(id=data.get('id'))
     button = keyboards.get_button_by_user(book, user)
     keyboards_markup = [
         InlineKeyboardButton('Переглянути інформацію',
                              callback_data='show_data',
                              url=generate_book_link(book.id)),
         InlineKeyboardButton(
             '❤️ {}'.format(book.get_likes()),
             callback_data=BookLikeCallback.set_callback_data(id=book.id)),
         button,
     ]
     reply_markup = InlineKeyboardMarkup(
         keyboards.build_menu(keyboards_markup))
     query.edit_message_text(text="Інформація про книжку: \n{}".format(
         book.show_details()),
                             reply_markup=reply_markup)
     return True