emvecchi commited on
Commit
3111cc8
·
verified ·
1 Parent(s): c796a61

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -5
app.py CHANGED
@@ -466,8 +466,8 @@ def show_field(f: Field, index: int, data_collected):
466
  show_field(child, index, data_collected)
467
  case 'skip_checkbox':
468
  st.checkbox(f.title, key=f.name, value=False)
469
- #case 'rupture_markers':
470
- # render_rupture_markers_widget(index, rupture_choices)
471
  else:
472
  key = f.name + str(index)
473
  st.session_state.data_inputs_keys.append(f.name)
@@ -559,6 +559,7 @@ def show_field(f: Field, index: int, data_collected):
559
  st.session_state.unacceptable_response = False
560
  st.error(f"Mandatory field")
561
 
 
562
  def show_fields(fields: List[Field]):
563
  st.session_state.valid = True
564
  index = st.session_state.current_index
@@ -585,6 +586,19 @@ def show_fields(fields: List[Field]):
585
  navigate(1)
586
 
587
  st.session_state.form_displayed = st.session_state.current_index
 
 
 
 
 
 
 
 
 
 
 
 
 
588
 
589
  def prep_and_save_data(index, skip_sample):
590
  payload = {
@@ -735,9 +749,26 @@ elif st.session_state.current_index == -1:
735
 
736
  elif st.session_state.current_index < len(st.session_state.data):
737
  #add_annotation_guidelines()
738
- with st.form("data_form"+str(st.session_state.current_index)):
739
- show_fields(fields)
740
- render_rupture_markers_widget(st.session_state.current_index, rupture_choices)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
741
 
742
  elif st.session_state.current_index == len(st.session_state.data):
743
  st.write(f"**Thank you for taking part in this study!** \n ")
 
466
  show_field(child, index, data_collected)
467
  case 'skip_checkbox':
468
  st.checkbox(f.title, key=f.name, value=False)
469
+ case 'rupture_markers':
470
+ render_rupture_markers_widget(index, rupture_choices)
471
  else:
472
  key = f.name + str(index)
473
  st.session_state.data_inputs_keys.append(f.name)
 
559
  st.session_state.unacceptable_response = False
560
  st.error(f"Mandatory field")
561
 
562
+ '''
563
  def show_fields(fields: List[Field]):
564
  st.session_state.valid = True
565
  index = st.session_state.current_index
 
586
  navigate(1)
587
 
588
  st.session_state.form_displayed = st.session_state.current_index
589
+ '''
590
+
591
+ def show_fields(fields: List[Field]):
592
+ index = st.session_state.current_index
593
+ data_collected = read_saved_data()
594
+ st.session_state.data_inputs_keys = [] # rebuilt each render
595
+ st.session_state.following_mandatory = False
596
+
597
+ for field in fields:
598
+ show_field(field, index, data_collected)
599
+
600
+ # mark that the page has been rendered at least once (if you still use this elsewhere)
601
+ st.session_state.form_displayed = st.session_state.current_index
602
 
603
  def prep_and_save_data(index, skip_sample):
604
  payload = {
 
749
 
750
  elif st.session_state.current_index < len(st.session_state.data):
751
  #add_annotation_guidelines()
752
+ #with st.form("data_form"+str(st.session_state.current_index)):
753
+ # show_fields(fields)
754
+ #render_rupture_markers_widget(st.session_state.current_index, rupture_choices)
755
+ show_fields(fields)
756
+
757
+ # Action buttons
758
+ c1, c2, c3 = st.columns([1,1,6])
759
+ with c1:
760
+ if st.button("Save & Next"):
761
+ if validate_current_page(fields, st.session_state.current_index):
762
+ with st.spinner("saving"):
763
+ prep_and_save_data(st.session_state.current_index, ('skip' in st.session_state and st.session_state['skip']))
764
+ st.success("Saved!")
765
+ navigate(1)
766
+ with c2:
767
+ if st.button("Save only"):
768
+ if validate_current_page(fields, st.session_state.current_index):
769
+ with st.spinner("saving"):
770
+ prep_and_save_data(st.session_state.current_index, ('skip' in st.session_state and st.session_state['skip']))
771
+ st.success("Saved!")
772
 
773
  elif st.session_state.current_index == len(st.session_state.data):
774
  st.write(f"**Thank you for taking part in this study!** \n ")