Browse Source

Исправление списка заказов

pull/3/head
Alexei 2 years ago
parent
commit
f6d60532cf
  1. 11
      bot_modules/mod_table_operate.py
  2. 33
      bot_modules/orders.py
  3. 4
      main.py

11
bot_modules/mod_table_operate.py

@ -23,6 +23,7 @@ class ButtonNames(Enum):
EDIT_ACCESS = auto()
EDIT_DEFAULT_ACCESS = auto()
EDIT_ADDRESS = auto()
EDIT_STATUS = auto()
DEL = auto()
class Messages(Enum):
@ -41,6 +42,7 @@ class Messages(Enum):
EDIT_ACCESS = auto()
EDIT_DEFAULT_ACCESS = auto()
EDIT_ADDRESS = auto()
EDIT_STATUS = auto()
SUCCESS_EDIT = auto()
SELECT_TO_DELETE = auto()
SUCCESS_DELETE = auto()
@ -53,6 +55,7 @@ class FSMs(Enum):
EDIT_ACCESS = auto()
EDIT_DEFAULT_ACCESS = auto()
EDIT_ADDRESS = auto()
EDIT_STATUS = auto()
create_fsms_cmd = '''
class FSMCreate{a_ModName}(StatesGroup):
@ -78,6 +81,9 @@ class FSMEdit{a_ModName}DefaultAccessItem(StatesGroup):
class FSMEdit{a_ModName}AddressItem(StatesGroup):
item_field = State()
class FSMEdit{a_ModName}StatusItem(StatesGroup):
item_field = State()
fsm = {
FSMs.CREATE: FSMCreate{a_ModName},
FSMs.EDIT_NAME: FSMEdit{a_ModName}NameItem,
@ -86,6 +92,7 @@ fsm = {
FSMs.EDIT_ACCESS: FSMEdit{a_ModName}AccessItem,
FSMs.EDIT_DEFAULT_ACCESS: FSMEdit{a_ModName}DefaultAccessItem,
FSMs.EDIT_ADDRESS: FSMEdit{a_ModName}AddressItem,
FSMs.EDIT_STATUS: FSMEdit{a_ModName}StatusItem,
}
'''
@ -152,6 +159,8 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_DESC), user_access.AccessMode.DELETE, self.GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_ACCESS), user_access.AccessMode.DELETE, self.GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_DEFAULT_ACCESS), user_access.AccessMode.EDIT, self.GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_ADDRESS), user_access.AccessMode.EDIT, self.GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_STATUS), user_access.AccessMode.EDIT, self.GetAccess()),
]
return mod_buttons + keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups)
@ -414,6 +423,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
)
address_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.ADDRESS)
status_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.STATUS)
self.RegisterEdit(self.GetButton(ButtonNames.EDIT_NAME), self.GetFSM(FSMs.EDIT_NAME), self.GetMessage(Messages.EDIT_NAME), name_field, bd_item.FieldType.text)
self.RegisterEdit(self.GetButton(ButtonNames.EDIT_DESC), self.GetFSM(FSMs.EDIT_DESC), self.GetMessage(Messages.EDIT_DESC), desc_field, bd_item.FieldType.text)
@ -421,6 +431,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
self.RegisterEdit(self.GetButton(ButtonNames.EDIT_ACCESS), self.GetFSM(FSMs.EDIT_ACCESS), self.GetMessage(Messages.EDIT_ACCESS), access_field, bd_item.FieldType.text)
self.RegisterEdit(self.GetButton(ButtonNames.EDIT_DEFAULT_ACCESS), self.GetFSM(FSMs.EDIT_DEFAULT_ACCESS), self.GetMessage(Messages.EDIT_DEFAULT_ACCESS), def_access_field, bd_item.FieldType.text)
self.RegisterEdit(self.GetButton(ButtonNames.EDIT_ADDRESS), self.GetFSM(FSMs.EDIT_ADDRESS), self.GetMessage(Messages.EDIT_ADDRESS), address_field, bd_item.FieldType.text)
self.RegisterEdit(self.GetButton(ButtonNames.EDIT_STATUS), self.GetFSM(FSMs.EDIT_STATUS), self.GetMessage(Messages.EDIT_STATUS), status_field, bd_item.FieldType.text)
def OnChange(self):
pass

33
bot_modules/orders.py

@ -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, bd_item_view
from template import bd_item_select, bd_item_view, bd_item
from enum import Enum
from enum import auto
@ -61,6 +61,7 @@ button_names = {
mod_table_operate.ButtonNames.EDIT_NAME: "≂ Изменить название в заказе",
mod_table_operate.ButtonNames.EDIT_DESC: "𝌴 Изменить описание в заказе",
mod_table_operate.ButtonNames.EDIT_ADDRESS: "𝌴 Изменить адрес в заказе",
mod_table_operate.ButtonNames.EDIT_STATUS: "𝌴 Изменить статус в заказе",
mod_table_operate.ButtonNames.EDIT_ACCESS: "✋ Изменить доступ к заказу",
mod_table_operate.ButtonNames.DEL: "❌ Удалить заказ",
}
@ -132,6 +133,12 @@ messages = {
Введите новый адрес доставки заказа (укажите, кто, когда и где его сможет забрать):
''',
mod_table_operate.Messages.EDIT_STATUS: f'''
Текущий статус заказа:
#{status_field}
Введите новый статус заказа:
''',
mod_table_operate.Messages.EDIT_ACCESS: f'''
Текущий доступ к заказу:
#{access_field}
@ -149,18 +156,17 @@ messages = {
}
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):
user_id = str(a_Message.from_user.id)
return a_GetItemsFunc(a_Message, a_UserGroups, a_ParentID)(user_id)
return GetBDItem
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 GetBDItems
return items
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):
@ -172,7 +178,10 @@ class DBItemForUserSelectSource(bd_item_select.DBItemSelectSource):
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)
return GetBDItemsForUserTemplate(self.m_Bot, self.m_TableName, self.m_ParentIDFieldName)
def IsFirst(self):
return True
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):

4
main.py

@ -134,8 +134,8 @@ for m in test_mods:
m.Test()
if __name__ == '__main__':
# os.system('clear')
# os.system('cls')
#os.system('clear')
#os.system('cls')
g_Log.Success(log_start_message)
g_Bot.StartPolling()

Loading…
Cancel
Save