@ -4,7 +4,7 @@
# Модуль для редактирования и просмотра таблицы в БД
# Модуль для редактирования и просмотра таблицы в БД
from bot_sys import keyboard , user_access , bd_table , bot_bd , bot_subscribes
from bot_sys import keyboard , user_access , bd_table , bot_bd , bot_subscribes
from bot_modules import access_utils , mod_simple_message
from bot_modules import access_utils , mod_simple_message , groups_utils
from template import simple_message , bd_item , bd_item_select , bd_item_view , bd_item_delete , bd_item_add , bd_item_edit
from template import simple_message , bd_item , bd_item_select , bd_item_view , bd_item_delete , bd_item_add , bd_item_edit
from aiogram . dispatcher import FSMContext
from aiogram . dispatcher import FSMContext
@ -22,6 +22,9 @@ def EnumButton(a_EnumItem):
def EditMessage ( a_BDTableDestiny ) :
def EditMessage ( a_BDTableDestiny ) :
return ' edit ' + str ( a_BDTableDestiny )
return ' edit ' + str ( a_BDTableDestiny )
def InlineMessage ( a_ButtonName ) :
return ' inline ' + str ( a_ButtonName )
def CreateMessage ( a_BDTableDestiny ) :
def CreateMessage ( a_BDTableDestiny ) :
return ' create ' + str ( a_BDTableDestiny )
return ' create ' + str ( a_BDTableDestiny )
@ -35,6 +38,7 @@ def SubscribeMessage(a_EnumItem):
return ' subscribe ' + str ( a_EnumItem )
return ' subscribe ' + str ( a_EnumItem )
class ButtonNames ( Enum ) :
class ButtonNames ( Enum ) :
SHOW = auto ( )
LIST = auto ( )
LIST = auto ( )
ADD = auto ( )
ADD = auto ( )
EDIT = auto ( )
EDIT = auto ( )
@ -88,6 +92,20 @@ def MakeFSMForEdit(a_ModName, a_FieldName):
exec ( cmd , globals ( ) , _locals )
exec ( cmd , globals ( ) , _locals )
return _locals [ ' fsm ' ]
return _locals [ ' fsm ' ]
add_and_edit_fsm_cmd = '''
class FSMAddAndEdit { a_ModName } _ { a_FieldName } _Item ( StatesGroup ) :
item_field = State ( )
fsm = FSMAddAndEdit { a_ModName } _ { a_FieldName } _Item
'''
def MakeFSMForAddAndEdit ( a_ModName , a_FieldName ) :
cmd = add_and_edit_fsm_cmd . replace ( " {a_ModName} " , a_ModName ) . replace ( " {a_FieldName} " , a_FieldName )
_locals = locals ( )
exec ( cmd , globals ( ) , _locals )
return _locals [ ' fsm ' ]
class TableOperateModule ( mod_simple_message . SimpleMessageModule ) :
class TableOperateModule ( mod_simple_message . SimpleMessageModule ) :
def __init__ ( self , a_Table , a_Messages , a_Buttons , a_ParentModName , a_ChildModName , a_InitAccess , a_DefInitAccess , a_ChildModuleNameList , a_EditModuleNameList , a_Bot , a_ModuleAgregator , a_BotMessages , a_BotButtons , a_BotSubscribes , a_Log ) :
def __init__ ( self , a_Table , a_Messages , a_Buttons , a_ParentModName , a_ChildModName , a_InitAccess , a_DefInitAccess , a_ChildModuleNameList , a_EditModuleNameList , a_Bot , a_ModuleAgregator , a_BotMessages , a_BotButtons , a_BotSubscribes , a_Log ) :
super ( ) . __init__ ( a_Messages , a_Buttons , a_InitAccess , a_DefInitAccess , a_ChildModuleNameList , a_Bot , a_ModuleAgregator , a_BotMessages , a_BotButtons , a_BotSubscribes , a_Log )
super ( ) . __init__ ( a_Messages , a_Buttons , a_InitAccess , a_DefInitAccess , a_ChildModuleNameList , a_Bot , a_ModuleAgregator , a_BotMessages , a_BotButtons , a_BotSubscribes , a_Log )
@ -96,6 +114,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
self . m_ChildModName = a_ChildModName
self . m_ChildModName = a_ChildModName
self . m_ParentModName = a_ParentModName
self . m_ParentModName = a_ParentModName
self . m_SelectPrefix = ' '
self . m_SelectPrefix = ' '
self . m_EditPrefix = { }
def GetEditKeyboardButtons ( a_Message , a_UserGroups ) :
def GetEditKeyboardButtons ( a_Message , a_UserGroups ) :
return self . GetEditKeyboardButtons ( a_Message , a_UserGroups )
return self . GetEditKeyboardButtons ( a_Message , a_UserGroups )
@ -152,6 +171,11 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
cur_buttons + = [ keyboard . ButtonWithAccess ( self . GetButton ( EditButton ( f . m_Destiny ) ) , access , self . GetAccess ( ) ) , ]
cur_buttons + = [ keyboard . ButtonWithAccess ( self . GetButton ( EditButton ( f . m_Destiny ) ) , access , self . GetAccess ( ) ) , ]
return mod_buttons + keyboard . MakeButtons ( self . m_Bot , cur_buttons , a_UserGroups )
return mod_buttons + keyboard . MakeButtons ( self . m_Bot , cur_buttons , a_UserGroups )
def GetShowItemInlineKeyboardTemplate ( self , a_ItemID ) :
def GetShowItemInlineKeyboard ( a_Message , a_UserGroups ) :
return self . GetShowItemInlineKeyboard ( a_Message , a_UserGroups , a_ItemID )
return GetShowItemInlineKeyboard
def GetViewItemInlineKeyboardTemplate ( self , a_ItemID ) :
def GetViewItemInlineKeyboardTemplate ( self , a_ItemID ) :
def GetViewItemInlineKeyboard ( a_Message , a_UserGroups ) :
def GetViewItemInlineKeyboard ( a_Message , a_UserGroups ) :
return self . GetViewItemInlineKeyboard ( a_Message , a_UserGroups , a_ItemID )
return self . GetViewItemInlineKeyboard ( a_Message , a_UserGroups , a_ItemID )
@ -160,12 +184,27 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
def GetSelectPrefix ( self ) :
def GetSelectPrefix ( self ) :
return self . m_SelectPrefix
return self . m_SelectPrefix
def GetDelPrefix ( self ) :
return self . m_DelPrefix
def GetAddPrefix ( self ) :
return self . m_AddPrefix
def GetShowPrefix ( self ) :
return self . m_ShowPrefix
def GetShowItemInlineKeyboard ( self , a_Message , a_UserGroups , a_ItemID ) :
cur_buttons = [
keyboard . InlineButtonWithAccess ( self . GetButton ( ButtonNames . SHOW ) , self . GetShowPrefix ( ) , a_ItemID , self . GetAccess ( ) , user_access . AccessMode . VIEW ) ,
]
return keyboard . MakeInlineKeyboardButtons ( self . m_Bot , cur_buttons , a_UserGroups )
def GetViewItemInlineKeyboard ( self , a_Message , a_UserGroups , a_ItemID ) :
def GetViewItemInlineKeyboard ( self , a_Message , a_UserGroups , a_ItemID ) :
if not self . m_ChildModName :
if not self . m_ChildModName :
return None
return None
child_mod = self . GetModule ( self . m_ChildModName )
child_mod = self . GetModule ( self . m_ChildModName )
cur_buttons = [
cur_buttons = [
keyboard . InlineButtonWithAccess ( child_mod . GetButton ( ButtonNames . LIST ) , child_mod . GetSelectPrefix ( ) , a_ItemID , self . GetAccess ( ) , user_access . AccessMode . VIEW ) ,
keyboard . InlineButtonWithAccess ( child_mod . GetButton ( ButtonNames . LIST ) , child_mod . GetSelectPrefix ( ) , a_ItemID , child_mod . GetAccess ( ) , user_access . AccessMode . VIEW ) ,
]
]
return keyboard . MakeInlineKeyboardButtons ( self . m_Bot , cur_buttons , a_UserGroups )
return keyboard . MakeInlineKeyboardButtons ( self . m_Bot , cur_buttons , a_UserGroups )
@ -214,23 +253,49 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
a_Msg . UpdatePhotoID ( ' , ' . join ( photos ) )
a_Msg . UpdatePhotoID ( ' , ' . join ( photos ) )
return a_Msg
return a_Msg
def GetParentID ( self , a_Item , a_ItemDict , a_TableName ) :
parent_id = None
parent_id_field = self . m_Table . GetFieldNameByDestiny ( bd_table . TableFieldDestiny . PARENT_ID )
if parent_id_field and a_ItemDict and parent_id_field in a_ItemDict :
parent_id = str ( a_ItemDict [ parent_id_field ] )
parent_id_field_id = self . m_Table . GetFieldIDByDestiny ( bd_table . TableFieldDestiny . PARENT_ID )
if not parent_id and parent_id_field_id != None and a_Item and len ( a_Item ) == self . m_Table . GetFieldsCount ( ) and self . m_Table . GetName ( ) == a_TableName :
parent_id = str ( a_Item [ parent_id_field_id ] )
if self . m_ParentModName :
parent_mod = self . GetModule ( self . m_ParentModName )
if parent_mod :
key_field_id = parent_mod . m_Table . GetFieldIDByDestiny ( bd_table . TableFieldDestiny . KEY )
if not parent_id and key_field_id != None and a_Item and len ( a_Item ) == parent_mod . m_Table . GetFieldsCount ( ) and parent_mod . m_Table . GetName ( ) == a_TableName :
parent_id = str ( a_Item [ key_field_id ] )
return parent_id
def GetMessageNameWithTableFieldDestinyAndValue ( self , a_NameWithoutDestiny , a_Destiny , a_Value ) :
return a_NameWithoutDestiny + ' ? ' + str ( a_Destiny ) + ' = ' + str ( a_Value )
def ShowMessageTemplate ( self , a_Message , Inline_keyboard_template_func = None , a_EnablePhoto = False ) :
def ShowMessageTemplate ( self , a_Message , Inline_keyboard_template_func = None , a_EnablePhoto = False ) :
async def ShowMessage ( a_CallbackQuery , a_Item , a_ItemDict , table_name = self . m_Table . GetName ( ) ) :
async def ShowMessage ( a_CallbackQuery , a_Item , a_ItemDict , table_name = self . m_Table . GetName ( ) ) :
msg = a_Message . StaticCopy ( )
lang = str ( a_CallbackQuery . from_user . language_code )
msg = a_Message
# Подменяем сообщение, если оно уже есть для PARENT_ID
parent_id = self . GetParentID ( a_Item , a_ItemDict , table_name )
if parent_id :
name = self . GetMessageNameWithTableFieldDestinyAndValue ( msg . GetName ( ) , bd_table . TableFieldDestiny . PARENT_ID , parent_id )
parent_id_msg = a_Message . FindMessageForLang ( name , lang )
if parent_id_msg :
msg = parent_id_msg
msg = msg . GetMessageForLang ( lang ) . StaticCopy ( )
# TODO: добавить поддержку языков в a_MessageName
# TODO: добавить поддержку языков в a_MessageName
Inline_keyboard_func = None
Inline_keyboard_func = None
item_access = None
item_access = None
if a_ItemDict :
if a_ItemDict :
lang = str ( a_CallbackQuery . from_user . language_code )
msg = msg . GetMessageForLang ( lang ) . StaticCopy ( )
msg = self . UpdateMessageByDict ( msg , lang , a_ItemDict , a_EnablePhoto = a_EnablePhoto )
msg = self . UpdateMessageByDict ( msg , lang , a_ItemDict , a_EnablePhoto = a_EnablePhoto )
if a_Item and self . m_Table . GetName ( ) == table_name :
if a_Item and self . m_Table . GetName ( ) == table_name :
if len ( a_Item ) < self . m_Table . GetFieldsCount ( ) - 1 : # Для проектов это нужно. Там на 1 меньше поле. TODO разделить отправку сообщений item_access и Inline_keyboard_func
if len ( a_Item ) < self . m_Table . GetFieldsCount ( ) - 1 : # Для проектов это нужно. Там на 1 меньше поле. TODO разделить отправку сообщений item_access и Inline_keyboard_func
return simple_message . WorkFuncResult ( self . GetMessage ( Messages . ERROR_FIND ) )
return simple_message . WorkFuncResult ( self . GetMessage ( Messages . ERROR_FIND ) )
elif len ( a_Item ) == self . m_Table . GetFieldsCount ( ) :
elif len ( a_Item ) == self . m_Table . GetFieldsCount ( ) :
lang = str ( a_CallbackQuery . from_user . language_code )
msg = msg . GetMessageForLang ( lang ) . StaticCopy ( )
msg = self . UpdateMessage ( msg , lang , a_Item , a_EnablePhoto = a_EnablePhoto )
msg = self . UpdateMessage ( msg , lang , a_Item , a_EnablePhoto = a_EnablePhoto )
item_access = a_Item [ self . m_Table . GetFieldIDByDestiny ( bd_table . TableFieldDestiny . ACCESS ) ]
item_access = a_Item [ self . m_Table . GetFieldIDByDestiny ( bd_table . TableFieldDestiny . ACCESS ) ]
if Inline_keyboard_template_func :
if Inline_keyboard_template_func :
@ -247,34 +312,34 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
async def PostDelete ( self , a_CallbackQuery , a_ItemID ) :
async def PostDelete ( self , a_CallbackQuery , a_ItemID ) :
user_id = a_CallbackQuery . from_user . id
user_id = a_CallbackQuery . from_user . id
self . m_Log . Success ( f ' Задача №{ a_ItemID } была удалена пользователем { user_id } . ' )
self . m_Log . Success ( f ' Элемент №{ a_ItemID } была удалена пользователем { user_id } . ' )
#TODO: удалить вложенные
#TODO: удалить вложенные
self . OnChange ( )
self . OnChange ( )
subscribe_type = bot_subscribes . SubscribeType . ANY_ITEM_DEL
subscribe_type = bot_subscribes . SubscribeType . ANY_ITEM_DEL
item_id = - 1
item_id = - 1
await self . SendSubscribe ( subscribe_type , item_id , user_id )
await self . SendSubscribe ( subscribe_type , item_id , user_id , item_id )
subscribe_type = bot_subscribes . SubscribeType . ITEM_DEL
subscribe_type = bot_subscribes . SubscribeType . ITEM_DEL
item_id = a_ItemID
item_id = a_ItemID
await self . SendSubscribe ( subscribe_type , item_id , user_id )
await self . SendSubscribe ( subscribe_type , item_id , user_id , item_id )
table_name = self . m_Table . GetName ( )
table_name = self . m_Table . GetName ( )
key_name = self . GetKeyFieldName ( )
key_name = self . GetKeyFieldName ( )
cur_item = GetCurItem ( self . m_Bot , table_name , key_name , a_ItemID )
cur_item = GetCurItem ( self . m_Bot , table_name , key_name , a_ItemID )
print ( cur_item )
parent_id_field_index = self . m_Table . GetFieldIDByDestiny ( bd_table . TableFieldDestiny . PARENT_ID )
parent_id_field_index = self . m_Table . GetFieldIDByDestiny ( bd_table . TableFieldDestiny . PARENT_ID )
if parent_id_field_index and cur_item and cur_item [ parent_id_field_index ] :
if parent_id_field_index and cur_item and cur_item [ parent_id_field_index ] :
subscribe_type = bot_subscribes . SubscribeType . ANY_ITEM_DEL_WITH_PARENT
subscribe_type = bot_subscribes . SubscribeType . ANY_ITEM_DEL_WITH_PARENT
item_id = cur_item [ parent_id_field_index ]
item_id = cur_item [ parent_id_field_index ]
await self . SendSubscribe ( subscribe_type , item_id , user_id )
await self . SendSubscribe ( subscribe_type , item_id , user_id , item_id )
return simple_message . WorkFuncResult ( self . GetMessage ( Messages . SUCCESS_DELETE ) )
return simple_message . WorkFuncResult ( self . GetMessage ( Messages . SUCCESS_DELETE ) )
async def AddBDItemFunc ( self , a_ItemData , a_UserID ) :
async def AddBDItemFunc ( self , a_ItemData , a_UserID ) :
table_name = self . m_Table . GetName ( )
table_name = self . m_Table . GetName ( )
key_field = self . m_Table . GetFieldNameByDestiny ( bd_table . TableFieldDestiny . KEY )
name_field = self . m_Table . GetFieldNameByDestiny ( bd_table . TableFieldDestiny . NAME )
name_field = self . m_Table . GetFieldNameByDestiny ( bd_table . TableFieldDestiny . NAME )
photo_field = self . m_Table . GetFieldNameByDestiny ( bd_table . TableFieldDestiny . PHOTO )
photo_field = self . m_Table . GetFieldNameByDestiny ( bd_table . TableFieldDestiny . PHOTO )
desc_field = self . m_Table . GetFieldNameByDestiny ( bd_table . TableFieldDestiny . DESC )
desc_field = self . m_Table . GetFieldNameByDestiny ( bd_table . TableFieldDestiny . DESC )
@ -304,8 +369,8 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
values + = [ ' ? ' ]
values + = [ ' ? ' ]
param + = ( a_ItemData [ n ] , )
param + = ( a_ItemData [ n ] , )
request = f ' INSERT INTO { table_name } ( { " , " . join ( fields ) } ) VALUES( { " , " . join ( values ) } ) '
request = f ' INSERT INTO { table_name } ( { " , " . join ( fields ) } ) VALUES( { " , " . join ( values ) } ) ' # RETURNING {key_field}
print ( ' request ' , request , param )
#print('request', request, param )
res , error = self . m_Bot . SQLRequest ( request , commit = True , return_error = True , param = param )
res , error = self . m_Bot . SQLRequest ( request , commit = True , return_error = True , param = param )
self . OnChange ( )
self . OnChange ( )
@ -314,36 +379,56 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
else :
else :
self . m_Log . Success ( f ' Пользователь { a_UserID } . Добавлена запись в таблицу { request } { param } . ' )
self . m_Log . Success ( f ' Пользователь { a_UserID } . Добавлена запись в таблицу { request } { param } . ' )
res_id , error_id = self . m_Bot . SQLRequest ( f ' SELECT rowid from { table_name } order by ROWID DESC limit 1 ' , commit = False , return_error = True )
table_item_id = - 1
if not error_id and res_id and len ( res_id ) == 1 and len ( res_id [ 0 ] ) == 1 :
table_item_id = str ( res_id [ 0 ] [ 0 ] )
#print('res_id', res, error, table_item_id)
subscribe_type = bot_subscribes . SubscribeType . ANY_ITEM_ADD
subscribe_type = bot_subscribes . SubscribeType . ANY_ITEM_ADD
item_id = - 1
item_id = - 1
await self . SendSubscribe ( subscribe_type , item_id , a_UserID )
await self . SendSubscribe ( subscribe_type , item_id , a_UserID , table_item_id )
if parent_id_field and a_ItemData [ parent_id_field ] :
if parent_id_field and a_ItemData [ parent_id_field ] :
subscribe_type = bot_subscribes . SubscribeType . ANY_ITEM_ADD_WITH_PARENT
subscribe_type = bot_subscribes . SubscribeType . ANY_ITEM_ADD_WITH_PARENT
item_id = a_ItemData [ parent_id_field ]
item_id = a_ItemData [ parent_id_field ]
await self . SendSubscribe ( subscribe_type , item_id , a_UserID )
await self . SendSubscribe ( subscribe_type , item_id , a_UserID , table_item_id )
return res , error
return res , error
async def SendSubscribe ( self , a_Type , a_ItemID , a_OwnerUserID ) :
async def SendMessageToUser ( self , a_Message , a_UserID , a_GetButtonsFunc = None , a_GetInlineButtonsFunc = None , parse_mode = None ) :
a_Message = a_Message . StaticCopy ( )
a_MessageFromUSer = None
user_groups = groups_utils . GetUserGroupData ( self . m_Bot , a_UserID )
try :
#print('SendMessage', self.m_Bot, a_Message, a_GetButtonsFunc, a_GetInlineButtonsFunc, a_UserID, a_MessageFromUSer, user_groups, parse_mode)
await simple_message . SendMessage ( self . m_Bot , a_Message , a_GetButtonsFunc , a_GetInlineButtonsFunc , a_UserID , a_MessageFromUSer , user_groups , parse_mode = parse_mode )
return True
except :
return False
async def SendSubscribe ( self , a_Type , a_ItemID , a_OwnerUserID , a_TableItem ) :
table_name = self . m_Table . GetName ( )
key_name = self . GetKeyFieldName ( )
cur_item = GetCurItem ( self . m_Bot , table_name , key_name , a_TableItem )
for s_user_id in self . m_BotSubscribes . GetUserIDs ( self . GetName ( ) , a_Type , a_ItemID = a_ItemID ) :
for s_user_id in self . m_BotSubscribes . GetUserIDs ( self . GetName ( ) , a_Type , a_ItemID = a_ItemID ) :
a_BotMessage = self . GetMessage ( SubscribeMessage ( a_Type ) )
a_BotMessage = self . GetMessage ( SubscribeMessage ( a_Type ) )
#print('s_user_id', s_user_id, a_BotMessage, a_OwnerUserID, a_TableItem, cur_item)
if not a_BotMessage :
if not a_BotMessage :
continue
continue
if s_user_id == a_OwnerUserID :
if s_user_id == a_OwnerUserID :
continue
continue
a_BotMessage = a_BotMessage . StaticCopy ( )
a_BotMessage . UpdateDesc ( a_BotMessage . GetDesc ( ) . replace ( " #item_id " , str ( a_ItemID ) ) )
a_GetButtonsFunc = None
a_GetInlineButtonsFunc = None
a_UserID = s_user_id
a_UserID = s_user_id
a_Message = None
a_BotMessage = a_BotMessage . StaticCopy ( )
user_groups = None
a_BotMessage . UpdateDesc ( a_BotMessage . GetDesc ( ) . replace ( " #item_id " , str ( a_TableItem ) ) )
parse_mode = None
try :
inline_keyboard_func = None
await simple_message . SendMessage ( self . m_Bot , a_BotMessage , a_GetButtonsFunc , a_GetInlineButtonsFunc , a_UserID , a_Message , user_groups , parse_mode = parse_mode )
if cur_item :
except :
a_BotMessage . UpdateDesc ( self . m_Table . ReplaceAllFieldTags ( a_BotMessage . GetDesc ( ) , cur_item ) )
return
inline_keyboard_func = self . GetShowItemInlineKeyboardTemplate ( a_TableItem )
await self . SendMessageToUser ( a_BotMessage , a_UserID , a_GetInlineButtonsFunc = inline_keyboard_func )
def SelectSourceTemplate ( self , a_PrevPrefix , a_ButtonName ) :
def SelectSourceTemplate ( self , a_PrevPrefix , a_ButtonName ) :
parent_id_field = self . m_Table . GetFieldNameByDestiny ( bd_table . TableFieldDestiny . PARENT_ID )
parent_id_field = self . m_Table . GetFieldNameByDestiny ( bd_table . TableFieldDestiny . PARENT_ID )
@ -389,24 +474,23 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
async def OnChangeField ( self , a_Field , a_ItemID , a_ItemData , a_EditUserID ) :
async def OnChangeField ( self , a_Field , a_ItemID , a_ItemData , a_EditUserID ) :
subscribe_type = bot_subscribes . SubscribeType . ANY_ITEM_EDIT
subscribe_type = bot_subscribes . SubscribeType . ANY_ITEM_EDIT
item_id = - 1
item_id = - 1
await self . SendSubscribe ( subscribe_type , item_id , a_EditUserID )
await self . SendSubscribe ( subscribe_type , item_id , a_EditUserID , a_ItemID )
subscribe_type = bot_subscribes . SubscribeType . ITEM_EDIT
subscribe_type = bot_subscribes . SubscribeType . ITEM_EDIT
item_id = a_ItemID
item_id = a_ItemID
await self . SendSubscribe ( subscribe_type , item_id , a_EditUserID )
await self . SendSubscribe ( subscribe_type , item_id , a_EditUserID , a_ItemID )
table_name = self . m_Table . GetName ( )
table_name = self . m_Table . GetName ( )
key_name = self . GetKeyFieldName ( )
key_name = self . GetKeyFieldName ( )
cur_item = GetCurItem ( self . m_Bot , table_name , key_name , a_ItemID )
cur_item = GetCurItem ( self . m_Bot , table_name , key_name , a_ItemID )
print ( cur_item )
#print(cur_item )
parent_id_field_index = self . m_Table . GetFieldIDByDestiny ( bd_table . TableFieldDestiny . PARENT_ID )
parent_id_field_index = self . m_Table . GetFieldIDByDestiny ( bd_table . TableFieldDestiny . PARENT_ID )
if parent_id_field_index and cur_item and cur_item [ parent_id_field_index ] :
if parent_id_field_index and cur_item and cur_item [ parent_id_field_index ] :
subscribe_type = bot_subscribes . SubscribeType . ANY_ITEM_EDIT_WITH_PARENT
subscribe_type = bot_subscribes . SubscribeType . ANY_ITEM_EDIT_WITH_PARENT
item_id = cur_item [ parent_id_field_index ]
item_id = cur_item [ parent_id_field_index ]
await self . SendSubscribe ( subscribe_type , item_id , a_EditUserID )
await self . SendSubscribe ( subscribe_type , item_id , a_EditUserID , a_ItemID )
def RegisterEdit ( self , a_Field , a_AccessMode = user_access . AccessMode . EDIT ) :
def RegisterEdit ( self , a_Field , a_AccessMode = user_access . AccessMode . EDIT ) :
a_ButtonName = self . GetButton ( EditButton ( a_Field . m_Destiny ) )
a_ButtonName = self . GetButton ( EditButton ( a_Field . m_Destiny ) )
@ -432,7 +516,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
a_Prefix = self . RegisterSelect ( a_ButtonName , user_access . AccessMode . VIEW , only_parent = True )
a_Prefix = self . RegisterSelect ( a_ButtonName , user_access . AccessMode . VIEW , only_parent = True )
bd_item_edit . EditBDItemRegisterHandlers ( self . m_Bot , \
a_Prefix = bd_item_edit . EditBDItemRegisterHandlers ( self . m_Bot , \
self . SelectSourceTemplate ( a_Prefix , a_ButtonName ) , \
self . SelectSourceTemplate ( a_Prefix , a_ButtonName ) , \
MakeFSMForEdit ( self . GetName ( ) , a_FieldName ) , \
MakeFSMForEdit ( self . GetName ( ) , a_FieldName ) , \
self . GetMessage ( Messages . SELECT_TO_EDIT ) , \
self . GetMessage ( Messages . SELECT_TO_EDIT ) , \
@ -451,8 +535,10 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
field_type = a_FieldType \
field_type = a_FieldType \
)
)
def GetAddFields ( self ) :
self . m_EditPrefix . update ( { a_Field . m_Destiny : a_Prefix } )
add_destiny = (
def GetAddFieldDestinys ( self ) :
return (
bd_table . TableFieldDestiny . NAME ,
bd_table . TableFieldDestiny . NAME ,
bd_table . TableFieldDestiny . DESC ,
bd_table . TableFieldDestiny . DESC ,
bd_table . TableFieldDestiny . PHOTO ,
bd_table . TableFieldDestiny . PHOTO ,
@ -466,6 +552,9 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
bd_table . TableFieldDestiny . USER_CONTACTS ,
bd_table . TableFieldDestiny . USER_CONTACTS ,
bd_table . TableFieldDestiny . USER_CONFIRM ,
bd_table . TableFieldDestiny . USER_CONFIRM ,
)
)
def GetAddFields ( self ) :
add_destiny = self . GetAddFieldDestinys ( )
fields = [ ]
fields = [ ]
for f in self . m_Table . GetFields ( ) :
for f in self . m_Table . GetFields ( ) :
if f . m_Destiny in add_destiny :
if f . m_Destiny in add_destiny :
@ -562,6 +651,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
GetAccess , \
GetAccess , \
access_mode = user_access . AccessMode . VIEW \
access_mode = user_access . AccessMode . VIEW \
)
)
self . m_ShowPrefix = a_Prefix
bd_item_view . ShowBDItemRegisterHandlers ( self . m_Bot , \
bd_item_view . ShowBDItemRegisterHandlers ( self . m_Bot , \
a_Prefix , \
a_Prefix , \
table_name , \
table_name , \
@ -576,6 +666,8 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
a_ButtonName = self . GetButton ( ButtonNames . DEL )
a_ButtonName = self . GetButton ( ButtonNames . DEL )
if a_ButtonName :
if a_ButtonName :
a_Prefix = self . RegisterSelect ( a_ButtonName , user_access . AccessMode . VIEW )
a_Prefix = self . RegisterSelect ( a_ButtonName , user_access . AccessMode . VIEW )
self . m_DelPrefix = a_Prefix
bd_item_delete . DeleteBDItemRegisterHandlers ( self . m_Bot , \
bd_item_delete . DeleteBDItemRegisterHandlers ( self . m_Bot , \
a_Prefix , \
a_Prefix , \
table_name , \
table_name , \
@ -590,6 +682,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
a_ButtonName = self . GetButton ( ButtonNames . ADD )
a_ButtonName = self . GetButton ( ButtonNames . ADD )
if a_ButtonName :
if a_ButtonName :
a_Prefix = self . RegisterSelect ( a_ButtonName , user_access . AccessMode . VIEW , only_parent = True )
a_Prefix = self . RegisterSelect ( a_ButtonName , user_access . AccessMode . VIEW , only_parent = True )
self . m_AddPrefix = a_Prefix
check_func = bd_item . GetCheckForTextFunc ( a_ButtonName )
check_func = bd_item . GetCheckForTextFunc ( a_ButtonName )
if a_Prefix :
if a_Prefix :
@ -621,9 +714,6 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
bd_item . GetCheckForTextFunc ( a_ButtonName ) \
bd_item . GetCheckForTextFunc ( a_ButtonName ) \
)
)
address_field = self . m_Table . GetFieldNameByDestiny ( bd_table . TableFieldDestiny . ADDRESS )
status_field = self . m_Table . GetFieldNameByDestiny ( bd_table . TableFieldDestiny . STATUS )
for f in self . m_Table . GetFields ( ) :
for f in self . m_Table . GetFields ( ) :
self . RegisterEdit ( f )
self . RegisterEdit ( f )