arif670 commited on
Commit
e66172d
Β·
verified Β·
1 Parent(s): f80f379

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -24
app.py CHANGED
@@ -300,7 +300,7 @@ def main():
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
 
@@ -322,14 +322,31 @@ def main():
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(
@@ -339,10 +356,9 @@ def main():
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!")
@@ -350,9 +366,13 @@ def main():
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 = []
@@ -380,14 +400,24 @@ def main():
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
@@ -404,6 +434,9 @@ def main():
404
  "recurrence": {
405
  "type": recurrence,
406
  "original_date": str(date),
 
 
 
407
  "sequence": idx + 1
408
  },
409
  "attachments": attachments,
@@ -425,12 +458,11 @@ def main():
425
  if tasks:
426
  df = pd.DataFrame(tasks)
427
 
428
- # Ensure 'attachments' column exists and is a list
429
  if 'attachments' not in df.columns:
430
- df['attachments'] = [[] for _ in range(len(df))] # Initialize with empty lists
431
-
432
- # Convert NaN values to empty lists
433
- df['attachments'] = df['attachments'].apply(lambda x: x if isinstance(x, list) else [])
434
 
435
  # Filters
436
  col1, col2, col3 = st.columns(3)
@@ -484,9 +516,19 @@ def main():
484
  </div>
485
  """, unsafe_allow_html=True)
486
 
 
 
 
 
 
 
 
 
 
 
487
  # Attachments
488
  attachments = row['attachments']
489
- if attachments: # Check if attachments exist
490
  with st.expander(f"πŸ“Ž Attachments ({len(attachments)})"):
491
  for att in attachments:
492
  st.markdown(f"""
 
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
 
 
322
  status = st.selectbox("πŸ“Œ Status", ["Pending", "In Progress", "Completed"])
323
  date = st.date_input("πŸ“… Due Date", min_value=datetime.today())
324
 
325
+ # Recurrence Settings
326
  recurrence = st.selectbox("πŸ”„ Repeat", ["None", "Daily", "Weekly", "Monthly"])
327
+ end_condition = None
328
  end_date = None
329
+ num_occurrences = None
330
  if recurrence != "None":
331
+ end_condition = st.radio(
332
+ "End Condition",
333
+ ["End Date", "Number of Occurrences"],
334
+ horizontal=True
335
  )
336
+ if end_condition == "End Date":
337
+ end_date = st.date_input(
338
+ "Repeat Until",
339
+ min_value=date + relativedelta(days=1),
340
+ help="Recurrence end date (inclusive)"
341
+ )
342
+ else:
343
+ num_occurrences = st.number_input(
344
+ "Number of Occurrences",
345
+ min_value=2,
346
+ max_value=365,
347
+ value=5,
348
+ help="Total number of task instances"
349
+ )
350
 
351
  # File Upload Section
352
  uploaded_files = st.file_uploader(
 
356
  help="Upload relevant files (max 10MB each)"
357
  )
358
 
359
+ # Submit Button
360
  submitted = st.form_submit_button("πŸ’Ύ Save Task", use_container_width=True)
361
 
 
362
  if submitted:
363
  if not task.strip():
364
  st.error("❌ Task description cannot be empty!")
 
366
 
367
  try:
368
  # Validate recurrence
369
+ if recurrence != "None":
370
+ if end_condition == "End Date" and (not end_date or end_date <= date):
371
+ st.error("❌ End date must be after initial due date")
372
+ st.stop()
373
+ elif end_condition == "Number of Occurrences" and num_occurrences < 2:
374
+ st.error("❌ Number of occurrences must be at least 2")
375
+ st.stop()
376
 
377
  # Process attachments
378
  attachments = []
 
400
  dates = [date]
401
  if recurrence != "None":
402
  current_date = date
403
+ if end_condition == "End Date":
404
+ while current_date < end_date:
405
+ if recurrence == "Daily":
406
+ current_date += relativedelta(days=1)
407
+ elif recurrence == "Weekly":
408
+ current_date += relativedelta(weeks=1)
409
+ elif recurrence == "Monthly":
410
+ current_date += relativedelta(months=1)
411
+ if current_date <= end_date:
412
+ dates.append(current_date)
413
+ else:
414
+ for _ in range(num_occurrences - 1):
415
+ if recurrence == "Daily":
416
+ current_date += relativedelta(days=1)
417
+ elif recurrence == "Weekly":
418
+ current_date += relativedelta(weeks=1)
419
+ elif recurrence == "Monthly":
420
+ current_date += relativedelta(months=1)
421
  dates.append(current_date)
422
 
423
  # Batch write to Firestore
 
434
  "recurrence": {
435
  "type": recurrence,
436
  "original_date": str(date),
437
+ "end_condition": end_condition,
438
+ "end_date": str(end_date) if end_condition == "End Date" else None,
439
+ "num_occurrences": num_occurrences if end_condition == "Number of Occurrences" else None,
440
  "sequence": idx + 1
441
  },
442
  "attachments": attachments,
 
458
  if tasks:
459
  df = pd.DataFrame(tasks)
460
 
461
+ # Ensure 'attachments' and 'recurrence' columns exist
462
  if 'attachments' not in df.columns:
463
+ df['attachments'] = [[] for _ in range(len(df))]
464
+ if 'recurrence' not in df.columns:
465
+ df['recurrence'] = [{} for _ in range(len(df))]
 
466
 
467
  # Filters
468
  col1, col2, col3 = st.columns(3)
 
516
  </div>
517
  """, unsafe_allow_html=True)
518
 
519
+ # Recurrence Details
520
+ if row['recurrence'].get('type') != "None":
521
+ with st.expander("πŸ” Recurrence Details"):
522
+ st.write(f"**Type:** {row['recurrence']['type']}")
523
+ st.write(f"**Start Date:** {row['recurrence']['original_date']}")
524
+ if row['recurrence'].get('end_date'):
525
+ st.write(f"**End Date:** {row['recurrence']['end_date']}")
526
+ else:
527
+ st.write(f"**Occurrences:** {row['recurrence']['num_occurrences']}")
528
+
529
  # Attachments
530
  attachments = row['attachments']
531
+ if attachments:
532
  with st.expander(f"πŸ“Ž Attachments ({len(attachments)})"):
533
  for att in attachments:
534
  st.markdown(f"""