What I’m trying to do:
I am trying to get the question_index value corresponding to the question_column value to be saved in a data table
I have a data table (question_choices) with a column, question_index (which has a number for each question), it also has a column, question_column ( displaying each question).
the questions are shuffled as below and is called when continue_button is shown on screen.
def form_show(self, **event_args):
"""This method is called when the Button is shown on the screen"""
self.my_list =list(app_tables.questions_choices.search())
random.shuffle(self.my_list)
self.index=(0)
I have a function that calls (self.button_click) when button_1 is clicked.button _1 is visible and therefore clicked before continue_button( this sets the first question to be displayed)
def hide_label(self):
if self.label_12.visible == True:
self.column_panel_2.visible = False
self.label_3.visible = False
self.label_1.visible = False
self.label_9.visible = False
else:
self.label_3.visible = True
self.column_panel_2.visible = True
self.continue_button.visible = True
self.label_1.visible = True
self.button_click()
self.label_9.visible = True
def button_click is again called but by, continue_button which displays the next question on label_2 when continue_button is clicked.
def button_click(self):
try:
row = self.my_list[self.index]
q = row['question_index']
self.label_2.text = row['question_column']
self.label_4.text = row['Column1']
self.label_5.text = row['Column2']
self.label_6.text = row['Column3']
self.label_7.text = row['Column4']
self.label_8.text = row['Column5']
self.label_9.text = row['Column6']
self.label_10.text = row['Column7']
self.index +=1
this code is also called when continue_button is clicked(in order to send values to data table)
q is the value of (question_index)
new_user = list(app_tables.users.search())
row = users.get_user(new_user)
y = row['email']
for self.radio_button in self.column_panel_2.get_components():
if self.radio_button.selected:
add_select = self.radio_button.value
email = y
user_place = list(app_tables.users.search())
row = (anvil.users.get_user())
z = row ['position']
anvil.server.call('log_answer',add_select,email,z,q)
self.radio_button_reset()
My problem is that the value displayed in data table is always the next question.So the indexing for q is always corresponding to the next question and not the current question_column value.