Browse Source

Включены заказы. Не работает добавление пока.

pull/3/head
Alexei 2 years ago
parent
commit
28e549de67
  1. 7
      bot_modules/mod_table_operate.py
  2. 22
      bot_modules/orders.py
  3. 7
      main.py
  4. 2
      template/bd_item_select.py

7
bot_modules/mod_table_operate.py

@ -239,15 +239,12 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
self.OnChange() self.OnChange()
if error: if error:
self.m_Log.Error(f'Пользоватлель {a_UserID}. Ошибка добавления записи в таблицу {table_name} ({a_ItemData[photo_field]}, {a_ItemData[name_field]}, {a_ItemData[desc_field]}, {def_access}).') self.m_Log.Error(f'Пользователь {a_UserID}. Ошибка добавления записи в таблицу {table_name} ({a_ItemData[photo_field]}, {a_ItemData[name_field]}, {a_ItemData[desc_field]}, {def_access}).')
else: else:
self.m_Log.Success(f'Пользоватлель {a_UserID}. Добавлена запись в таблицу {table_name} ({a_ItemData[photo_field]}, {a_ItemData[name_field]}, {a_ItemData[desc_field]}, {def_access}).') self.m_Log.Success(f'Пользователь {a_UserID}. Добавлена запись в таблицу {table_name} ({a_ItemData[photo_field]}, {a_ItemData[name_field]}, {a_ItemData[desc_field]}, {def_access}).')
return res, error return res, error
def SelectItemsTemplate(self):
return bd_item_select.GetBDItemsTemplate(self.m_Bot, self.m_Table.GetName(), self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID))
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)
return bd_item_select.DBItemSelectSource(self.m_Bot, self.m_Table.GetName(), parent_id_field, a_PrevPrefix, a_ButtonName) return bd_item_select.DBItemSelectSource(self.m_Bot, self.m_Table.GetName(), parent_id_field, a_PrevPrefix, a_ButtonName)

22
bot_modules/orders.py

@ -5,6 +5,7 @@
from bot_sys import bot_bd, keyboard, user_access, bd_table from bot_sys import bot_bd, keyboard, user_access, bd_table
from bot_modules import mod_table_operate, mod_simple_message from bot_modules import mod_table_operate, mod_simple_message
from template import bd_item_select
from enum import Enum from enum import Enum
from enum import auto from enum import auto
@ -55,7 +56,7 @@ class Messages(Enum):
EDIT_ADDRESS = auto() EDIT_ADDRESS = auto()
button_names = { button_names = {
mod_simple_message.ButtonNames.START: "👨👨👧👦 🛒 Заказы", mod_simple_message.ButtonNames.START: "🛒 Заказы",
mod_table_operate.ButtonNames.LIST: "📃 Список текущих заказов", mod_table_operate.ButtonNames.LIST: "📃 Список текущих заказов",
ButtonNames.LIST_ALL: "📃 Список всех заказов", ButtonNames.LIST_ALL: "📃 Список всех заказов",
mod_table_operate.ButtonNames.ADD: "✅ Добавить заказ", mod_table_operate.ButtonNames.ADD: "✅ Добавить заказ",
@ -150,12 +151,29 @@ messages = {
mod_table_operate.Messages.SUCCESS_DELETE: '''✅ Заказ успешно удалён!''', mod_table_operate.Messages.SUCCESS_DELETE: '''✅ Заказ успешно удалён!''',
} }
class ModuleProjects(mod_table_operate.TableOperateModule): 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
return items
return GetBDItems
class DBItemForUserSelectSource(bd_item_select.DBItemSelectSource):
def GetItemsFunc(self):
return GetBDItemsForUserTemplate(super().GetItemsFunc())
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): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log):
super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log)
def GetName(self): def GetName(self):
return module_name return module_name
def SelectSourceTemplate(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)

7
main.py

@ -6,6 +6,7 @@ import os
from bot_sys import config, log, aiogram_bot, bot_messages, bd_table, user_access from bot_sys import config, log, aiogram_bot, bot_messages, bd_table, user_access
from bot_modules import mod_agregator, start, profile, backup, users_groups_agregator, access, projects, tasks, needs, comments from bot_modules import mod_agregator, start, profile, backup, users_groups_agregator, access, projects, tasks, needs, comments
from bot_modules import languages, messages, buttons, users, groups, user_in_groups from bot_modules import languages, messages, buttons, users, groups, user_in_groups
from bot_modules import orders
log_start_message = 'Бот успешно запущен!' log_start_message = 'Бот успешно запущен!'
@ -34,6 +35,7 @@ mod_buttons_name = buttons.module_name
mod_users_name = users.module_name mod_users_name = users.module_name
mod_groups_name = groups.module_name mod_groups_name = groups.module_name
mod_user_in_groups_name = user_in_groups.module_name mod_user_in_groups_name = user_in_groups.module_name
mod_orders_name = orders.module_name
start_mod_list = [mod_start_name] start_mod_list = [mod_start_name]
mod_access = access.ModuleAccess(start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log) mod_access = access.ModuleAccess(start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log)
@ -87,6 +89,10 @@ child_mod_name_list = [mod_start_name]
mod_buttons = buttons.ModuleButtons(mod_languages_name, None, child_mod_name_list, start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log) mod_buttons = buttons.ModuleButtons(mod_languages_name, None, child_mod_name_list, start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log)
g_ModuleAgregator.AddModule(mod_buttons) g_ModuleAgregator.AddModule(mod_buttons)
child_mod_name_list = [mod_start_name]
mod_orders = orders.ModuleOrders(None, None, child_mod_name_list, start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log)
g_ModuleAgregator.AddModule(mod_orders)
child_mod_name_list = [ child_mod_name_list = [
mod_profile.GetName(), mod_profile.GetName(),
mod_backup.GetName(), mod_backup.GetName(),
@ -94,6 +100,7 @@ child_mod_name_list = [
mod_access.GetName(), mod_access.GetName(),
mod_project.GetName(), mod_project.GetName(),
mod_languages.GetName(), mod_languages.GetName(),
mod_orders.GetName(),
] ]
mod_start = start.ModuleStart(child_mod_name_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log) mod_start = start.ModuleStart(child_mod_name_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log)
g_ModuleAgregator.AddModule(mod_start) g_ModuleAgregator.AddModule(mod_start)

2
template/bd_item_select.py

@ -61,7 +61,7 @@ class ISelectSource(ABC):
def GetPrefixBase(self): def GetPrefixBase(self):
pass pass
class DBItemSelectSource: class DBItemSelectSource(ISelectSource):
def __init__(self, a_Bot, a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_ButtonName): def __init__(self, a_Bot, a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_ButtonName):
self.m_Bot = a_Bot self.m_Bot = a_Bot
self.m_TableName = a_TableName self.m_TableName = a_TableName

Loading…
Cancel
Save