user-feedback / views /nav_buttons.py
Ashmi Banerjee
updated with resuming surveys:
0759822
raw
history blame
1.65 kB
from db.schema import Feedback
from db.crud import save_feedback, read
import streamlit as st
from datetime import datetime
import os
from dotenv import load_dotenv
load_dotenv()
VALIDATION_CODE = os.getenv("VALIDATION_CODE")
def submit_feedback(current_index):
"""Handles feedback submission to the database."""
feedback = Feedback(
id=current_index + 1,
user_id=st.session_state.username,
time_stamp=datetime.now().isoformat(),
responses=st.session_state.responses,
)
try:
save_feedback(feedback)
st.session_state.completed = True
st.rerun()
except Exception as e:
st.error(f"An error occurred while submitting feedback: {e}")
def navigation_buttons(data, ratings_v, ratings_p0, ratings_p1):
"""Display navigation buttons."""
current_index = st.session_state.current_index
col1, col2, col3 = st.columns([1, 1, 2])
with col1: # Back button
if st.button("Back") and current_index > 0:
st.session_state.current_index -= 1
st.rerun()
with col2: # Next button
if st.button("Next"):
if any(rating == 0 for rating in [ratings_v, ratings_p0, ratings_p1]):
st.warning("Please provide a rating before proceeding.")
else:
if current_index < len(data) - 1:
st.session_state.current_index += 1
st.rerun()
else:
submit_feedback(current_index)
with col3: # Save & Resume Later button
if st.button("Exit & Resume Later"):
submit_feedback(current_index)