Now with the ability to handle multiple custom question in the data export

This commit is contained in:
2024-04-07 11:57:44 -04:00
parent 2514106476
commit 00471df086
2 changed files with 19 additions and 6 deletions

View File

@@ -41,12 +41,11 @@ class Event_Exhibit_Tracking_Base(BaseModel):
exhibitor_notes: Optional[str]
responses_json: Optional[Json] # NOTE: Responses to custom questions
# responses_json: Json = [{'test': ''}] # NOTE: Responses to custom questions
# responses_json: Optional[Json] = Field(
# default_factory = lambda:[{'test': ''}]
# )
data_json: Optional[Json]
# data_json: Optional[str]
# Example:
# {"5_years": {"response": "I see myself in 5 years doing something."}, "colors": {"response": "green"}}
# {"example_text": {"response": "This is an example of an text answer."}, "example_option_list": {"response": "no"}, "the_code": {"response": "yes"}, "question_everything": {"response": "tomorrow"}, "pre_assesment": {"response": "yes"}}
data_json: Optional[Json] # NOTE: Additional data
enable: Optional[bool]
hide: Optional[bool]

View File

@@ -366,6 +366,17 @@ async def get_event_exhibit_obj_tracking_list(
data_dict['person_location'] = data_dict.pop('event_badge_location', None)
else: data_dict['person_location'] = None
# Example values for responses_json:
# {"5_years": {"response": "I see myself in 5 years doing something."}, "colors": {"response": "green"}}
# {"example_text": {"response": "This is an example of an text answer."}, "example_option_list": {"response": "no"}, "the_code": {"response": "yes"}, "question_everything": {"response": "tomorrow"}, "pre_assesment": {"response": "yes"}}
if 'responses_json' in data_dict and data_dict['responses_json']:
responses_json = data_dict.pop('responses_json', None)
for key, value in responses_json.items():
# Only use the response value.
data_dict[key] = value.get('response')
else:
data_dict[key] = None
log.debug(data_dict)
data_dict_list_for_export.append(data_dict)
@@ -425,6 +436,9 @@ async def get_event_exhibit_obj_tracking_list(
'created_on',
'updated_on',
]
# Add the custom questions to the column_name_li for the label row of the export file
column_name_li.extend(data_dict_list_for_export[0].keys())
log.debug(column_name_li)
log.debug(data_dict_list_for_export)