Skip to content

Commit

Permalink
fix the table element displaying response
Browse files Browse the repository at this point in the history
  • Loading branch information
XiChenn committed Aug 3, 2022
1 parent 6bf037e commit 1ca33e2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pybossa/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,12 @@ def process_table_component(tp_code, user_response):
for table_element in table_elements:
response_key = table_element.get('name')
response_value = user_response.get(response_key, [])

# In case the response_value is dict, we need to convert it to a list
# so that the table-element can display the data correctly
if type(response_value) is dict:
response_value = list(response_value.values())

table_element[':data'] = json.dumps(response_value)

# Remove initial-value attribute so that table can display the data
Expand Down
19 changes: 19 additions & 0 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,25 @@ def test_process_table_component(self):
assert ":data='" + json.dumps(user_response.get("all_info")) in result
assert " initial-value=" not in result

user_response = {"all_info": {
"0":
{"name": "Xi", "linkedIn": "2343",
"position": "software engieer",
"zoomInfo": "aaa", "phoneNumber": "1234",
"emailAddress": "xchen375@bb.net",
"physicalLocation": "aa"}
},
"1":
{"name": "Chen", "linkedIn": "2353",
"moreInfo": "", "position": "CEO",
"zoomInfo": "bbb", "phoneNumber": "546",
"emailAddress": "aaaa@gg.com",
"physicalLocation": "bb"}
}
result = util.process_table_component(tp_code, user_response)
assert ":data='" + json.dumps(list(user_response.get("all_info").values())) in result
assert " initial-value=" not in result


class TestIsReservedName(object):
from test import flask_app as app
Expand Down

0 comments on commit 1ca33e2

Please sign in to comment.