173 строки
3.7 KiB
Python
173 строки
3.7 KiB
Python
import database
|
|
from models import date, ReplyKeyboardMarkup, KeyboardButton, Category, FreeToOrder, Order, Issue
|
|
|
|
|
|
def start():
|
|
return ReplyKeyboardMarkup([
|
|
[
|
|
KeyboardButton('Записаться'),
|
|
],
|
|
[
|
|
KeyboardButton('Мои обращения'),
|
|
],
|
|
])
|
|
|
|
|
|
async def categories():
|
|
keyboard = ReplyKeyboardMarkup()
|
|
for category in await database.read_categories():
|
|
keyboard.add(
|
|
KeyboardButton(category.name),
|
|
)
|
|
keyboard.add(
|
|
KeyboardButton('Назад'),
|
|
)
|
|
return keyboard
|
|
|
|
|
|
async def subcategories(category: Category):
|
|
keyboard = ReplyKeyboardMarkup()
|
|
for subcategory in await database.read_subcategories(category):
|
|
keyboard.add(
|
|
KeyboardButton(subcategory.name),
|
|
)
|
|
keyboard.add(
|
|
KeyboardButton('Назад'),
|
|
)
|
|
return keyboard
|
|
|
|
|
|
def dates(free_to_order: tuple[FreeToOrder]):
|
|
_dates = tuple(
|
|
sorted(
|
|
set(
|
|
item.date
|
|
for item in free_to_order
|
|
)
|
|
)
|
|
)
|
|
keyboard = ReplyKeyboardMarkup()
|
|
for _date in _dates:
|
|
keyboard.insert(_date.strftime('%d.%m'))
|
|
keyboard.add(
|
|
KeyboardButton('Назад'),
|
|
)
|
|
return keyboard
|
|
|
|
|
|
def time_ranges(free_to_order: tuple[FreeToOrder], _date: date):
|
|
_time_ranges = tuple(
|
|
sorted(
|
|
set(
|
|
item.time_range
|
|
for item in free_to_order
|
|
if item.date == _date
|
|
),
|
|
key=lambda x: x.id,
|
|
)
|
|
)
|
|
keyboard = ReplyKeyboardMarkup()
|
|
for time_range in _time_ranges:
|
|
keyboard.insert('%s - %s' % (
|
|
time_range.start_time.strftime('%H:%M'),
|
|
time_range.end_time.strftime('%H:%M'),
|
|
))
|
|
keyboard.add(
|
|
KeyboardButton('Назад'),
|
|
)
|
|
return keyboard
|
|
|
|
|
|
def back():
|
|
return ReplyKeyboardMarkup(
|
|
keyboard=[
|
|
[
|
|
KeyboardButton('Назад'),
|
|
],
|
|
],
|
|
)
|
|
|
|
|
|
def order_confirmation():
|
|
return ReplyKeyboardMarkup(
|
|
keyboard=[
|
|
[
|
|
KeyboardButton('Подтвердить'),
|
|
],
|
|
[
|
|
KeyboardButton('Назад'),
|
|
],
|
|
],
|
|
)
|
|
|
|
|
|
def main_menu():
|
|
return ReplyKeyboardMarkup(
|
|
keyboard=[
|
|
[
|
|
KeyboardButton('Главное меню'),
|
|
],
|
|
],
|
|
)
|
|
|
|
|
|
def orders(_orders: tuple[Order]):
|
|
keyboard = ReplyKeyboardMarkup()
|
|
for order in _orders:
|
|
keyboard.insert(
|
|
KeyboardButton('№%d' % order.id),
|
|
)
|
|
keyboard.add(
|
|
KeyboardButton('Назад'),
|
|
)
|
|
return keyboard
|
|
|
|
|
|
def operations():
|
|
return ReplyKeyboardMarkup(
|
|
keyboard=[
|
|
[
|
|
# KeyboardButton('Перенести'),
|
|
KeyboardButton('Отменить'),
|
|
],
|
|
[
|
|
KeyboardButton('Назад'),
|
|
],
|
|
],
|
|
)
|
|
|
|
|
|
def cancel_order():
|
|
return ReplyKeyboardMarkup(
|
|
keyboard=[
|
|
[
|
|
KeyboardButton('Отменить заказ'),
|
|
],
|
|
[
|
|
KeyboardButton('Назад'),
|
|
],
|
|
],
|
|
)
|
|
|
|
|
|
def my_orders():
|
|
return ReplyKeyboardMarkup(
|
|
keyboard=[
|
|
[
|
|
KeyboardButton('Мои обращения'),
|
|
],
|
|
],
|
|
)
|
|
|
|
|
|
def issues(_issues: tuple[Issue]):
|
|
keyboard = ReplyKeyboardMarkup()
|
|
for issue in _issues:
|
|
keyboard.insert(
|
|
KeyboardButton('%s' % issue.key),
|
|
)
|
|
keyboard.add(
|
|
KeyboardButton('Назад'),
|
|
)
|
|
return keyboard
|