mirror of
https://github.com/kevinveenbirkenbach/baserow-ifto.git
synced 2024-11-26 04:41:04 +01:00
Implemented matrix variable
This commit is contained in:
parent
e69fb4db04
commit
2d3905b354
@ -9,53 +9,47 @@ class MatrixBuilder:
|
|||||||
print(message)
|
print(message)
|
||||||
|
|
||||||
def build_multitable_matrix(self, tables_data):
|
def build_multitable_matrix(self, tables_data):
|
||||||
original_keys=list(tables_data.keys())
|
original_keys = list(tables_data.keys())
|
||||||
for table_name, table_rows in tables_data.copy().items():
|
matrix = {}
|
||||||
self.build_matrix(tables_data,table_name, table_rows)
|
for table_name, table_rows in tables_data.items():
|
||||||
|
matrix[table_name] = self.build_matrix(tables_data, table_name, table_rows.copy())
|
||||||
matrix={}
|
|
||||||
for key in original_keys:
|
|
||||||
matrix[key]=tables_data[key]
|
|
||||||
return matrix
|
return matrix
|
||||||
|
|
||||||
def build_matrix(self, tables_data, table_name, table_rows, reference_map={}):
|
def build_matrix(self, tables_data, table_name, table_rows, reference_map={}):
|
||||||
"""Build a matrix with linked rows filled recursively."""
|
"""Build a matrix with linked rows filled recursively."""
|
||||||
|
matrix = {table_name: table_rows}
|
||||||
reference_map_child = reference_map.copy()
|
reference_map_child = reference_map.copy()
|
||||||
self.process_link_fields(table_name, tables_data, reference_map_child)
|
self.process_link_fields(table_name, tables_data, reference_map_child)
|
||||||
self.fill_cells_with_related_content(tables_data,table_name, table_rows, reference_map_child)
|
self.fill_cells_with_related_content(tables_data, matrix, table_name, table_rows, reference_map_child)
|
||||||
|
return matrix[table_name]
|
||||||
|
|
||||||
return tables_data
|
def fill_cells_with_related_content(self, tables_data, matrix, table_name, table_rows, reference_map_child):
|
||||||
|
self.print_verbose_message(f"table_name: {table_name}")
|
||||||
def fill_cells_with_related_content(self, tables_data, table_name, table_rows, reference_map_child):
|
|
||||||
"""Fill cells with related content."""
|
|
||||||
for table_row in table_rows:
|
for table_row in table_rows:
|
||||||
self.print_verbose_message(f"table_row: {table_row}")
|
self.print_verbose_message(f"table_row: {table_row}")
|
||||||
for table_column_name, table_cell_content in table_row.items():
|
for table_column_name, table_cell_content in table_row.items():
|
||||||
self.print_verbose_message(f"table_cell_content {table_cell_content}")
|
self.print_verbose_message(f"table_cell_content {table_cell_content}")
|
||||||
if table_column_name in reference_map_child:
|
if table_column_name in reference_map_child:
|
||||||
|
|
||||||
link_row_table_id = reference_map_child[table_column_name]["link_row_table_id"]
|
link_row_table_id = reference_map_child[table_column_name]["link_row_table_id"]
|
||||||
self.print_verbose_message(f"link_row_table_id: {link_row_table_id}")
|
self.print_verbose_message(f"link_row_table_id: {link_row_table_id}")
|
||||||
|
|
||||||
link_row_related_field_id = reference_map_child[table_column_name]["link_row_related_field_id"]
|
link_row_related_field_id = reference_map_child[table_column_name]["link_row_related_field_id"]
|
||||||
self.print_verbose_message(f"link_row_related_field_id: {link_row_related_field_id}")
|
self.print_verbose_message(f"link_row_related_field_id: {link_row_related_field_id}")
|
||||||
# This could be wrong:
|
|
||||||
if link_row_related_field_id:
|
|
||||||
new_content = []
|
|
||||||
for entry_id, entry_content in table_cell_content:
|
|
||||||
self.print_verbose_message(f"entry_content {entry_content}")
|
|
||||||
|
|
||||||
related_cell_identifier = self.generate_related_cell_identifier(link_row_table_id, link_row_related_field_id, entry_id)
|
if not link_row_related_field_id:
|
||||||
self.print_verbose_message(f"related_cell_identifier: {related_cell_identifier}")
|
raise Exception("link_row_related_field_id has to be a positive number")
|
||||||
|
new_content = []
|
||||||
|
|
||||||
if related_cell_identifier in reference_map_child[table_column_name]["embeded"]:
|
for entry in table_cell_content:
|
||||||
self.print_verbose_message(f"Skipped {related_cell_identifier}. Already implemented")
|
self.print_verbose_message(f"entry: {entry}")
|
||||||
continue
|
related_cell_identifier = self.generate_related_cell_identifier(link_row_table_id, link_row_related_field_id, entry["id"])
|
||||||
|
self.print_verbose_message(f"related_cell_identifier: {related_cell_identifier}")
|
||||||
|
|
||||||
reference_map_child[table_column_name]["embeded"].append(related_cell_identifier)
|
if related_cell_identifier not in reference_map_child[table_column_name].get("embeded", []):
|
||||||
self.build_matrix(tables_data, link_row_table_id, tables_data[link_row_table_id], reference_map_child)
|
reference_map_child[table_column_name].setdefault("embeded", []).append(related_cell_identifier)
|
||||||
new_content.append(entry_content) # Append the original content or modify as needed
|
matrix[link_row_table_id] = self.build_matrix(tables_data, link_row_table_id, tables_data[link_row_table_id].copy(), reference_map_child)
|
||||||
table_row[table_column_name] = new_content
|
new_content.append(entry) # Append the original content or modify as needed
|
||||||
|
table_row[table_column_name] = new_content
|
||||||
|
|
||||||
def generate_related_cell_identifier(self, table_id, table_column_id, table_row_id):
|
def generate_related_cell_identifier(self, table_id, table_column_id, table_row_id):
|
||||||
return self.generate_cell_identifier(table_id, "field_" + str(table_column_id), table_row_id);
|
return self.generate_cell_identifier(table_id, "field_" + str(table_column_id), table_row_id);
|
||||||
|
Loading…
Reference in New Issue
Block a user