Browse Source

Фото для чека в заказах

Добавилось возможность показывать нескольких фотографий за раз
pull/3/head
Alexei 2 years ago
parent
commit
dbb12983fb
  1. 2
      bot_modules/buttons.py
  2. 2
      bot_modules/comments.py
  3. 2
      bot_modules/groups.py
  4. 2
      bot_modules/languages.py
  5. 2
      bot_modules/messages.py
  6. 1
      bot_modules/mod_simple_message.py
  7. 24
      bot_modules/mod_table_operate.py
  8. 2
      bot_modules/needs.py
  9. 9
      bot_modules/orders.py
  10. 2
      bot_modules/projects.py
  11. 2
      bot_modules/tasks.py
  12. 2
      bot_modules/users.py
  13. 24
      bot_sys/aiogram_bot.py
  14. 3
      bot_sys/bd_table.py

2
bot_modules/buttons.py

@ -27,7 +27,7 @@ table = bd_table.Table(table_name, [
bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT),
table_name_field,
bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO),
bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR),
bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR),
table_parent_id_field,

2
bot_modules/comments.py

@ -23,7 +23,7 @@ table = bd_table.Table(table_name, [
bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT),
bd_table.TableField(name_field, bd_table.TableFieldDestiny.NAME, bd_table.TableFieldType.STR),
bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO),
bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR),
bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR),
bd_table.TableField(parent_id_field, bd_table.TableFieldDestiny.PARENT_ID, bd_table.TableFieldType.INT),

2
bot_modules/groups.py

@ -25,7 +25,7 @@ table = bd_table.Table(table_name, [
bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT),
table_name_field,
bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO),
bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR),
bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR),
],

2
bot_modules/languages.py

@ -25,7 +25,7 @@ table = bd_table.Table(table_name, [
bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT),
table_name_field,
bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO),
bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR),
bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR),
],

2
bot_modules/messages.py

@ -27,7 +27,7 @@ table = bd_table.Table(table_name, [
bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT),
table_name_field,
bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO),
bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR),
bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR),
table_parent_id_field,

1
bot_modules/mod_simple_message.py

@ -72,6 +72,7 @@ class SimpleMessageModule(mod_interface.IModule):
assert len(a_ButtonDesc) < 41 # Телеграм не поддерживает больше
assert a_ButtonDesc[0] != ' ' # Телеграм не поддерживает пробелы в начале
assert a_ButtonDesc[-1:] != ' ' # Телеграм не поддерживает пробелы в конце
# TODO добавить проверку, что все кнопки (a_ButtonDesc) разные
btn = self.m_BotButtons.CreateMessage(f'{self.GetName()} {str(a_ButtonName).replace("ButtonNames.", "")}', a_ButtonDesc, self.m_Log.GetTimeNow())
return btn

24
bot_modules/mod_table_operate.py

@ -131,15 +131,9 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
def GetEditKeyboardButtons(self, a_Message, a_UserGroups):
mod_buttons = keyboard.MakeButtons(self.m_Bot, self.GetButtons(self.m_EditModuleNameList), a_UserGroups)
cur_buttons = [
keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.PHOTO)), user_access.AccessMode.VIEW, self.GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.NAME)), user_access.AccessMode.ADD, self.GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.DESC)), user_access.AccessMode.DELETE, self.GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.ACCESS)), user_access.AccessMode.DELETE, self.GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.DEFAULT_ACCESS)), user_access.AccessMode.EDIT, self.GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.ADDRESS)), user_access.AccessMode.EDIT, self.GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.STATUS)), user_access.AccessMode.EDIT, self.GetAccess()),
]
cur_buttons = []
for f in self.m_Table.GetFields():
cur_buttons += [keyboard.ButtonWithAccess(self.GetButton(EditButton(f.m_Destiny)), user_access.AccessMode.EDIT, self.GetAccess()),]
return mod_buttons + keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups)
def GetViewItemInlineKeyboardTemplate(self, a_ItemID):
@ -173,18 +167,20 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
def UpdateMessage(self, a_Msg, a_Lang, a_Item):
a_Msg.UpdateDesc(self.m_Table.ReplaceAllFieldTags(a_Msg.GetDesc(), a_Item))
photo_field = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PHOTO)
if photo_field:
a_Msg.UpdatePhotoID(a_Item[photo_field])
photos = []
field_id = 0
for f in self.m_Table.GetFields():
if f.m_Type == bd_table.TableFieldType.ENUM:
for s in f.m_Enum:
msg = self.GetMessage(EnumMessageForView(s))
if msg:
a_Msg.UpdateDesc(a_Msg.GetDesc().replace(str(s), str(msg.GetMessageForLang(a_Lang).StaticCopy())))
elif f.m_Type == bd_table.TableFieldType.PHOTO:
photos += [str(a_Item[field_id])]
field_id += 1
a_Msg.UpdatePhotoID(','.join(photos))
return a_Msg
def ShowMessageTemplate(self, a_Message, Inline_keyboard_template_func = None):
async def ShowMessage(a_CallbackQuery, a_Item):
msg = a_Message.StaticCopy()
@ -307,7 +303,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
a_FieldName = a_Field.m_Name
a_FieldType = bd_item.FieldType.text
if a_Field.m_Destiny == bd_table.TableFieldDestiny.PHOTO:
if a_Field.m_Type == bd_table.TableFieldType.PHOTO:
a_FieldType = bd_item.FieldType.photo
if not a_ButtonName or not a_EditMessage:

2
bot_modules/needs.py

@ -23,7 +23,7 @@ table = bd_table.Table(table_name, [
bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT),
bd_table.TableField(name_field, bd_table.TableFieldDestiny.NAME, bd_table.TableFieldType.STR),
bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO),
bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR),
bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR),
bd_table.TableField(parent_id_field, bd_table.TableFieldDestiny.PARENT_ID, bd_table.TableFieldType.INT),

9
bot_modules/orders.py

@ -25,6 +25,7 @@ key_name = 'orderID'
name_field = 'orderName'
desc_field = 'orderDesc'
photo_field = 'orderPhoto'
photo_pay_field = 'orderPhotoPay'
status_field = 'orderStatus'
address_field = 'orderAddress'
access_field = 'orderAccess'
@ -35,7 +36,8 @@ table = bd_table.Table(table_name, [
bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT),
bd_table.TableField(name_field, bd_table.TableFieldDestiny.NAME, bd_table.TableFieldType.STR),
bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO),
bd_table.TableField(photo_pay_field, bd_table.TableFieldDestiny.PHOTO_PAY, bd_table.TableFieldType.PHOTO),
bd_table.TableField(status_field, bd_table.TableFieldDestiny.STATUS, bd_table.TableFieldType.ENUM, a_Enum = OrderStatus),
bd_table.TableField(address_field, bd_table.TableFieldDestiny.ADDRESS, bd_table.TableFieldType.STR),
bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR),
@ -57,6 +59,7 @@ button_names = {
ButtonNames.LIST_CURRENT: "📃 Список моих текущих заказов",
mod_table_operate.ButtonNames.ADD: "✅ Добавить заказ",
mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать мой заказ",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO_PAY): "☐ Загрузить фото оплаты моего заказа",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение в моём заказе",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название в моём заказе",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание в моём заказе",
@ -110,6 +113,9 @@ messages = {
mod_table_operate.Messages.SELECT_TO_EDIT: '''
Выберите заказ, который вы хотите отредактировать.
''',
mod_table_operate.EditMessage(bd_table.TableFieldDestiny.PHOTO_PAY): '''
Загрузите чек по оплате заказа (фото):
''',
mod_table_operate.EditMessage(bd_table.TableFieldDestiny.PHOTO): '''
Загрузите новую обложку для заказа (Фото):
Она будет отображаться в его описании.
@ -200,6 +206,7 @@ class ModuleOrders(mod_table_operate.TableOperateModule):
a_ItemData[parent_id_field] = a_UserID
a_ItemData[status_field] = str(OrderStatus.NEW)
a_ItemData[address_field] = ''
a_ItemData[photo_pay_field] = '0'
return super().AddBDItemFunc(a_ItemData, a_UserID)
def GetStartKeyboardButtons(self, a_Message, a_UserGroups):

2
bot_modules/projects.py

@ -22,7 +22,7 @@ table = bd_table.Table(table_name, [
bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT),
bd_table.TableField(name_field, bd_table.TableFieldDestiny.NAME, bd_table.TableFieldType.STR),
bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO),
bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR),
bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR),
])

2
bot_modules/tasks.py

@ -23,7 +23,7 @@ table = bd_table.Table(table_name, [
bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT),
bd_table.TableField(name_field, bd_table.TableFieldDestiny.NAME, bd_table.TableFieldType.STR),
bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO),
bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR),
bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR),
bd_table.TableField(parent_id_field, bd_table.TableFieldDestiny.PARENT_ID, bd_table.TableFieldType.INT),

2
bot_modules/users.py

@ -29,7 +29,7 @@ table = bd_table.Table(table_name, [
bd_table.TableField(name2_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR),
bd_table.TableField(is_bot_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR),
bd_table.TableField(language_code_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO),
bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR),
bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR),
])

24
bot_sys/aiogram_bot.py

@ -9,6 +9,16 @@ from aiogram.dispatcher import Dispatcher
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.utils import executor
def GetPhotoList(a_PhotoIDs):
if not a_PhotoIDs or a_PhotoIDs == 0:
return []
photos = a_PhotoIDs.split(",")
result = []
for p in photos:
if p != '0' and p != '':
result += [p]
return result
class AiogramBot(interfaces.IBot):
def __init__(self, a_TelegramBotApiToken, a_BDFileName, a_RootIDs, a_Log):
self.m_TelegramBotApiToken = a_TelegramBotApiToken
@ -39,19 +49,27 @@ class AiogramBot(interfaces.IBot):
base_keyboards = [keyboard.MakeAiogramKeyboard(a_KeyboardButtons)]
if inline_keyboards:
base_keyboards = inline_keyboards
if a_PhotoIDs and a_PhotoIDs != 0 and a_PhotoIDs != '0':
photos = GetPhotoList(a_PhotoIDs)
if len(photos) > 0:
for p in photos[:-1]:
await self.m_TBot.send_photo(
a_UserID,
p,
''
)
p = photos[-1]
if base_keyboards:
for k in base_keyboards:
await self.m_TBot.send_photo(
a_UserID,
a_PhotoIDs,
p,
a_Message,
reply_markup = k
)
else:
await self.m_TBot.send_photo(
a_UserID,
a_PhotoIDs,
p,
a_Message
)
else:

3
bot_sys/bd_table.py

@ -9,12 +9,14 @@ class TableFieldType(Enum):
INT = auto()
STR = auto()
ENUM = auto()
PHOTO = auto()
def InitTableType(a_TableFieldType):
types = {
TableFieldType.INT: 'INTEGER',
TableFieldType.STR: 'TEXT',
TableFieldType.ENUM: 'TEXT',
TableFieldType.PHOTO: 'TEXT',
}
return types.get(a_TableFieldType, None)
@ -24,6 +26,7 @@ class TableFieldDestiny(Enum):
NAME = auto()
DESC = auto()
PHOTO = auto()
PHOTO_PAY = auto()
ACCESS = auto()
DEFAULT_ACCESS = auto()
CREATE_DATE = auto()

Loading…
Cancel
Save