Implement CORS-fields in views & HTML, improve list rendering & selection

This commit is contained in:
Josako
2024-05-15 21:27:23 +02:00
parent ea23e8d327
commit 8c6d9bf5ca
13 changed files with 434 additions and 68 deletions

View File

@@ -0,0 +1,36 @@
def prepare_table(model_objects, column_names):
"""
Converts a list of SQLAlchemy model objects into a list of dictionaries based on specified column names.
Args:
model_objects (list): List of SQLAlchemy model instances.
column_names (list): List of strings representing the column names to be included in the dictionaries.
Returns:
list: List of dictionaries where each dictionary represents a record with keys as column names.
"""
table_data = [
{col: getattr(obj, col) for col in column_names}
for obj in model_objects
]
return table_data
def prepare_table_for_macro(model_objects, column_attrs):
"""
Prepare data for rendering in a macro that expects each cell as a dictionary with class, type, and value.
Args:
model_objects (list): List of model instances or dictionaries.
column_attrs (list of tuples): Each tuple contains the attribute name and additional properties like class.
Returns:
list: A list of rows, where each row is a list of cell dictionaries.
"""
return [
[
{'value': getattr(obj, attr), 'class': cls, 'type': 'text'} # Adjust 'type' as needed
for attr, cls in column_attrs
]
for obj in model_objects
]