Finally got Table column names in comment for table control custom procedure
This commit is contained in:
45
sm2gen.py
45
sm2gen.py
@@ -29,7 +29,7 @@ ini_file_path = os.path.expanduser("~/.smegit/conf")
|
||||
OPENAI_API_KEY = ""
|
||||
|
||||
# Configure the basic logging system
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
|
||||
# Create a logger
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -294,7 +294,20 @@ def get_db_fields():
|
||||
|
||||
def get_table_control_data():
|
||||
return find_values_with_key(json5_html_list, "TableControl")
|
||||
|
||||
|
||||
def extract_tables(json_data):
|
||||
result = {}
|
||||
# Iterate over the 'html' list in the JSON data
|
||||
for item in json_data.get('html', []):
|
||||
if isinstance(item, dict):
|
||||
for key, value in item.items():
|
||||
if isinstance(value, dict):
|
||||
if value.get('Type') == 'Table' and 'TableControl' in value:
|
||||
table_control = value['TableControl']
|
||||
columns = value.get('Columns', [])
|
||||
result[table_control] = {'columns': columns}
|
||||
|
||||
return result
|
||||
|
||||
def format_text(text):
|
||||
#
|
||||
@@ -558,7 +571,7 @@ if __name__ == "__main__":
|
||||
json5_html_list = json5_dict["html"]
|
||||
|
||||
# Identify message
|
||||
logger.info(f"\nGenerating mojo panels for {hl('PackageName')}")
|
||||
logger.info(f"Generating mojo panels for {hl('PackageName')}")
|
||||
logger.info("-----------------------------------")
|
||||
|
||||
# Routes for each panel
|
||||
@@ -586,17 +599,17 @@ if __name__ == "__main__":
|
||||
partial_files.append(check_file_version(
|
||||
target_directory_path + '_' + hl("prefix") + "_" + panel + ".html.ep",force_Files)
|
||||
)
|
||||
logger.info(f"Partial files to be created:{partial_files}")
|
||||
logger.debug(f"Partial files to be created:{partial_files}")
|
||||
lex_file = check_file_version(target_directory_path + hl("PackageName").lower() + "_en.lex",force_Files)
|
||||
logger.info(lex_file)
|
||||
tablecontrols = (
|
||||
get_table_control_data()
|
||||
) # arrays of hashes used to drive rows in tables
|
||||
|
||||
# logger.info(strVersion,tablecontrols,routes)
|
||||
|
||||
tablecontrols = extract_tables(json5_dict)
|
||||
# arrays of hashes used to drive rows in tables
|
||||
|
||||
# Generate controller file
|
||||
dbfields = [] #extract_input_fields(json5_dict, 'db') # Params which correspond to Db fields - TBD
|
||||
logger.debug(f"{tablecontrols}")
|
||||
logger.debug(f"{tablecontrols.items()}")
|
||||
#quit(1)
|
||||
try:
|
||||
controller_template = PageTemplateFile(
|
||||
"Templates/controller.pm.tem", CHAMELEON_DEBUG="true"
|
||||
@@ -604,7 +617,7 @@ if __name__ == "__main__":
|
||||
try:
|
||||
controller_perl = controller_template.render(
|
||||
version=strVersion,
|
||||
tablecontrols=tablecontrols,
|
||||
tablecontrols=tablecontrols.items(),
|
||||
dbfields=dbfields,
|
||||
**json5_dict,
|
||||
panels=routes,
|
||||
@@ -627,7 +640,11 @@ if __name__ == "__main__":
|
||||
#quit(0)
|
||||
try:
|
||||
custom_controller_perl = custom_controller_template.render(
|
||||
version=strVersion, panels=routes, tablecontrols=tablecontrols, fields=fields, dbfields=dbfields
|
||||
version=strVersion,
|
||||
panels=routes,
|
||||
tablecontrols=tablecontrols.items(),
|
||||
fields=fields,
|
||||
dbfields=dbfields
|
||||
)
|
||||
# We must be careful to not overwrite the custom file if the developer has already written to it - TBD
|
||||
with open(custom_controller_file, "w") as file:
|
||||
@@ -726,7 +743,7 @@ if __name__ == "__main__":
|
||||
class_name = html_Type.lower()[:4]+type_serial
|
||||
acc_css_entries += f".{class_name} {{}}\n"
|
||||
if not type_serial == "":
|
||||
print(html_control,html_Type,type_serial)
|
||||
logger.debug(f"{html_control},{html_Type},{type_serial}")
|
||||
try:
|
||||
simple_control_template = PageTemplate(html_controls[html_Type])
|
||||
try:
|
||||
@@ -764,7 +781,7 @@ if __name__ == "__main__":
|
||||
|
||||
# Create the css file (the header, followed by a dumy entry for each class created/used above)
|
||||
with open(css_file, "w") as file:
|
||||
file.write(f"/*\n Generated by SM2Gen version: {strVersion}\n*/\n")
|
||||
file.write(f"/*\nGenerated by SM2Gen version: {strVersion}\n*/\n")
|
||||
file.write(f".{hl('PackageName')}-panel {{}}\n")
|
||||
file.write(acc_css_entries);
|
||||
|
||||
|
Reference in New Issue
Block a user