Spaces:
Paused
Paused
| # academic_list.py | |
| import streamlit as st | |
| from app5_selectbox.database_con import cursor, db_connection #connect_to_database, execute_query | |
| from app5_selectbox.app5_selectbox_func import display_table, generate_unique_4 | |
| def academic_list(table_name): | |
| # Include the academic_list-specific code here | |
| acad_id = generate_unique_4(cursor, "acad_id", table_name) | |
| acad_year = st.text_input("Academic Year", key="acad_year") | |
| sem_num = st.selectbox("Semester Number", ("1", "2"), key="sem_num") | |
| if st.button("Insert Academic List Record"): | |
| # Check if the acad_year and sem_num are provided | |
| if not acad_year or not sem_num: | |
| st.error("Academic Year and Semester Number are required. Please provide values for both fields.") | |
| else: | |
| try: | |
| # Check for duplicates in acad_year and sem_num | |
| cursor.execute("SELECT acad_id FROM academic_list WHERE acad_year = %s AND sem_num = %s", (acad_year, sem_num)) | |
| duplicate = cursor.fetchone() | |
| if duplicate is not None: | |
| st.error("Duplicate entry found. Please provide unique Academic Year and Semester Number.") | |
| else: | |
| # Insert a record into the academic_list table | |
| cursor.execute("INSERT INTO academic_list (acad_id, acad_year, sem_num) VALUES (%s, %s, %s)", | |
| (acad_id, acad_year, sem_num)) | |
| db_connection.commit() | |
| st.success("Record inserted successfully.") | |
| except Exception as e: | |
| st.error(f"An error occurred: {str(e)}") | |
| display_table(cursor, table_name) | |