@ -5,7 +5,7 @@
from bot_sys import bot_bd , keyboard , user_access , bd_table
from bot_modules import mod_table_operate , mod_simple_message
from template import bd_item_select
from template import bd_item_select , bd_item_view
from enum import Enum
from enum import auto
@ -49,21 +49,18 @@ init_access = f'{user_access.user_access_group_new}=va'
# Сообщения и кнопки
class ButtonNames ( Enum ) :
LIST_ALL = auto ( )
EDIT_ADDRESS = auto ( )
class Messages ( Enum ) :
EDIT_ADDRESS = auto ( )
LIST_CURRENT = auto ( )
button_names = {
mod_simple_message . ButtonNames . START : " 🛒 Заказы" ,
mod_table_operate . ButtonNames . LIST : " 📃 Список текущи х заказов " ,
ButtonNames . LIST_ALL : " 📃 Список все х заказов " ,
mod_table_operate . ButtonNames . LIST : " 📃 Список всех заказов " ,
ButtonNames . LIST_CURRENT : " 📃 Список текущи х заказов " ,
mod_table_operate . ButtonNames . ADD : " ✅ Добавить заказ " ,
mod_table_operate . ButtonNames . EDIT : " 🛠 Редактировать заказ " ,
mod_table_operate . ButtonNames . EDIT_PHOTO : " ☐ Изменить изображение в заказе " ,
mod_table_operate . ButtonNames . EDIT_NAME : " ≂ Изменить название в заказе " ,
mod_table_operate . ButtonNames . EDIT_DESC : " 𝌴 Изменить описание в заказе " ,
mod_table_operate . ButtonNames . EDIT_ADDRESS : " 𝌴 Изменить адрес в заказе " ,
mod_table_operate . ButtonNames . EDIT_ACCESS : " ✋ Изменить доступ к заказу " ,
mod_table_operate . ButtonNames . DEL : " ❌ Удалить заказ " ,
}
@ -129,7 +126,7 @@ messages = {
Введите новое описание заказа :
''' ,
Messages . EDIT_ADDRESS : f '''
mod_table_operate . Messages . EDIT_ADDRESS : f '''
Текущий адрес заказа :
#{desc_field}
@ -151,6 +148,11 @@ messages = {
mod_table_operate . Messages . SUCCESS_DELETE : ''' ✅ Заказ успешно удалён! ''' ,
}
def GetCurItemsTemplate ( a_Bot , a_TableName , a_UserIDFieldName , a_StatusFieldName ) :
def GetBDItem ( a_KeyValue ) :
return a_Bot . SQLRequest ( f ' SELECT * FROM { a_TableName } WHERE { a_UserIDFieldName } = ? AND { a_StatusFieldName } != ? ' , param = ( [ a_KeyValue , OrderStatus . FINISH ] ) )
return GetBDItem
def GetBDItemsForUserTemplate ( a_GetItemsFunc ) :
def GetBDItems ( a_Message , a_UserGroups , a_ParentID ) :
def GetBDItem ( a_KeyValue ) :
@ -162,8 +164,15 @@ def GetBDItemsForUserTemplate(a_GetItemsFunc):
return GetBDItems
class DBItemForUserSelectSource ( bd_item_select . DBItemSelectSource ) :
def __init__ ( self , a_Bot , a_TableName , a_ParentIDFieldName , a_PrevPrefix , a_ButtonName , a_OnlyCurent = False ) :
super ( ) . __init__ ( a_Bot , a_TableName , a_ParentIDFieldName , a_PrevPrefix , a_ButtonName )
self . m_OnlyCurent = a_OnlyCurent
def GetItemsFunc ( self ) :
return GetBDItemsForUserTemplate ( super ( ) . GetItemsFunc ( ) )
get_items_func = super ( ) . GetItemsFunc ( )
if self . m_OnlyCurent :
get_items_func = GetCurItemsTemplate ( self . m_Bot , self . m_TableName , self . m_ParentIDFieldName , status_field )
return GetBDItemsForUserTemplate ( get_items_func )
class ModuleOrders ( mod_table_operate . TableOperateModule ) :
def __init__ ( self , a_ParentModName , a_ChildModName , a_ChildModuleNameList , a_EditModuleNameList , a_Bot , a_ModuleAgregator , a_BotMessages , a_BotButtons , a_Log ) :
@ -176,4 +185,53 @@ class ModuleOrders(mod_table_operate.TableOperateModule):
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 )
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 )
def AddBDItemFunc ( self , a_ItemData , a_UserID ) :
parent_id_field = self . m_Table . GetFieldNameByDestiny ( bd_table . TableFieldDestiny . PARENT_ID )
a_ItemData [ parent_id_field ] = a_UserID
return super ( ) . AddBDItemFunc ( a_ItemData , a_UserID )
def GetStartKeyboardButtons ( self , a_Message , a_UserGroups ) :
parent_buttons = super ( ) . GetStartKeyboardButtons ( a_Message , a_UserGroups )
cur_buttons = [
keyboard . ButtonWithAccess ( self . GetButton ( ButtonNames . LIST_CURRENT ) , user_access . AccessMode . VIEW , self . GetAccess ( ) ) ,
]
return parent_buttons + keyboard . MakeButtons ( self . m_Bot , cur_buttons , a_UserGroups )
def RegisterHandlers ( self ) :
super ( ) . RegisterHandlers ( )
table_name = self . m_Table . GetName ( )
key_name = self . m_Table . GetFieldNameByDestiny ( bd_table . TableFieldDestiny . KEY )
def GetViewItemInlineKeyboardTemplate ( a_ItemID ) :
return self . GetViewItemInlineKeyboardTemplate ( a_ItemID )
GetButtonNameAndKeyValueAndAccess = self . m_GetButtonNameAndKeyValueAndAccessFunc
GetAccess = self . m_GetAccessFunc
default_keyboard_func = self . m_GetStartKeyboardButtonsFunc
# Список текущих, открытых заказов
a_ButtonName = self . GetButton ( ButtonNames . LIST_CURRENT )
if a_ButtonName :
a_Prefix = self . RegisterSelect ( a_ButtonName , user_access . AccessMode . VIEW , only_parent = True )
a_Prefix = bd_item_select . SelectRegisterHandlers ( self . m_Bot , \
self . SelectSourceForCurrentTemplate ( a_Prefix , a_ButtonName ) , \
GetButtonNameAndKeyValueAndAccess , \
self . GetMessage ( mod_table_operate . Messages . SELECT ) , \
GetAccess , \
access_mode = user_access . AccessMode . VIEW \
)
bd_item_view . ShowBDItemRegisterHandlers ( self . m_Bot , \
a_Prefix , \
table_name , \
key_name , \
self . ShowMessageTemplate ( self . GetMessage ( mod_table_operate . Messages . OPEN ) , GetViewItemInlineKeyboardTemplate ) , \
GetAccess , \
default_keyboard_func , \
access_mode = user_access . AccessMode . VIEW \
)