Skip to content

Commit

Permalink
Separate table column model from table header model
Browse files Browse the repository at this point in the history
  • Loading branch information
kavehshahedi committed Jul 15, 2024
1 parent 5d41600 commit 6eff8c2
Showing 1 changed file with 42 additions and 35 deletions.
77 changes: 42 additions & 35 deletions tsp/virtual_table_header_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,46 +38,53 @@ def __init__(self, params):
self.columns = []
if params is not None:
for column in params:
# Column ID
column_id = None
if COLUMN_ID_KEY in column:
column_id = column.get(COLUMN_ID_KEY)
del column[COLUMN_ID_KEY]
# Create a new virtual table header column model
self.columns.append(VirtualTableHeaderColumnModel(column))

# Column name
column_name = None
if COLUMN_NAME_KEY in column:
column_name = column.get(COLUMN_NAME_KEY)
del column[COLUMN_NAME_KEY]
def print(self):
'''
Print the virtual table header model
'''
print("Virtual Table Columns:")
for column in self.columns:
column.print()

class VirtualTableHeaderColumnModel:
'''
Virtual table header column model that will be returned by the server
'''

def __init__(self, params):
# Column ID
self.id = None
if COLUMN_ID_KEY in params:
self.id = params.get(COLUMN_ID_KEY)
del params[COLUMN_ID_KEY]

# Column description
column_description = None
if COLUMN_DESCRIPTION_KEY in column:
column_description = column.get(COLUMN_DESCRIPTION_KEY)
del column[COLUMN_DESCRIPTION_KEY]
# Column name
self.name = None
if COLUMN_NAME_KEY in params:
self.name = params.get(COLUMN_NAME_KEY)
del params[COLUMN_NAME_KEY]

# Column type
column_type = None
if COLUMN_TYPE_KEY in column:
column_type = column.get(COLUMN_TYPE_KEY)
del column[COLUMN_TYPE_KEY]
# Column description
self.description = None
if COLUMN_DESCRIPTION_KEY in params:
self.description = params.get(COLUMN_DESCRIPTION_KEY)
del params[COLUMN_DESCRIPTION_KEY]

# Add column to the list
self.columns.append({
COLUMN_ID_KEY: column_id,
COLUMN_NAME_KEY: column_name,
COLUMN_DESCRIPTION_KEY: column_description,
COLUMN_TYPE_KEY: column_type
})
# Column type
self.type = None
if COLUMN_TYPE_KEY in params:
self.type = params.get(COLUMN_TYPE_KEY)
del params[COLUMN_TYPE_KEY]

def print(self):
'''
Print the virtual table header model
Print the virtual table header column model
'''
print("Virtual Table Columns:")
for column in self.columns:
print(" id: " + str(column.get(COLUMN_ID_KEY)))
print(" name: " + str(column.get(COLUMN_NAME_KEY)))
print(" description: " + str(column.get(COLUMN_DESCRIPTION_KEY)))
print(" type: " + str(column.get(COLUMN_TYPE_KEY)))
print("-" * 50)
print(" id: " + str(self.id))
print(" name: " + str(self.name))
print(" description: " + str(self.description))
print(" type: " + str(self.type))
print("-" * 50)

0 comments on commit 6eff8c2

Please sign in to comment.