def _show_requests(self, event, custom_data=None): if custom_data: user = custom_data.get('user', None) page = custom_data.get('page', 0) stp_filter = custom_data.get('stp', None) else: stp_filter = None user = event.kwargs.get('user') page = 0 stp = Stp.get(Stp.user == user) stp_sections = StpSection.select(StpSection.section).where(StpSection.stp == stp).where( Request.is_finished == False) requests = Request.select().where(Request.section << stp_sections) if stp_filter: requests = requests.where(Request.stp == stp_filter) else: requests = requests.where(Request.stp == None) requests = requests.offset(page * REQUEST_PAGE_SIZE).limit( REQUEST_PAGE_SIZE + 1) if not custom_data: self.tb.send_message(self.chat, "Заявки:", reply_markup=generate_custom_keyboard(types.ReplyKeyboardMarkup, [[get_button( "В главное меню")]])) req_len = len(requests) if req_len: for i in range(req_len): buttons = self.get_request_control_buttons(stp, requests[i].id) if req_len == REQUEST_PAGE_SIZE + 1 and req_len == i + 1: buttons.append([get_button_inline(text="Показать еще", data="stp_request_show %s" % (page + 1))]) self.print_request(requests[i], stp=stp, keyboard=generate_custom_keyboard(types.InlineKeyboardMarkup, buttons)) else: self.tb.send_message(self.chat, "Нету доступных заявок.")
def show_requests(self, user_id): requests = Request.select().where(Request.user == user_id).where(Request.is_finished == False) keyboard = generate_custom_keyboard(types.ReplyKeyboardMarkup, [['В главное меню']]) self.tb.send_message(self.chat, "Список заявок:", reply_markup=keyboard) if not requests: self.tb.send_message(self.chat, "Нету активных заявок.") for request in requests: self.print_request(request)
def show_request(self, request_id, curr_user, reply=None): try: r = Request.get(id=request_id) buttons = [] stp = Stp.get(Stp.user == curr_user) stp_sections = StpSection.select(StpSection.section).where(StpSection.stp == stp) is_suitable = Request.select().where(Request.section == r.section).where( Request.section << stp_sections).where(Request.is_finished == False).exists() if is_suitable: buttons = self.get_request_control_buttons(stp, request_id) self.print_request(r, keyboard=generate_custom_keyboard(types.InlineKeyboardMarkup, buttons), stp=stp) except: self.tb.send_message(self.chat, "Данная заявка не найдена")