Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,41 +21,105 @@ def connect_db():
|
|
| 21 |
st.error(f"Error connecting to the database: {e}")
|
| 22 |
return None
|
| 23 |
|
|
|
|
| 24 |
# Insert user data into the "users" table
|
| 25 |
def insert_user(company_name, requirements, date, status, notes, next_steps, contact_person, contact_information):
|
| 26 |
conn = connect_db()
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
# Streamlit UI
|
| 47 |
-
st.title("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
|
|
|
|
|
|
| 49 |
with st.form("user_form"):
|
| 50 |
company_name = st.text_input("Company Name", max_chars=255)
|
| 51 |
-
requirements = st.text_area("Requirements")
|
| 52 |
date = st.date_input("Date", value=datetime.today())
|
| 53 |
status = st.text_input("Status", max_chars=50)
|
| 54 |
-
notes = st.text_area("Notes")
|
| 55 |
-
next_steps = st.text_area("Next Steps")
|
| 56 |
contact_person = st.text_input("Contact Person", max_chars=100)
|
| 57 |
contact_information = st.text_input("Contact Information (Email/Phone)", max_chars=255)
|
| 58 |
|
|
|
|
| 59 |
submitted = st.form_submit_button("Add User")
|
| 60 |
|
| 61 |
if submitted:
|
|
|
|
| 21 |
st.error(f"Error connecting to the database: {e}")
|
| 22 |
return None
|
| 23 |
|
| 24 |
+
|
| 25 |
# Insert user data into the "users" table
|
| 26 |
def insert_user(company_name, requirements, date, status, notes, next_steps, contact_person, contact_information):
|
| 27 |
conn = connect_db()
|
| 28 |
+
cur = conn.cursor()
|
| 29 |
+
|
| 30 |
+
query = """
|
| 31 |
+
INSERT INTO users
|
| 32 |
+
(company_name, requirements, date, status, notes, next_steps, contact_person, contact_information)
|
| 33 |
+
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
|
| 34 |
+
"""
|
| 35 |
|
| 36 |
+
cur.execute(query, (company_name, requirements, date, status, notes, next_steps, contact_person, contact_information))
|
| 37 |
+
conn.commit()
|
| 38 |
+
cur.close()
|
| 39 |
+
conn.close()
|
| 40 |
+
|
| 41 |
+
st.success("User added successfully!")
|
| 42 |
+
|
| 43 |
+
# Search users based on query
|
| 44 |
+
def search_users(query):
|
| 45 |
+
conn = connect_db()
|
| 46 |
+
cur = conn.cursor()
|
| 47 |
+
|
| 48 |
+
search_query = """
|
| 49 |
+
SELECT company_name
|
| 50 |
+
FROM users
|
| 51 |
+
WHERE company_name ILIKE %s
|
| 52 |
+
"""
|
| 53 |
+
|
| 54 |
+
cur.execute(search_query, (f"%{query}%",))
|
| 55 |
+
results = cur.fetchall()
|
| 56 |
+
cur.close()
|
| 57 |
+
conn.close()
|
| 58 |
+
|
| 59 |
+
return results
|
| 60 |
+
|
| 61 |
+
# Get detailed information of a specific company
|
| 62 |
+
def get_company_details(company_name):
|
| 63 |
+
conn = connect_db()
|
| 64 |
+
cur = conn.cursor()
|
| 65 |
+
|
| 66 |
+
details_query = """
|
| 67 |
+
SELECT company_name, requirements, date, status, notes, next_steps, contact_person, contact_information
|
| 68 |
+
FROM users
|
| 69 |
+
WHERE company_name = %s
|
| 70 |
+
"""
|
| 71 |
+
|
| 72 |
+
cur.execute(details_query, (company_name,))
|
| 73 |
+
details = cur.fetchone()
|
| 74 |
+
cur.close()
|
| 75 |
+
conn.close()
|
| 76 |
+
|
| 77 |
+
return details
|
| 78 |
|
| 79 |
# Streamlit UI
|
| 80 |
+
st.title("User Management")
|
| 81 |
+
|
| 82 |
+
# Search bar
|
| 83 |
+
search_query = st.text_input("Search", placeholder="Enter company name...", max_chars=100)
|
| 84 |
+
|
| 85 |
+
if search_query:
|
| 86 |
+
companies = search_users(search_query)
|
| 87 |
+
|
| 88 |
+
if companies:
|
| 89 |
+
st.write("**Company Suggestions:**")
|
| 90 |
+
company_names = [row[0] for row in companies]
|
| 91 |
+
selected_company = st.selectbox("Select a company:", company_names)
|
| 92 |
+
|
| 93 |
+
if selected_company:
|
| 94 |
+
details = get_company_details(selected_company)
|
| 95 |
+
if details:
|
| 96 |
+
st.subheader("Company Details")
|
| 97 |
+
st.write(f"**Company Name:** {details[0]}")
|
| 98 |
+
st.write(f"**Requirements:** {details[1]}")
|
| 99 |
+
st.write(f"**Date:** {details[2]}")
|
| 100 |
+
st.write(f"**Status:** {details[3]}")
|
| 101 |
+
st.write(f"**Notes:** {details[4]}")
|
| 102 |
+
st.write(f"**Next Steps:** {details[5]}")
|
| 103 |
+
st.write(f"**Contact Person:** {details[6]}")
|
| 104 |
+
st.write(f"**Contact Information:** {details[7]}")
|
| 105 |
+
else:
|
| 106 |
+
st.write("No details found.")
|
| 107 |
+
else:
|
| 108 |
+
st.write("No company names found.")
|
| 109 |
|
| 110 |
+
# Form for adding a new user
|
| 111 |
+
st.header("Add a New User")
|
| 112 |
with st.form("user_form"):
|
| 113 |
company_name = st.text_input("Company Name", max_chars=255)
|
| 114 |
+
requirements = st.text_area("Requirements", height=100)
|
| 115 |
date = st.date_input("Date", value=datetime.today())
|
| 116 |
status = st.text_input("Status", max_chars=50)
|
| 117 |
+
notes = st.text_area("Notes", height=100)
|
| 118 |
+
next_steps = st.text_area("Next Steps", height=100)
|
| 119 |
contact_person = st.text_input("Contact Person", max_chars=100)
|
| 120 |
contact_information = st.text_input("Contact Information (Email/Phone)", max_chars=255)
|
| 121 |
|
| 122 |
+
# Form submission button
|
| 123 |
submitted = st.form_submit_button("Add User")
|
| 124 |
|
| 125 |
if submitted:
|