Feat(SQL, UI): 1. Dog Command Links page completed with get + set functionality. \n 2. Commands page and Command Categories page completed with get + set functionality.
This commit is contained in:
@@ -14,9 +14,9 @@ Datastore for Users
|
||||
# from routes import bp_home
|
||||
import dog_training.lib.argument_validation as av
|
||||
from dog_training.business_objects.dog.command import Command, Command_Temp
|
||||
from dog_training.business_objects.dog.command_category import Command_Category
|
||||
from dog_training.business_objects.dog.command_category import Command_Category, Command_Category_Temp
|
||||
from dog_training.business_objects.dog.dog import Dog
|
||||
from dog_training.business_objects.dog.dog_command_link import Dog_Command_Link
|
||||
from dog_training.business_objects.dog.dog_command_link import Dog_Command_Link, Dog_Command_Link_Temp
|
||||
from dog_training.business_objects.sql_error import SQL_Error
|
||||
from dog_training.datastores.datastore_base import DataStore_Base
|
||||
from dog_training.helpers.helper_app import Helper_App
|
||||
@@ -95,6 +95,8 @@ class DataStore_Dog(DataStore_Base):
|
||||
command_category_indexes[new_command_category.id_command_category] = len(command_categories)
|
||||
command_categories.append(new_command_category)
|
||||
|
||||
Helper_App.console_log(f'command_category_indexes: {command_category_indexes}')
|
||||
|
||||
# Commands
|
||||
cursor.nextset()
|
||||
result_set_1 = cursor.fetchall()
|
||||
@@ -104,6 +106,8 @@ class DataStore_Dog(DataStore_Base):
|
||||
for row in result_set_1:
|
||||
new_command = Command.from_db_command(row)
|
||||
command_indexes[new_command.id_command] = len(commands)
|
||||
index_command_category = command_category_indexes[new_command.id_command_category]
|
||||
new_command.command_category = command_categories[index_command_category]
|
||||
commands.append(new_command)
|
||||
|
||||
# Errors
|
||||
@@ -158,6 +162,50 @@ class DataStore_Dog(DataStore_Base):
|
||||
|
||||
return dog_command_links, errors
|
||||
|
||||
@classmethod
|
||||
def save_dog_command_links(cls, comment, links):
|
||||
_m = f'{cls}.save_dog_command_links'
|
||||
av.val_str(comment, 'comment', _m)
|
||||
|
||||
guid = Helper_DB_MySQL.create_guid_str()
|
||||
now = datetime.now()
|
||||
user = cls.get_user_session()
|
||||
|
||||
Helper_App.console_log(f'saving links: {links}')
|
||||
|
||||
rows = []
|
||||
for link in links:
|
||||
row = Dog_Command_Link_Temp.from_dog_command_link(link)
|
||||
row.guid = guid
|
||||
rows.append(row)
|
||||
|
||||
cls.upload_bulk(Dog_Command_Link_Temp.__tablename__, rows, 1000)
|
||||
|
||||
Helper_App.console_log('Links uploaded')
|
||||
|
||||
argument_dict_list = {
|
||||
'a_comment': comment,
|
||||
'a_guid': guid,
|
||||
'a_id_user': user.id_user,
|
||||
'a_debug': 0
|
||||
}
|
||||
result = cls.db_procedure_execute('p_dog_save_dog_command_link', argument_dict_list)
|
||||
|
||||
Helper_App.console_log('Dog Command Links saved')
|
||||
|
||||
# Errors
|
||||
cursor = result.cursor
|
||||
cursor.nextset()
|
||||
result_set_e = cursor.fetchall()
|
||||
errors = []
|
||||
if len(result_set_e) > 0:
|
||||
errors = [SQL_Error.from_db_record(row) for row in result_set_e]
|
||||
for error in errors:
|
||||
Helper_App.console_log(f"Error [{error.code}]: {error.msg}")
|
||||
|
||||
cls.db_cursor_clear(cursor)
|
||||
return errors
|
||||
|
||||
@classmethod
|
||||
def save_commands(cls, comment, commands):
|
||||
_m = f'{cls}.save_commands'
|
||||
@@ -201,3 +249,50 @@ class DataStore_Dog(DataStore_Base):
|
||||
|
||||
cls.db_cursor_clear(cursor)
|
||||
return errors
|
||||
|
||||
@classmethod
|
||||
def save_command_categories(cls, comment, command_categories):
|
||||
_m = f'{cls}.save_command_categories'
|
||||
av.val_str(comment, 'comment', _m)
|
||||
|
||||
guid = Helper_DB_MySQL.create_guid_str()
|
||||
now = datetime.now()
|
||||
user = cls.get_user_session()
|
||||
|
||||
Helper_App.console_log(f'saving command categories: {command_categories}')
|
||||
|
||||
rows = []
|
||||
for command_category in command_categories:
|
||||
row = Command_Category_Temp.from_command_category(command_category)
|
||||
row.guid = guid
|
||||
rows.append(row)
|
||||
|
||||
cls.upload_bulk(Command_Category_Temp.__tablename__, rows, 1000)
|
||||
|
||||
Helper_App.console_log('Commands uploaded')
|
||||
|
||||
argument_dict_list = {
|
||||
'a_comment': comment,
|
||||
'a_guid': guid,
|
||||
'a_id_user': user.id_user,
|
||||
'a_debug': 0
|
||||
}
|
||||
result = cls.db_procedure_execute('p_dog_save_command_category', argument_dict_list)
|
||||
|
||||
Helper_App.console_log('Commands saved')
|
||||
|
||||
# Errors
|
||||
cursor = result.cursor
|
||||
cursor.nextset()
|
||||
result_set_e = cursor.fetchall()
|
||||
errors = []
|
||||
if len(result_set_e) > 0:
|
||||
errors = [SQL_Error.from_db_record(row) for row in result_set_e]
|
||||
for error in errors:
|
||||
Helper_App.console_log(f"Error [{error.code}]: {error.msg}")
|
||||
|
||||
cls.db_cursor_clear(cursor)
|
||||
return errors
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user