arif670 commited on
Commit
9738110
Β·
verified Β·
1 Parent(s): 34db388

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +110 -108
app.py CHANGED
@@ -300,122 +300,124 @@ def main():
300
 
301
  # Task Entry
302
  elif menu == "πŸ“₯ Task Entry":
303
- with st.form(key="task_form", clear_on_submit=True):
304
  st.subheader("βž• Add New Task")
305
  col1, col2 = st.columns(2)
306
-
307
- # Left Column
308
- with col1:
309
- task = st.text_area("πŸ“ Task Description", height=100)
310
- task_type = st.selectbox(
311
- "πŸ“¦ Task Type",
312
- ["Design", "Procurement", "Construction", "Testing", "Other"]
313
- )
314
-
315
- # Right Column
316
- with col2:
317
- projects = [p.id for p in db.collection("projects").stream()] + ["Add New Project"]
318
- project = st.selectbox("πŸ—οΈ Project", projects)
319
- if project == "Add New Project":
320
- project = st.text_input("✨ New Project Name")
321
 
322
- status = st.selectbox("πŸ“Œ Status", ["Pending", "In Progress", "Completed"])
323
- date = st.date_input("πŸ“… Due Date", min_value=datetime.today())
324
-
325
- recurrence = st.selectbox("πŸ”„ Repeat", ["None", "Daily", "Weekly", "Monthly"])
326
- end_date = None
327
- if recurrence != "None":
328
- end_date = st.date_input(
329
- "πŸ”š Repeat Until",
330
- min_value=date + relativedelta(days=1),
331
- help="Recurrence end date (inclusive)"
332
  )
333
-
334
- # File Upload Section
335
- uploaded_files = st.file_uploader(
336
- "πŸ“Ž Attachments",
337
- type=["pdf", "docx", "xlsx", "png", "jpg", "jpeg"],
338
- accept_multiple_files=True,
339
- help="Upload relevant files (max 10MB each)"
340
- )
341
-
342
- submitted = st.form_submit_button("πŸ’Ύ Save Task", use_container_width=True)
343
-
344
- if submitted:
345
- if not task.strip():
346
- st.error("❌ Task description cannot be empty!")
347
- st.stop()
348
 
349
- try:
350
- # Validate recurrence
351
- if recurrence != "None" and (not end_date or end_date <= date):
352
- st.error("❌ End date must be after initial due date")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
  st.stop()
354
-
355
- # Process attachments
356
- attachments = []
357
- if uploaded_files:
358
- for file in uploaded_files:
359
- if file.size > 10 * 1024 * 1024: # 10MB limit
360
- st.error(f"❌ File {file.name} exceeds 10MB limit")
361
- st.stop()
 
 
 
 
 
 
 
 
 
 
 
 
 
362
 
363
- # Upload to Cloudinary
364
- result = cloudinary.uploader.upload(
365
- file,
366
- folder=f"attachments/{st.session_state.user_uid}/",
367
- resource_type="auto"
368
- )
369
-
370
- attachments.append({
371
- "name": file.name,
372
- "url": result['secure_url'],
373
- "type": file.type,
374
- "size": file.size
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
375
  })
376
-
377
- # Generate recurring dates
378
- dates = [date]
379
- if recurrence != "None":
380
- current_date = date
381
- while current_date < end_date:
382
- if recurrence == "Daily":
383
- current_date += relativedelta(days=1)
384
- elif recurrence == "Weekly":
385
- current_date += relativedelta(weeks=1)
386
- elif recurrence == "Monthly":
387
- current_date += relativedelta(months=1)
388
- if current_date <= end_date:
389
- dates.append(current_date)
390
-
391
- # Batch write to Firestore
392
- batch = db.batch()
393
- for idx, task_date in enumerate(dates):
394
- task_ref = db.collection("tasks").document()
395
- batch.set(task_ref, {
396
- "user": st.session_state.email,
397
- "task": task.strip(),
398
- "type": task_type,
399
- "project": project,
400
- "status": status,
401
- "date": str(task_date),
402
- "recurrence": {
403
- "type": recurrence,
404
- "original_date": str(date),
405
- "sequence": idx + 1
406
- },
407
- "attachments": attachments,
408
- "created_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
409
- })
410
- batch.commit()
411
-
412
- st.success(f"βœ… Created {len(dates)} {'task' if len(dates) == 1 else 'tasks'} with {len(attachments)} attachments!")
413
- st.rerun()
414
-
415
- except cloudinary.exceptions.Error as e:
416
- st.error(f"❌ Cloudinary upload failed: {str(e)}")
417
- except Exception as e:
418
- st.error(f"❌ Error: {str(e)}")
419
 
420
  # Task Explorer (Updated Date Filter)
421
  elif menu == "πŸ‘€ Task Explorer":
 
300
 
301
  # Task Entry
302
  elif menu == "πŸ“₯ Task Entry":
303
+ with st.form(key="task_form", clear_on_submit=True): # Form starts here
304
  st.subheader("βž• Add New Task")
305
  col1, col2 = st.columns(2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
306
 
307
+ # Left Column
308
+ with col1:
309
+ task = st.text_area("πŸ“ Task Description", height=100)
310
+ task_type = st.selectbox(
311
+ "πŸ“¦ Task Type",
312
+ ["Design", "Procurement", "Construction", "Testing", "Other"]
 
 
 
 
313
  )
314
+
315
+ # Right Column
316
+ with col2:
317
+ projects = [p.id for p in db.collection("projects").stream()] + ["Add New Project"]
318
+ project = st.selectbox("πŸ—οΈ Project", projects)
319
+ if project == "Add New Project":
320
+ project = st.text_input("✨ New Project Name")
321
+
322
+ status = st.selectbox("πŸ“Œ Status", ["Pending", "In Progress", "Completed"])
323
+ date = st.date_input("πŸ“… Due Date", min_value=datetime.today())
 
 
 
 
 
324
 
325
+ recurrence = st.selectbox("πŸ”„ Repeat", ["None", "Daily", "Weekly", "Monthly"])
326
+ end_date = None
327
+ if recurrence != "None":
328
+ end_date = st.date_input(
329
+ "πŸ”š Repeat Until",
330
+ min_value=date + relativedelta(days=1),
331
+ help="Recurrence end date (inclusive)"
332
+ )
333
+
334
+ # File Upload Section
335
+ uploaded_files = st.file_uploader(
336
+ "πŸ“Ž Attachments",
337
+ type=["pdf", "docx", "xlsx", "png", "jpg", "jpeg"],
338
+ accept_multiple_files=True,
339
+ help="Upload relevant files (max 10MB each)"
340
+ )
341
+
342
+ # Submit Button - MUST be inside the form context
343
+ submitted = st.form_submit_button("πŸ’Ύ Save Task", use_container_width=True)
344
+
345
+ # Form Submission Handling
346
+ if submitted:
347
+ if not task.strip():
348
+ st.error("❌ Task description cannot be empty!")
349
  st.stop()
350
+
351
+ try:
352
+ # Validate recurrence
353
+ if recurrence != "None" and (not end_date or end_date <= date):
354
+ st.error("❌ End date must be after initial due date")
355
+ st.stop()
356
+
357
+ # Process attachments
358
+ attachments = []
359
+ if uploaded_files:
360
+ for file in uploaded_files:
361
+ if file.size > 10 * 1024 * 1024: # 10MB limit
362
+ st.error(f"❌ File {file.name} exceeds 10MB limit")
363
+ st.stop()
364
+
365
+ # Upload to Cloudinary
366
+ result = cloudinary.uploader.upload(
367
+ file,
368
+ folder=f"attachments/{st.session_state.user_uid}/",
369
+ resource_type="auto"
370
+ )
371
 
372
+ attachments.append({
373
+ "name": file.name,
374
+ "url": result['secure_url'],
375
+ "type": file.type,
376
+ "size": file.size
377
+ })
378
+
379
+ # Generate recurring dates
380
+ dates = [date]
381
+ if recurrence != "None":
382
+ current_date = date
383
+ while current_date < end_date:
384
+ if recurrence == "Daily":
385
+ current_date += relativedelta(days=1)
386
+ elif recurrence == "Weekly":
387
+ current_date += relativedelta(weeks=1)
388
+ elif recurrence == "Monthly":
389
+ current_date += relativedelta(months=1)
390
+ if current_date <= end_date:
391
+ dates.append(current_date)
392
+
393
+ # Batch write to Firestore
394
+ batch = db.batch()
395
+ for idx, task_date in enumerate(dates):
396
+ task_ref = db.collection("tasks").document()
397
+ batch.set(task_ref, {
398
+ "user": st.session_state.email,
399
+ "task": task.strip(),
400
+ "type": task_type,
401
+ "project": project,
402
+ "status": status,
403
+ "date": str(task_date),
404
+ "recurrence": {
405
+ "type": recurrence,
406
+ "original_date": str(date),
407
+ "sequence": idx + 1
408
+ },
409
+ "attachments": attachments,
410
+ "created_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
411
  })
412
+ batch.commit()
413
+
414
+ st.success(f"βœ… Created {len(dates)} {'task' if len(dates) == 1 else 'tasks'} with {len(attachments)} attachments!")
415
+ st.rerun()
416
+
417
+ except cloudinary.exceptions.Error as e:
418
+ st.error(f"❌ Cloudinary upload failed: {str(e)}")
419
+ except Exception as e:
420
+ st.error(f"❌ Error: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
 
422
  # Task Explorer (Updated Date Filter)
423
  elif menu == "πŸ‘€ Task Explorer":