Browse Source

Переделано добавление элементов на универсальный код.

pull/3/head
Alexei 2 years ago
parent
commit
a8ff8c2455
  1. 36
      bot_modules/mod_table_operate.py
  2. 4
      bot_modules/orders.py
  3. 13
      bot_modules/user_in_groups.py
  4. 2
      bot_sys/bd_table.py

36
bot_modules/mod_table_operate.py

@ -217,21 +217,37 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
create_datetime_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.CREATE_DATE)
parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID)
res, error = None, None
def_access = access_utils.GetItemDefaultAccessForModule(self.m_Bot, self.GetName())
#TODO сделать список полей, чтобы запрос генерировался автоматически.
if parent_id_field:
res, error = self.m_Bot.SQLRequest(f'INSERT INTO {table_name}({photo_field}, {name_field}, {desc_field}, {access_field}, {parent_id_field}, {create_datetime_field}) VALUES(?, ?, ?, ?, ?, {bot_bd.GetBDDateTimeNow()})',
commit = True, return_error = True, param = (a_ItemData[photo_field], a_ItemData[name_field], a_ItemData[desc_field], def_access + f";{a_UserID}=+", a_ItemData[parent_id_field]))
else:
res, error = self.m_Bot.SQLRequest(f'INSERT INTO {table_name}({photo_field}, {name_field}, {desc_field}, {access_field}, {create_datetime_field}) VALUES(?, ?, ?, ?, {bot_bd.GetBDDateTimeNow()})',
commit = True, return_error = True, param = (a_ItemData[photo_field], a_ItemData[name_field], a_ItemData[desc_field], def_access + f";{a_UserID}=+"))
fields = []
values = []
param = ()
for f in self.m_Table.GetFields():
d = f.m_Destiny
n = f.m_Name
if d == bd_table.TableFieldDestiny.KEY:
continue
elif d == bd_table.TableFieldDestiny.CREATE_DATE:
fields += [n]
values += [bot_bd.GetBDDateTimeNow()]
elif d == bd_table.TableFieldDestiny.ACCESS:
fields += [n]
values += ['?']
param += (def_access + f";{a_UserID}=+", )
else:
fields += [n]
values += ['?']
param += (a_ItemData[n], )
request = f'INSERT INTO {table_name}({",".join(fields)}) VALUES({",".join(values)})'
print('request', request, param)
res, error = self.m_Bot.SQLRequest(request, commit = True, return_error = True, param = param)
self.OnChange()
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}. Ошибка добавления записи в таблицу {request} {param}.')
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}. Добавлена запись в таблицу {request} {param}.')
return res, error

4
bot_modules/orders.py

@ -26,7 +26,7 @@ name_field = 'orderName'
desc_field = 'orderDesc'
photo_field = 'orderPhoto'
status_field = 'orderStatus'
address_field = 'orderAddres'
address_field = 'orderAddress'
access_field = 'orderAccess'
create_datetime_field = 'orderCreateDateTime'
parent_id_field = 'userID'
@ -201,6 +201,8 @@ class ModuleOrders(mod_table_operate.TableOperateModule):
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
a_ItemData[status_field] = str(OrderStatus.NEW)
a_ItemData[address_field] = ''
return super().AddBDItemFunc(a_ItemData, a_UserID)
def GetStartKeyboardButtons(self, a_Message, a_UserGroups):

13
bot_modules/user_in_groups.py

@ -118,19 +118,6 @@ class ModuleUserInGroups(mod_table_operate.TableOperateModule):
]
return t_buttons + keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups)
def AddBDItemFunc(self, a_ItemData, a_UserID):
def_access = access_utils.GetItemDefaultAccessForModule(self.m_Bot, self.GetName())
res, error = self.m_Bot.SQLRequest(f'INSERT INTO {table_name}({name_field}, {access_field}, {parent_id_field}, {create_datetime_field}) VALUES(?, ?, ?, {bot_bd.GetBDDateTimeNow()})',
commit = True, return_error = True, param = (a_ItemData[name_field], def_access + f";{a_UserID}=+", a_ItemData[parent_id_field]))
self.OnChange()
if error:
self.m_Log.Error(f'Пользоватлель {a_UserID}. Ошибка добавления записи в таблицу {table_name} ({a_ItemData[name_field]}, {def_access}).')
else:
self.m_Log.Success(f'Пользоватлель {a_UserID}. Добавлена запись в таблицу {table_name} ({a_ItemData[name_field]}, {def_access}).')
return res, error
def RegisterHandlers(self):
super().RegisterHandlers()
GetButtonNameAndKeyValueAndAccess = self.m_GetButtonNameAndKeyValueAndAccessFunc

2
bot_sys/bd_table.py

@ -39,7 +39,7 @@ class Table:
return self.m_TableName
def GetFields(self):
return self.TableFieldType
return self.m_Fields
def GetFieldsCount(self):
return len(self.m_Fields)

Loading…
Cancel
Save