Browse Source

Новый тип поля - ENUM

Автоматически под него создаются кнопки при редактировании и конвертируются в удобоваримый формат сообщения
pull/3/head
Alexei 2 years ago
parent
commit
b665e7cfbe
  1. 35
      bot_modules/mod_table_operate.py
  2. 36
      bot_modules/orders.py
  3. 37
      bot_sys/bd_table.py
  4. 10
      template/bd_item.py
  5. 23
      template/bd_item_add.py
  6. 14
      template/bd_item_edit.py

35
bot_modules/mod_table_operate.py

@ -16,12 +16,18 @@ from enum import auto
def EditButton(a_BDTableDestiny):
return 'edit ' + str(a_BDTableDestiny)
def EnumButton(a_EnumItem):
return 'enum ' + str(a_EnumItem)
def EditMessage(a_BDTableDestiny):
return 'edit ' + str(a_BDTableDestiny)
def CreateMessage(a_BDTableDestiny):
return 'create ' + str(a_BDTableDestiny)
def EnumMessageForView(a_EnumItem):
return 'enum ' + str(a_EnumItem)
class ButtonNames(Enum):
LIST = auto()
ADD = auto()
@ -170,8 +176,15 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
photo_field = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PHOTO)
if photo_field:
a_Msg.UpdatePhotoID(a_Item[photo_field])
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())))
return a_Msg
def ShowMessageTemplate(self, a_Message, Inline_keyboard_template_func = None):
async def ShowMessage(a_CallbackQuery, a_Item):
msg = a_Message.StaticCopy()
@ -268,6 +281,26 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
return a_Prefix
def AdditionalKeyboardForEditTemplate(self, a_Field):
if a_Field.m_Type == bd_table.TableFieldType.ENUM:
def KeyboardButtons(a_Message, a_UserGroups):
cur_buttons = []
for s in a_Field.m_Enum:
cur_buttons += [keyboard.ButtonWithAccess(self.GetButton(EnumButton(s)), user_access.AccessMode.EDIT, self.GetAccess()),]
return keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups)
return KeyboardButtons
return None
def PostProccessingForFieldForEditTemplate(self, a_Field):
if a_Field.m_Type == bd_table.TableFieldType.ENUM:
def PostProccessing(a_Message):
for s in a_Field.m_Enum:
if a_Message == str(self.GetButton(EnumButton(s))):
return str(s)
return a_Message
return PostProccessing
return None
def RegisterEdit(self, a_Field, a_AccessMode = user_access.AccessMode.EDIT):
a_ButtonName = self.GetButton(EditButton(a_Field.m_Destiny))
a_EditMessage = self.GetMessage(EditMessage(a_Field.m_Destiny))
@ -300,8 +333,10 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
table_name, \
key_name, \
a_FieldName, \
self.PostProccessingForFieldForEditTemplate(a_Field),\
GetButtonNameAndKeyValueAndAccess, \
GetAccess, \
self.AdditionalKeyboardForEditTemplate(a_Field),\
edit_keyboard_func, \
OnChange,\
access_mode = a_AccessMode, \

36
bot_modules/orders.py

@ -36,7 +36,7 @@ table = bd_table.Table(table_name, [
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(status_field, bd_table.TableFieldDestiny.STATUS, bd_table.TableFieldType.STR),
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),
bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR),
@ -63,6 +63,10 @@ button_names = {
mod_table_operate.EditButton(bd_table.TableFieldDestiny.ADDRESS): "𝌴 Изменить адрес в заказе",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.STATUS): "𝌴 Изменить статус в заказе",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Изменить доступ к заказу",
mod_table_operate.EnumButton(OrderStatus.NEW): "Заказ ожидает модерации",
mod_table_operate.EnumButton(OrderStatus.PAY): "Заказ ожидает оплаты",
mod_table_operate.EnumButton(OrderStatus.ADDRESS): "Заказ ожидает уточнения адреса",
mod_table_operate.EnumButton(OrderStatus.FINISH): "Заказ выполнен",
mod_table_operate.ButtonNames.DEL: "❌ Удалить заказ",
}
@ -156,37 +160,35 @@ messages = {
}
messages_order_status = {
OrderStatus.NEW: f'''Заказ создан, ожидает модерации''',
OrderStatus.PAY: f'''Заказ ожидает оплаты''',
OrderStatus.ADDRESS: f'''Заказ ожидает указания адреса доставки''',
OrderStatus.FINISH: f'''Заказ выполнен''',
mod_table_operate.EnumMessageForView(OrderStatus.NEW): f'''Заказ создан, ожидает модерации''',
mod_table_operate.EnumMessageForView(OrderStatus.PAY): f'''Заказ ожидает оплаты''',
mod_table_operate.EnumMessageForView(OrderStatus.ADDRESS): f'''Заказ ожидает указания адреса доставки''',
mod_table_operate.EnumMessageForView(OrderStatus.FINISH): f'''Заказ выполнен''',
}
messages.update(messages_order_status)
def GetCurItemsTemplate(a_Bot, a_TableName, a_UserIDFieldName, a_StatusFieldName):
def GetBDItems(a_Message, a_UserGroups, a_ParentID):
user_id = str(a_Message.from_user.id)
request = f'SELECT * FROM {a_TableName} WHERE {a_UserIDFieldName} = ? AND {a_StatusFieldName} != ?'
print('GetCurItemsTemplate', a_TableName, a_UserIDFieldName, a_KeyValue)
return a_Bot.SQLRequest(request, param = ([a_KeyValue, OrderStatus.FINISH]))
return a_Bot.SQLRequest(request, param = ([user_id, str(OrderStatus.FINISH)]))
return GetBDItems
def GetBDItemsForUserTemplate(a_Bot, a_TableName, a_UserIDFieldName):
def GetBDItems(a_Message, a_UserGroups, a_ParentID):
user_id = str(a_Message.from_user.id)
print('user_id', a_Message, user_id)
return bd_item.GetBDItemsTemplate(a_Bot, a_TableName, a_UserIDFieldName)(user_id)
return GetBDItems
class DBItemForUserSelectSource(bd_item_select.DBItemSelectSource):
def __init__(self, a_Bot, a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_ButtonName, a_OnlyCurent = False):
def __init__(self, a_Bot, a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_ButtonName, a_OnlyCurrent = False):
super().__init__(a_Bot, a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_ButtonName)
self.m_OnlyCurent = a_OnlyCurent
self.m_OnlyCurrent = a_OnlyCurrent
def GetItemsFunc(self):
get_items_func = super().GetItemsFunc()
if self.m_OnlyCurent:
get_items_func = GetCurItemsTemplate(self.m_Bot, self.m_TableName, self.m_ParentIDFieldName, status_field)
if self.m_OnlyCurrent:
return GetCurItemsTemplate(self.m_Bot, self.m_TableName, self.m_ParentIDFieldName, status_field)
return GetBDItemsForUserTemplate(self.m_Bot, self.m_TableName, self.m_ParentIDFieldName)
def IsFirst(self):
@ -205,7 +207,7 @@ class ModuleOrders(mod_table_operate.TableOperateModule):
def SelectSourceForCurrentTemplate(self, a_PrevPrefix, a_ButtonName):
parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID)
return DBItemForUserSelectSource(self.m_Bot, self.m_Table.GetName(), parent_id_field, a_PrevPrefix, a_ButtonName, a_OnlyCurent = True)
return DBItemForUserSelectSource(self.m_Bot, self.m_Table.GetName(), parent_id_field, a_PrevPrefix, a_ButtonName, a_OnlyCurrent = True)
def AddBDItemFunc(self, a_ItemData, a_UserID):
parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID)
@ -221,12 +223,6 @@ class ModuleOrders(mod_table_operate.TableOperateModule):
]
return parent_buttons + keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups)
def UpdateMessage(self, a_Msg, a_Lang, a_Item):
a_Msg = super().UpdateMessage(a_Msg, a_Lang, a_Item)
for s in OrderStatus:
a_Msg.UpdateDesc(a_Msg.GetDesc().replace(str(s), str(self.GetMessage(s).GetMessageForLang(a_Lang).StaticCopy())))
return a_Msg
def RegisterHandlers(self):
super().RegisterHandlers()
table_name = self.m_Table.GetName()

37
bot_sys/bd_table.py

@ -8,6 +8,15 @@ from enum import auto
class TableFieldType(Enum):
INT = 'INTEGER'
STR = 'TEXT'
ENUM = 'ENUM'
def InitTableType(a_TableFieldType):
types = {
TableFieldType.INT: 'INTEGER',
TableFieldType.STR: 'TEXT',
TableFieldType.ENUM: 'TEXT',
}
return types.get(a_TableFieldType, None)
# Предназначение поля в таблице
class TableFieldDestiny(Enum):
@ -24,10 +33,11 @@ class TableFieldDestiny(Enum):
OTHER = auto()
class TableField:
def __init__(self, a_Name, a_Destiny : TableFieldDestiny, a_Type : TableFieldType):
def __init__(self, a_Name, a_Destiny : TableFieldDestiny, a_Type : TableFieldType, a_Enum = None):
self.m_Name = a_Name
self.m_Destiny = a_Destiny
self.m_Type = a_Type
self.m_Enum = a_Enum
class Table:
def __init__(self, a_TableName, a_Fields : [TableField], a_UniqueFields = None):
@ -67,7 +77,7 @@ class Table:
request = f'CREATE TABLE IF NOT EXISTS {self.GetName()}('
items = []
for f in self.m_Fields:
item = f.m_Name + ' ' + str(f.m_Type.value)
item = f.m_Name + ' ' + str(InitTableType(f.m_Type))
if f.m_Destiny == TableFieldDestiny.KEY:
item += ' PRIMARY KEY'
items += [item]
@ -86,14 +96,20 @@ class Table:
result = result.replace(f'#{f.m_Name}', str(a_BDItem[i]))
return result
class Status(Enum):
NEW = auto()
FINISH = auto()
def Test():
f1 = TableField('f1', TableFieldDestiny.KEY, TableFieldType.INT)
f2 = TableField('f2', TableFieldDestiny.NAME, TableFieldType.STR)
f3 = TableField('f3', TableFieldDestiny.DESC, TableFieldType.STR)
f4 = TableField('f4', TableFieldDestiny.STATUS, TableFieldType.ENUM, a_Enum = Status)
table = Table('tname', [
f1,
f2,
f3
f3,
f4,
],
[[f1], [f2, f3]]
)
@ -113,16 +129,21 @@ def Test():
assert table.GetFieldByDestiny(TableFieldDestiny.DESC).m_Destiny == TableFieldDestiny.DESC
assert table.GetFieldByDestiny(TableFieldDestiny.DESC).m_Type == TableFieldType.STR
assert table.GetFieldIDByDestiny(TableFieldDestiny.DESC) == 2
assert table.GetFieldByDestiny(TableFieldDestiny.STATUS).m_Name == 'f4'
assert table.GetFieldNameByDestiny(TableFieldDestiny.STATUS) == 'f4'
assert table.GetFieldByDestiny(TableFieldDestiny.STATUS).m_Destiny == TableFieldDestiny.STATUS
assert table.GetFieldByDestiny(TableFieldDestiny.STATUS).m_Type == TableFieldType.ENUM
assert table.GetFieldIDByDestiny(TableFieldDestiny.STATUS) == 3
assert table.GetFieldByDestiny(TableFieldDestiny.PHOTO) == None
assert table.GetFieldIDByDestiny(TableFieldDestiny.PHOTO) == None
assert table.GetFieldNameByDestiny(TableFieldDestiny.PHOTO) == None
assert table.GetFieldsCount() == 3
assert len(table.GetFields()) == 3
assert table.GetFieldsCount() == 4
assert len(table.GetFields()) == 4
print(table.GetInitTableRequest())
assert table.GetInitTableRequest() == 'CREATE TABLE IF NOT EXISTS tname(f1 INTEGER PRIMARY KEY, f2 TEXT, f3 TEXT, UNIQUE(f1), UNIQUE(f2, f3));'
assert table.GetInitTableRequest() == 'CREATE TABLE IF NOT EXISTS tname(f1 INTEGER PRIMARY KEY, f2 TEXT, f3 TEXT, f4 TEXT, UNIQUE(f1), UNIQUE(f2, f3));'
item = [10, 'i1', 'i2']
assert table.ReplaceAllFieldTags('#f1 #f2 #f3', item) == '10 i1 i2'
item = [10, 'i2', 'i3', 'i4']
assert table.ReplaceAllFieldTags('#f1 #f2 #f3 #f4', item) == '10 i2 i3 i4'

10
template/bd_item.py

@ -42,6 +42,16 @@ def GetKeyDataFromCallbackMessage(a_Message, a_Prefix):
key_item_id = str(a_Message.data).replace(a_Prefix, '')
return key_item_id
def MixKeyboardFuncTemplate(a_Func1, a_Func2):
def KeyboardButtons(a_Message, a_UserGroups):
func = [a_Func1, a_Func2]
result = []
for f in func:
if f:
result += f(a_Message, a_UserGroups)
return result
return KeyboardButtons
def GetCancelKeyboardButtonsTemplate(a_Bot, a_AccessFunc, a_AccessMode):
def GetCancelKeyboardButtons(a_Message, a_UserGroups):
cur_buttons = [

23
template/bd_item_add.py

@ -39,13 +39,13 @@ def StartAddBDItemTemplate(a_Bot, a_FSM, a_FSMStart, a_MessageFunc, a_ParentTabl
return res_of_work_func
return simple_message.SimpleMessageTemplate(a_Bot, StartAddBDItem, a_ButtonFunc, None, a_AccessFunc, access_mode)
def FinishAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.ADD, field_type = bd_item.FieldType.text):
return FinishOrNextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_ButtonFunc, True, access_mode = access_mode, field_type = field_type)
def FinishAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.ADD, field_type = bd_item.FieldType.text):
return FinishOrNextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, a_ButtonFunc, True, access_mode = access_mode, field_type = field_type)
def NextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = user_access.AccessMode.ADD, field_type = bd_item.FieldType.text):
return FinishOrNextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, False, access_mode = access_mode, field_type = field_type)
def NextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = user_access.AccessMode.ADD, field_type = bd_item.FieldType.text):
return FinishOrNextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, False, access_mode = access_mode, field_type = field_type)
def FinishOrNextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, a_Finish, access_mode = user_access.AccessMode.ADD, field_type = bd_item.FieldType.text):
def FinishOrNextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, a_Finish, access_mode = user_access.AccessMode.ADD, field_type = bd_item.FieldType.text):
async def FinishAddBDItem(a_Message, state):
state_func = None
if a_Finish:
@ -84,7 +84,10 @@ def FinishOrNextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableNa
return simple_message.WorkFuncResult(bot_messages.MakeBotMessage(error_photo_type_message), keyboard_func = a_FinishButtonFunc)
field_value = a_Message.photo[0].file_id
else:
field_value = a_Message.text
result = a_Message.text
if a_PostProcessFunc:
result = a_PostProcessFunc(result)
field_value = result
item_data[a_FieldName] = field_value
if a_Finish:
res, error = a_AddBDItemFunc(item_data, user_id)
@ -104,9 +107,9 @@ def AddBDItem3RegisterHandlers(a_Bot, a_StartCheckFunc, a_FSM, a_FSMName, a_FSMD
reg_func(StartAddBDItemTemplate(a_Bot, a_FSM, a_FSMName, a_AddNameMessageFunc, a_ParentTableName, a_ParentKeyFieldName, a_ParentPrefix, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode), a_StartCheckFunc)
# TODO: Сделать возможность не указывать все поля. пусть a_FSMName и a_NameField например могут быть пустыми. Возможно лучше вообще передавать список полей и их fsm
a_Bot.RegisterMessageHandler(NextAddBDItemTemplate(a_Bot, a_FSM, None, a_ParentTableName, a_ParentKeyFieldName, a_NameField, a_AddDescMessageFunc, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.text), state = a_FSMName)
a_Bot.RegisterMessageHandler(NextAddBDItemTemplate(a_Bot, a_FSM, None, a_ParentTableName, a_ParentKeyFieldName, a_DescField, a_AddPhotoMessageFunc, a_AccessFunc, keyboard_skip_and_cancel, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.text), state = a_FSMDesc)
a_Bot.RegisterMessageHandler(FinishAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_PhotoField, a_FinishMessageFunc, a_AccessFunc, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.photo), content_types = ['photo', 'text'], state = a_FSMPhoto)
a_Bot.RegisterMessageHandler(NextAddBDItemTemplate(a_Bot, a_FSM, None, a_ParentTableName, a_ParentKeyFieldName, a_NameField, a_AddDescMessageFunc, None, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.text), state = a_FSMName)
a_Bot.RegisterMessageHandler(NextAddBDItemTemplate(a_Bot, a_FSM, None, a_ParentTableName, a_ParentKeyFieldName, a_DescField, a_AddPhotoMessageFunc, None, a_AccessFunc, keyboard_skip_and_cancel, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.text), state = a_FSMDesc)
a_Bot.RegisterMessageHandler(FinishAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_PhotoField, a_FinishMessageFunc, None, a_AccessFunc, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.photo), content_types = ['photo', 'text'], state = a_FSMPhoto)
def AddBDItem1RegisterHandlers(a_Bot, a_StartCheckFunc, a_FSM, a_AddBDItemFunc, a_AddMessageFunc, a_FinishMessageFunc, a_ParentPrefix, a_ParentTableName : str, a_ParentKeyFieldName, a_FieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_ButtonFunc, a_FieldType, access_mode = user_access.AccessMode.ADD):
keyboard_cancel = bd_item.GetCancelKeyboardButtonsTemplate(a_Bot, a_AccessFunc, access_mode)
@ -114,7 +117,7 @@ def AddBDItem1RegisterHandlers(a_Bot, a_StartCheckFunc, a_FSM, a_AddBDItemFunc,
if a_ParentTableName:
reg_func = a_Bot.RegisterCallbackHandler
reg_func(StartAddBDItemTemplate(a_Bot, a_FSM, a_FSM.bd_item, a_AddMessageFunc, a_ParentTableName, a_ParentKeyFieldName, a_ParentPrefix, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode), a_StartCheckFunc)
finish_handler = FinishAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_FinishMessageFunc, a_AccessFunc, a_ButtonFunc, access_mode, field_type = a_FieldType)
finish_handler = FinishAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_FinishMessageFunc, None, a_AccessFunc, a_ButtonFunc, access_mode, field_type = a_FieldType)
if a_FieldType == bd_item.FieldType.photo:
a_Bot.RegisterMessageHandler(finish_handler, content_types = ['photo', 'text'], state = a_FSM.bd_item)
else:

14
template/bd_item_edit.py

@ -18,7 +18,7 @@ error_photo_type_message = '''
def StartEditBDItemTemplate(a_Bot, a_FSM, a_MessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = user_access.AccessMode.EDIT):
return bd_item_add.StartAddBDItemTemplate(a_Bot, a_FSM, a_FSM.item_field, a_MessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = access_mode)
def FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_OnChangeFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text):
def FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, a_OnChangeFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text):
def EditBDItemFunc(a_ItemData, a_UserID):
item_id = a_ItemData[a_KeyName]
field_value = a_ItemData[a_FieldName]
@ -31,15 +31,15 @@ def FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName,
a_OnChangeFunc()
return res, error
return bd_item_add.FinishAddBDItemTemplate(a_Bot, a_FSM, EditBDItemFunc, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, access_mode = access_mode, field_type = field_type)
return bd_item_add.FinishAddBDItemTemplate(a_Bot, a_FSM, EditBDItemFunc, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, access_mode = access_mode, field_type = field_type)
def EditBDItemRegisterHandlers(a_Bot, a_SelectSource, a_FSM, a_StartMessage, a_EditMessageFunc, a_FinishMessageFunc, a_TableName : str, a_KeyName, a_FieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_FinishButtonFunc, a_OnChangeFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text):
keyboard_cancel = bd_item.GetCancelKeyboardButtonsTemplate(a_Bot, a_AccessFunc, access_mode)
def EditBDItemRegisterHandlers(a_Bot, a_SelectSource, a_FSM, a_StartMessage, a_EditMessageFunc, a_FinishMessageFunc, a_TableName, a_KeyName, a_FieldName, a_PostProcessFunc, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_AdditionalButtonFunc, a_FinishButtonFunc, a_OnChangeFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text):
keyboard = bd_item.MixKeyboardFuncTemplate(a_AdditionalButtonFunc, bd_item.GetCancelKeyboardButtonsTemplate(a_Bot, a_AccessFunc, access_mode))
a_Prefix = bd_item_select.SelectRegisterHandlers(a_Bot, a_SelectSource, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = access_mode)
a_Bot.RegisterCallbackHandler(StartEditBDItemTemplate(a_Bot, a_FSM, a_EditMessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, keyboard_cancel, a_FinishButtonFunc, access_mode), bd_item.GetCheckForPrefixFunc(a_Prefix))
a_Bot.RegisterCallbackHandler(StartEditBDItemTemplate(a_Bot, a_FSM, a_EditMessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, keyboard, a_FinishButtonFunc, access_mode), bd_item.GetCheckForPrefixFunc(a_Prefix))
if field_type == bd_item.FieldType.photo:
a_Bot.RegisterMessageHandler(FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_AccessFunc, a_FinishButtonFunc, a_OnChangeFunc, access_mode, field_type = field_type), content_types = ['photo', 'text'], state = a_FSM.item_field)
a_Bot.RegisterMessageHandler(FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_PostProcessFunc, a_AccessFunc, a_FinishButtonFunc, a_OnChangeFunc, access_mode, field_type = field_type), content_types = ['photo', 'text'], state = a_FSM.item_field)
else:
a_Bot.RegisterMessageHandler(FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_AccessFunc, a_FinishButtonFunc, a_OnChangeFunc, access_mode, field_type = field_type), state = a_FSM.item_field)
a_Bot.RegisterMessageHandler(FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_PostProcessFunc, a_AccessFunc, a_FinishButtonFunc, a_OnChangeFunc, access_mode, field_type = field_type), state = a_FSM.item_field)

Loading…
Cancel
Save