Update app.py
Browse files
app.py
CHANGED
|
@@ -873,17 +873,6 @@ if selected_task_id:
|
|
| 873 |
</div>
|
| 874 |
""", unsafe_allow_html=True)
|
| 875 |
|
| 876 |
-
# Description section - Fix formatting
|
| 877 |
-
st.markdown('<div class="section-divider"></div>', unsafe_allow_html=True)
|
| 878 |
-
st.markdown('<div class="task-details-section">', unsafe_allow_html=True)
|
| 879 |
-
st.markdown('<h3>Description</h3>', unsafe_allow_html=True)
|
| 880 |
-
st.markdown('<div class="task-description">', unsafe_allow_html=True)
|
| 881 |
-
# Ensure proper encoding and sanitization of description text
|
| 882 |
-
description_text = task['Description'] if task['Description'] else 'No description provided.'
|
| 883 |
-
st.markdown(f"<p>{description_text}</p>", unsafe_allow_html=True)
|
| 884 |
-
st.markdown('</div>', unsafe_allow_html=True)
|
| 885 |
-
st.markdown('</div>', unsafe_allow_html=True)
|
| 886 |
-
|
| 887 |
# Task actions
|
| 888 |
st.markdown('<div class="section-divider"></div>', unsafe_allow_html=True)
|
| 889 |
st.markdown('<div class="task-details-section">', unsafe_allow_html=True)
|
|
@@ -897,18 +886,8 @@ if selected_task_id:
|
|
| 897 |
|
| 898 |
# File upload section
|
| 899 |
uploaded_files = st.file_uploader("Upload Documents",
|
| 900 |
-
|
| 901 |
-
|
| 902 |
-
|
| 903 |
-
# Save changes button for description
|
| 904 |
-
if st.button("Save Description", key=f"save_desc_{selected_task_id}"):
|
| 905 |
-
task_idx = task_df.index[0]
|
| 906 |
-
|
| 907 |
-
# Only update if description changed
|
| 908 |
-
if new_description != task['Description']:
|
| 909 |
-
update_task(task_idx, 'Description', new_description)
|
| 910 |
-
st.success("Description updated successfully!")
|
| 911 |
-
st.rerun()
|
| 912 |
|
| 913 |
# Handle file uploads
|
| 914 |
if uploaded_files:
|
|
@@ -924,24 +903,42 @@ if selected_task_id:
|
|
| 924 |
# Read file content
|
| 925 |
file_content = uploaded_file.read()
|
| 926 |
|
| 927 |
-
#
|
| 928 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 929 |
os.makedirs(doc_dir, exist_ok=True)
|
| 930 |
|
| 931 |
# Create task-specific directory
|
| 932 |
task_doc_dir = os.path.join(doc_dir, f"task_{selected_task_id.replace('#', '')}")
|
| 933 |
os.makedirs(task_doc_dir, exist_ok=True)
|
| 934 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 935 |
# Save file
|
| 936 |
file_path = os.path.join(task_doc_dir, uploaded_file.name)
|
| 937 |
with open(file_path, "wb") as f:
|
| 938 |
f.write(file_content)
|
| 939 |
|
| 940 |
-
# Update task with document reference
|
| 941 |
if 'Documents' not in task or not isinstance(task['Documents'], list):
|
| 942 |
task_df.at[task_df.index[0], 'Documents'] = [uploaded_file.name]
|
| 943 |
else:
|
| 944 |
-
docs = task['Documents']
|
| 945 |
if uploaded_file.name not in docs:
|
| 946 |
docs.append(uploaded_file.name)
|
| 947 |
task_df.at[task_df.index[0], 'Documents'] = docs
|
|
@@ -953,9 +950,11 @@ if selected_task_id:
|
|
| 953 |
upload_status.success(f"Uploaded {uploaded_file.name} successfully!")
|
| 954 |
except Exception as e:
|
| 955 |
upload_status.error(f"Error uploading {uploaded_file.name}: {str(e)}")
|
|
|
|
|
|
|
| 956 |
|
| 957 |
# Clear status after all files processed
|
| 958 |
-
st.success("All files processed.
|
| 959 |
|
| 960 |
# Display attached documents if any
|
| 961 |
if 'Documents' in task and isinstance(task['Documents'], list) and len(task['Documents']) > 0:
|
|
|
|
| 873 |
</div>
|
| 874 |
""", unsafe_allow_html=True)
|
| 875 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 876 |
# Task actions
|
| 877 |
st.markdown('<div class="section-divider"></div>', unsafe_allow_html=True)
|
| 878 |
st.markdown('<div class="task-details-section">', unsafe_allow_html=True)
|
|
|
|
| 886 |
|
| 887 |
# File upload section
|
| 888 |
uploaded_files = st.file_uploader("Upload Documents",
|
| 889 |
+
accept_multiple_files=True,
|
| 890 |
+
key=f"upload_{selected_task_id}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 891 |
|
| 892 |
# Handle file uploads
|
| 893 |
if uploaded_files:
|
|
|
|
| 903 |
# Read file content
|
| 904 |
file_content = uploaded_file.read()
|
| 905 |
|
| 906 |
+
# Get a writable directory path that is guaranteed to work
|
| 907 |
+
if TASKS_FILE:
|
| 908 |
+
base_dir = os.path.dirname(TASKS_FILE)
|
| 909 |
+
else:
|
| 910 |
+
# Fall back to temp directory if TASKS_FILE is not available
|
| 911 |
+
base_dir = TEMP_DIR
|
| 912 |
+
|
| 913 |
+
# Create documents directory
|
| 914 |
+
doc_dir = os.path.join(base_dir, "task_documents")
|
| 915 |
os.makedirs(doc_dir, exist_ok=True)
|
| 916 |
|
| 917 |
# Create task-specific directory
|
| 918 |
task_doc_dir = os.path.join(doc_dir, f"task_{selected_task_id.replace('#', '')}")
|
| 919 |
os.makedirs(task_doc_dir, exist_ok=True)
|
| 920 |
|
| 921 |
+
# Test if directory is writable
|
| 922 |
+
test_file = os.path.join(task_doc_dir, ".write_test")
|
| 923 |
+
try:
|
| 924 |
+
with open(test_file, 'w') as f:
|
| 925 |
+
f.write("test")
|
| 926 |
+
os.remove(test_file)
|
| 927 |
+
except (PermissionError, OSError):
|
| 928 |
+
# If task directory isn't writable, use temp directory
|
| 929 |
+
task_doc_dir = os.path.join(TEMP_DIR, f"task_{selected_task_id.replace('#', '')}")
|
| 930 |
+
os.makedirs(task_doc_dir, exist_ok=True)
|
| 931 |
+
|
| 932 |
# Save file
|
| 933 |
file_path = os.path.join(task_doc_dir, uploaded_file.name)
|
| 934 |
with open(file_path, "wb") as f:
|
| 935 |
f.write(file_content)
|
| 936 |
|
| 937 |
+
# Update task with document reference
|
| 938 |
if 'Documents' not in task or not isinstance(task['Documents'], list):
|
| 939 |
task_df.at[task_df.index[0], 'Documents'] = [uploaded_file.name]
|
| 940 |
else:
|
| 941 |
+
docs = task['Documents'] if isinstance(task['Documents'], list) else []
|
| 942 |
if uploaded_file.name not in docs:
|
| 943 |
docs.append(uploaded_file.name)
|
| 944 |
task_df.at[task_df.index[0], 'Documents'] = docs
|
|
|
|
| 950 |
upload_status.success(f"Uploaded {uploaded_file.name} successfully!")
|
| 951 |
except Exception as e:
|
| 952 |
upload_status.error(f"Error uploading {uploaded_file.name}: {str(e)}")
|
| 953 |
+
import traceback
|
| 954 |
+
print(traceback.format_exc()) # Print detailed error for debugging
|
| 955 |
|
| 956 |
# Clear status after all files processed
|
| 957 |
+
st.success("All files processed.")
|
| 958 |
|
| 959 |
# Display attached documents if any
|
| 960 |
if 'Documents' in task and isinstance(task['Documents'], list) and len(task['Documents']) > 0:
|