Browse Source

Список внутренних элементов при просмотре. Изменение работы инлайн кнопок

test_bot
Alexei 2 years ago
parent
commit
1eb755c295
  1. 4
      bot_modules/comments.py
  2. 20
      bot_modules/needs.py
  3. 17
      bot_modules/projects.py
  4. 21
      bot_modules/tasks.py
  5. 18
      bot_sys/keyboard.py
  6. 6
      template/bd_item_select.py

4
bot_modules/comments.py

@ -45,6 +45,8 @@ init_bd_cmds = [f'''CREATE TABLE IF NOT EXISTS {table_name}(
f"INSERT OR IGNORE INTO module_access (modName, modAccess, itemDefaultAccess) VALUES ('{module_name}', '{user_access.user_access_group_new}=va', '{user_access.user_access_group_new}=va');" f"INSERT OR IGNORE INTO module_access (modName, modAccess, itemDefaultAccess) VALUES ('{module_name}', '{user_access.user_access_group_new}=va', '{user_access.user_access_group_new}=va');"
] ]
select_comments_prefix = ''
# --------------------------------------------------------- # ---------------------------------------------------------
# Сообщения # Сообщения
@ -264,6 +266,8 @@ def RegisterHandlers(dp : Dispatcher):
defaul_keyboard_func, \ defaul_keyboard_func, \
access_mode = user_access.AccessMode.VIEW\ access_mode = user_access.AccessMode.VIEW\
) )
global select_comments_prefix
select_comments_prefix = a_Prefix
# Удаление комментариев # Удаление комментариев
a_Prefix = RegisterSelectParent(del_comment_button_name, user_access.AccessMode.DELETE) a_Prefix = RegisterSelectParent(del_comment_button_name, user_access.AccessMode.DELETE)

20
bot_modules/needs.py

@ -59,6 +59,8 @@ init_bd_cmds = [f'''CREATE TABLE IF NOT EXISTS {table_name}(
f"INSERT OR IGNORE INTO module_access (modName, modAccess, itemDefaultAccess) VALUES ('{module_name}', '{user_access.user_access_group_new}=va', '{user_access.user_access_group_new}=va');" f"INSERT OR IGNORE INTO module_access (modName, modAccess, itemDefaultAccess) VALUES ('{module_name}', '{user_access.user_access_group_new}=va', '{user_access.user_access_group_new}=va');"
] ]
select_needs_prefix = ''
# --------------------------------------------------------- # ---------------------------------------------------------
# Сообщения # Сообщения
@ -187,6 +189,13 @@ def GetStartNeedKeyboardButtons(a_Message, a_UserGroups):
mods = [start, projects, tasks, comments] mods = [start, projects, tasks, comments]
return keyboard.MakeKeyboard(keyboard.GetButtons(mods) + cur_buttons, a_UserGroups) return keyboard.MakeKeyboard(keyboard.GetButtons(mods) + cur_buttons, a_UserGroups)
def GetViewItemInlineKeyboardTemplate(a_ItemID):
def GetViewItemInlineKeyboard(a_Message, a_UserGroups):
cur_buttons = [
keyboard.InlineButton(comments.list_comment_button_name, comments.select_comments_prefix, a_ItemID, GetAccess(), user_access.AccessMode.VIEW),
]
return keyboard.MakeInlineKeyboard(cur_buttons, a_UserGroups)
return GetViewItemInlineKeyboard
# --------------------------------------------------------- # ---------------------------------------------------------
# Обработка сообщений # Обработка сообщений
@ -198,7 +207,7 @@ def GetButtonNameAndKeyValueAndAccess(a_Item):
# needName needID needAccess # needName needID needAccess
return a_Item[1], a_Item[0], a_Item[4] return a_Item[1], a_Item[0], a_Item[4]
def ShowMessageTemplate(a_StringMessage): def ShowMessageTemplate(a_StringMessage, keyboard_template_func = None):
async def ShowMessage(a_CallbackQuery : types.CallbackQuery, a_Item): async def ShowMessage(a_CallbackQuery : types.CallbackQuery, a_Item):
if (len(a_Item) < 6): if (len(a_Item) < 6):
return simple_message.WorkFuncResult(error_find_proj_message) return simple_message.WorkFuncResult(error_find_proj_message)
@ -208,7 +217,10 @@ def ShowMessageTemplate(a_StringMessage):
replace(f'#{desc_field}', a_Item[2]).\ replace(f'#{desc_field}', a_Item[2]).\
replace(f'#{create_datetime_field}', a_Item[5]).\ replace(f'#{create_datetime_field}', a_Item[5]).\
replace(f'#{access_field}', a_Item[4]) replace(f'#{access_field}', a_Item[4])
return simple_message.WorkFuncResult(msg, photo_id = a_Item[3], item_access = a_Item[4]) keyboard_func = None
if keyboard_template_func:
keyboard_func = keyboard_template_func(a_Item[0])
return simple_message.WorkFuncResult(msg, photo_id = a_Item[3], item_access = a_Item[4], keyboard_func = keyboard_func)
return ShowMessage return ShowMessage
def SimpleMessageTemplate(a_StringMessage): def SimpleMessageTemplate(a_StringMessage):
@ -294,13 +306,15 @@ def RegisterHandlers(dp : Dispatcher):
bd_item_view.LastSelectAndShowBDItemRegisterHandlers(dp, \ bd_item_view.LastSelectAndShowBDItemRegisterHandlers(dp, \
a_Prefix, parent_id_field, \ a_Prefix, parent_id_field, \
table_name, key_name, \ table_name, key_name, \
ShowMessageTemplate(need_open_message), \ ShowMessageTemplate(need_open_message, GetViewItemInlineKeyboardTemplate), \
GetButtonNameAndKeyValueAndAccess, \ GetButtonNameAndKeyValueAndAccess, \
select_need_message, \ select_need_message, \
GetAccess, \ GetAccess, \
defaul_keyboard_func, \ defaul_keyboard_func, \
access_mode = user_access.AccessMode.VIEW\ access_mode = user_access.AccessMode.VIEW\
) )
global select_needs_prefix
select_needs_prefix = a_Prefix
# Удаление потребностей # Удаление потребностей
a_Prefix = RegisterSelectParent(del_need_button_name, user_access.AccessMode.DELETE) a_Prefix = RegisterSelectParent(del_need_button_name, user_access.AccessMode.DELETE)

17
bot_modules/projects.py

@ -181,6 +181,14 @@ def GetStartProjectKeyboardButtons(a_Message, a_UserGroups):
mods = [start, tasks, needs, comments] mods = [start, tasks, needs, comments]
return keyboard.MakeKeyboard(keyboard.GetButtons(mods) + cur_buttons, a_UserGroups) return keyboard.MakeKeyboard(keyboard.GetButtons(mods) + cur_buttons, a_UserGroups)
def GetViewItemInlineKeyboardTemplate(a_ItemID):
def GetViewItemInlineKeyboard(a_Message, a_UserGroups):
cur_buttons = [
keyboard.InlineButton(tasks.list_task_button_name, tasks.select_tasks_prefix, a_ItemID, GetAccess(), user_access.AccessMode.VIEW),
]
return keyboard.MakeInlineKeyboard(cur_buttons, a_UserGroups)
return GetViewItemInlineKeyboard
# --------------------------------------------------------- # ---------------------------------------------------------
# Обработка сообщений # Обработка сообщений
@ -192,7 +200,7 @@ def GetButtonNameAndKeyValueAndAccess(a_Item):
# projectName projectID projectAccess # projectName projectID projectAccess
return a_Item[1], a_Item[0], a_Item[4] return a_Item[1], a_Item[0], a_Item[4]
def ShowMessageTemplate(a_StringMessage): def ShowMessageTemplate(a_StringMessage, keyboard_template_func = None):
async def ShowMessage(a_CallbackQuery : types.CallbackQuery, a_Item): async def ShowMessage(a_CallbackQuery : types.CallbackQuery, a_Item):
if (len(a_Item) < 6): if (len(a_Item) < 6):
return simple_message.WorkFuncResult(error_find_proj_message) return simple_message.WorkFuncResult(error_find_proj_message)
@ -202,7 +210,10 @@ def ShowMessageTemplate(a_StringMessage):
replace(f'#{desc_field}', a_Item[2]).\ replace(f'#{desc_field}', a_Item[2]).\
replace(f'#{create_datetime_field}', a_Item[5]).\ replace(f'#{create_datetime_field}', a_Item[5]).\
replace(f'#{access_field}', a_Item[4]) replace(f'#{access_field}', a_Item[4])
return simple_message.WorkFuncResult(msg, photo_id = a_Item[3], item_access = a_Item[4]) keyboard_func = None
if keyboard_template_func:
keyboard_func = keyboard_template_func(a_Item[0])
return simple_message.WorkFuncResult(msg, photo_id = a_Item[3], item_access = a_Item[4], keyboard_func = keyboard_func)
return ShowMessage return ShowMessage
def SimpleMessageTemplate(a_StringMessage): def SimpleMessageTemplate(a_StringMessage):
@ -257,7 +268,7 @@ def RegisterHandlers(dp : Dispatcher):
# Список проектов # Список проектов
dp.register_message_handler(simple_message.SimpleMessageTemplate(ProjectsOpen, defaul_keyboard_func, GetAccess), text = projects_button_name) dp.register_message_handler(simple_message.SimpleMessageTemplate(ProjectsOpen, defaul_keyboard_func, GetAccess), text = projects_button_name)
bd_item_view.FirstSelectAndShowBDItemRegisterHandlers(dp, list_project_button_name, table_name, key_name, ShowMessageTemplate(project_open_message), GetButtonNameAndKeyValueAndAccess, select_project_message, GetAccess, defaul_keyboard_func) bd_item_view.FirstSelectAndShowBDItemRegisterHandlers(dp, list_project_button_name, table_name, key_name, ShowMessageTemplate(project_open_message, GetViewItemInlineKeyboardTemplate), GetButtonNameAndKeyValueAndAccess, select_project_message, GetAccess, defaul_keyboard_func)
# Удаление проекта # Удаление проекта
bd_item_delete.DeleteBDItemRegisterHandlers(dp, None, bd_item.GetCheckForTextFunc(del_project_button_name), table_name, key_name, None, ProjectPreDelete, ProjectPostDelete, GetButtonNameAndKeyValueAndAccess, select_project_message, GetAccess, defaul_keyboard_func) bd_item_delete.DeleteBDItemRegisterHandlers(dp, None, bd_item.GetCheckForTextFunc(del_project_button_name), table_name, key_name, None, ProjectPreDelete, ProjectPostDelete, GetButtonNameAndKeyValueAndAccess, select_project_message, GetAccess, defaul_keyboard_func)

21
bot_modules/tasks.py

@ -59,6 +59,8 @@ init_bd_cmds = [f'''CREATE TABLE IF NOT EXISTS {table_name}(
f"INSERT OR IGNORE INTO module_access (modName, modAccess, itemDefaultAccess) VALUES ('{module_name}', '{user_access.user_access_group_new}=va', '{user_access.user_access_group_new}=va');" f"INSERT OR IGNORE INTO module_access (modName, modAccess, itemDefaultAccess) VALUES ('{module_name}', '{user_access.user_access_group_new}=va', '{user_access.user_access_group_new}=va');"
] ]
select_tasks_prefix = ''
# --------------------------------------------------------- # ---------------------------------------------------------
# Сообщения # Сообщения
@ -187,6 +189,14 @@ def GetStartTaskKeyboardButtons(a_Message, a_UserGroups):
mods = [start, projects, needs, comments] mods = [start, projects, needs, comments]
return keyboard.MakeKeyboard(keyboard.GetButtons(mods) + cur_buttons, a_UserGroups) return keyboard.MakeKeyboard(keyboard.GetButtons(mods) + cur_buttons, a_UserGroups)
def GetViewItemInlineKeyboardTemplate(a_ItemID):
def GetViewItemInlineKeyboard(a_Message, a_UserGroups):
cur_buttons = [
keyboard.InlineButton(needs.list_need_button_name, needs.select_needs_prefix, a_ItemID, GetAccess(), user_access.AccessMode.VIEW),
]
return keyboard.MakeInlineKeyboard(cur_buttons, a_UserGroups)
return GetViewItemInlineKeyboard
# --------------------------------------------------------- # ---------------------------------------------------------
# Обработка сообщений # Обработка сообщений
@ -198,7 +208,7 @@ def GetButtonNameAndKeyValueAndAccess(a_Item):
# taskName taskID taskAccess # taskName taskID taskAccess
return a_Item[1], a_Item[0], a_Item[4] return a_Item[1], a_Item[0], a_Item[4]
def ShowMessageTemplate(a_StringMessage): def ShowMessageTemplate(a_StringMessage, keyboard_template_func = None):
async def ShowMessage(a_CallbackQuery : types.CallbackQuery, a_Item): async def ShowMessage(a_CallbackQuery : types.CallbackQuery, a_Item):
if (len(a_Item) < 6): if (len(a_Item) < 6):
return simple_message.WorkFuncResult(error_find_proj_message) return simple_message.WorkFuncResult(error_find_proj_message)
@ -208,7 +218,10 @@ def ShowMessageTemplate(a_StringMessage):
replace(f'#{desc_field}', a_Item[2]).\ replace(f'#{desc_field}', a_Item[2]).\
replace(f'#{create_datetime_field}', a_Item[5]).\ replace(f'#{create_datetime_field}', a_Item[5]).\
replace(f'#{access_field}', a_Item[4]) replace(f'#{access_field}', a_Item[4])
return simple_message.WorkFuncResult(msg, photo_id = a_Item[3], item_access = a_Item[4]) keyboard_func = None
if keyboard_template_func:
keyboard_func = keyboard_template_func(a_Item[0])
return simple_message.WorkFuncResult(msg, photo_id = a_Item[3], item_access = a_Item[4], keyboard_func = keyboard_func)
return ShowMessage return ShowMessage
def SimpleMessageTemplate(a_StringMessage): def SimpleMessageTemplate(a_StringMessage):
@ -280,13 +293,15 @@ def RegisterHandlers(dp : Dispatcher):
bd_item_view.LastSelectAndShowBDItemRegisterHandlers(dp, \ bd_item_view.LastSelectAndShowBDItemRegisterHandlers(dp, \
a_Prefix, parent_id_field, \ a_Prefix, parent_id_field, \
table_name, key_name, \ table_name, key_name, \
ShowMessageTemplate(task_open_message), \ ShowMessageTemplate(task_open_message, GetViewItemInlineKeyboardTemplate), \
GetButtonNameAndKeyValueAndAccess, \ GetButtonNameAndKeyValueAndAccess, \
select_task_message, \ select_task_message, \
GetAccess, \ GetAccess, \
defaul_keyboard_func, \ defaul_keyboard_func, \
access_mode = user_access.AccessMode.VIEW\ access_mode = user_access.AccessMode.VIEW\
) )
global select_tasks_prefix
select_tasks_prefix = a_Prefix
# Удаление задачи # Удаление задачи
a_Prefix = RegisterSelectParent(del_task_button_name, user_access.AccessMode.DELETE) a_Prefix = RegisterSelectParent(del_task_button_name, user_access.AccessMode.DELETE)

18
bot_sys/keyboard.py

@ -27,7 +27,7 @@ def Chunks(a_List, a_ChunkSize):
for i in range(0, len(a_List), a_ChunkSize): for i in range(0, len(a_List), a_ChunkSize):
yield a_List[i: i + a_ChunkSize] yield a_List[i: i + a_ChunkSize]
def GetKeyInRowCount(a_AllKeyCount): def GetButtonInRowCount(a_AllKeyCount):
return min(max(int(math.sqrt(a_AllKeyCount) // 1), 1), 4) return min(max(int(math.sqrt(a_AllKeyCount) // 1), 1), 4)
def MakeKeyboard(a_ButtonList : [ButtonWithAccess], a_UserGroups): def MakeKeyboard(a_ButtonList : [ButtonWithAccess], a_UserGroups):
@ -35,7 +35,7 @@ def MakeKeyboard(a_ButtonList : [ButtonWithAccess], a_UserGroups):
for b in a_ButtonList: for b in a_ButtonList:
if user_access.CheckAccessString(b.access_string, a_UserGroups, b.access_mode): if user_access.CheckAccessString(b.access_string, a_UserGroups, b.access_mode):
buttons += [types.KeyboardButton(b.label)] buttons += [types.KeyboardButton(b.label)]
step = GetKeyInRowCount(len(buttons)) step = GetButtonInRowCount(len(buttons))
key = types.ReplyKeyboardMarkup(keyboard=Chunks(buttons, step), resize_keyboard = True) key = types.ReplyKeyboardMarkup(keyboard=Chunks(buttons, step), resize_keyboard = True)
return key return key
@ -46,16 +46,20 @@ def MakeKeyboardForMods(a_ModList, a_UserGroups):
buttons = GetButtons(a_ModList) buttons = GetButtons(a_ModList)
return MakeKeyboard(buttons, a_UserGroups) return MakeKeyboard(buttons, a_UserGroups)
class Button: class InlineButton:
def __init__(self, a_Label, a_CallBackData): def __init__(self, a_Label, a_CallBackPrefix, a_CallBackData, a_AccessString, a_AccessMode):
self.label = a_Label self.label = a_Label
self.callback_prefix = a_CallBackPrefix
self.callback_data = str(a_CallBackData) self.callback_data = str(a_CallBackData)
self.access_string = a_AccessString
self.access_mode = a_AccessMode
def MakeInlineKeyboard(a_ButtonList : [Button], a_CallBackPrefix : str): def MakeInlineKeyboard(a_ButtonList : [InlineButton], a_UserGroups):
buttons = [] buttons = []
for b in a_ButtonList: for b in a_ButtonList:
buttons += [types.InlineKeyboardButton(text = b.label, callback_data = f'{a_CallBackPrefix}{b.callback_data}')] if user_access.CheckAccessString(b.access_string, a_UserGroups, b.access_mode):
step = GetKeyInRowCount(len(buttons)) buttons += [types.InlineKeyboardButton(text = b.label, callback_data = f'{b.callback_prefix}{b.callback_data}')]
step = GetButtonInRowCount(len(buttons))
inline_keyboard = InlineKeyboardMarkup(inline_keyboard=Chunks(buttons, step)) inline_keyboard = InlineKeyboardMarkup(inline_keyboard=Chunks(buttons, step))
return inline_keyboard return inline_keyboard

6
template/bd_item_select.py

@ -23,10 +23,10 @@ def GetBDItemsListKeyboardButtonsTemplate(a_TableName : str, a_ParentIDFieldName
bname, key_value, access = a_GetButtonNameAndKeyValueAndAccessFunc(t) bname, key_value, access = a_GetButtonNameAndKeyValueAndAccessFunc(t)
if access is None: if access is None:
access = '' access = ''
if not bname is None and user_access.CheckAccessString(access, a_UserGroups, access_mode): if bname:
b = keyboard.Button(bname, key_value) b = keyboard.InlineButton(bname, a_NextPrefix, key_value, access, access_mode)
items_button_list += [b] items_button_list += [b]
return keyboard.MakeInlineKeyboard(items_button_list, a_NextPrefix) return keyboard.MakeInlineKeyboard(items_button_list, a_UserGroups)
return GetBDItemsListKeyboardButtons return GetBDItemsListKeyboardButtons
def SelectDBItemTemplate(a_TableName : str, a_ParentIDFieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_PrevPrefix, a_NextPrefix, access_mode = user_access.AccessMode.VIEW): def SelectDBItemTemplate(a_TableName : str, a_ParentIDFieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_PrevPrefix, a_NextPrefix, access_mode = user_access.AccessMode.VIEW):

Loading…
Cancel
Save