Skip to content

Commit 9861732

Browse files
kavehshahediMatthewKhouzam
authored andcommitted
Separate table column model from table header model
1 parent 1c93750 commit 9861732

File tree

1 file changed

+42
-35
lines changed

1 file changed

+42
-35
lines changed

tsp/virtual_table_header_model.py

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,46 +38,53 @@ def __init__(self, params):
3838
self.columns = []
3939
if params is not None:
4040
for column in params:
41-
# Column ID
42-
column_id = None
43-
if COLUMN_ID_KEY in column:
44-
column_id = column.get(COLUMN_ID_KEY)
45-
del column[COLUMN_ID_KEY]
41+
# Create a new virtual table header column model
42+
self.columns.append(VirtualTableHeaderColumnModel(column))
4643

47-
# Column name
48-
column_name = None
49-
if COLUMN_NAME_KEY in column:
50-
column_name = column.get(COLUMN_NAME_KEY)
51-
del column[COLUMN_NAME_KEY]
44+
def print(self):
45+
'''
46+
Print the virtual table header model
47+
'''
48+
print("Virtual Table Columns:")
49+
for column in self.columns:
50+
column.print()
51+
52+
class VirtualTableHeaderColumnModel:
53+
'''
54+
Virtual table header column model that will be returned by the server
55+
'''
56+
57+
def __init__(self, params):
58+
# Column ID
59+
self.id = None
60+
if COLUMN_ID_KEY in params:
61+
self.id = params.get(COLUMN_ID_KEY)
62+
del params[COLUMN_ID_KEY]
5263

53-
# Column description
54-
column_description = None
55-
if COLUMN_DESCRIPTION_KEY in column:
56-
column_description = column.get(COLUMN_DESCRIPTION_KEY)
57-
del column[COLUMN_DESCRIPTION_KEY]
64+
# Column name
65+
self.name = None
66+
if COLUMN_NAME_KEY in params:
67+
self.name = params.get(COLUMN_NAME_KEY)
68+
del params[COLUMN_NAME_KEY]
5869

59-
# Column type
60-
column_type = None
61-
if COLUMN_TYPE_KEY in column:
62-
column_type = column.get(COLUMN_TYPE_KEY)
63-
del column[COLUMN_TYPE_KEY]
70+
# Column description
71+
self.description = None
72+
if COLUMN_DESCRIPTION_KEY in params:
73+
self.description = params.get(COLUMN_DESCRIPTION_KEY)
74+
del params[COLUMN_DESCRIPTION_KEY]
6475

65-
# Add column to the list
66-
self.columns.append({
67-
COLUMN_ID_KEY: column_id,
68-
COLUMN_NAME_KEY: column_name,
69-
COLUMN_DESCRIPTION_KEY: column_description,
70-
COLUMN_TYPE_KEY: column_type
71-
})
76+
# Column type
77+
self.type = None
78+
if COLUMN_TYPE_KEY in params:
79+
self.type = params.get(COLUMN_TYPE_KEY)
80+
del params[COLUMN_TYPE_KEY]
7281

7382
def print(self):
7483
'''
75-
Print the virtual table header model
84+
Print the virtual table header column model
7685
'''
77-
print("Virtual Table Columns:")
78-
for column in self.columns:
79-
print(" id: " + str(column.get(COLUMN_ID_KEY)))
80-
print(" name: " + str(column.get(COLUMN_NAME_KEY)))
81-
print(" description: " + str(column.get(COLUMN_DESCRIPTION_KEY)))
82-
print(" type: " + str(column.get(COLUMN_TYPE_KEY)))
83-
print("-" * 50)
86+
print(" id: " + str(self.id))
87+
print(" name: " + str(self.name))
88+
print(" description: " + str(self.description))
89+
print(" type: " + str(self.type))
90+
print("-" * 50)

0 commit comments

Comments
 (0)