Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the table element displaying response #759

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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