Files
chore/backend/models/chore_schedule.py
Ryan Kegel a197f8e206
Some checks failed
Chore App Build, Test, and Push Docker Images / build-and-push (push) Failing after 2m30s
feat: Refactor ScheduleModal to support interval scheduling with date input and deadline toggle
- Updated ChoreSchedule model to include anchor_date and interval_has_deadline.
- Refactored interval scheduling logic in scheduleUtils to use anchor_date.
- Introduced DateInputField component for selecting anchor dates in ScheduleModal.
- Enhanced ScheduleModal to include a stepper for interval days and a toggle for deadline.
- Updated tests for ScheduleModal and scheduleUtils to reflect new interval scheduling logic.
- Added DateInputField tests to ensure proper functionality and prop handling.
2026-02-26 15:16:46 -05:00

81 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from dataclasses import dataclass, field
from typing import Literal
from models.base import BaseModel
@dataclass
class DayConfig:
day: int # 0=Sun, 1=Mon, ..., 6=Sat
hour: int # 023 (24h)
minute: int # 0, 15, 30, or 45
def to_dict(self) -> dict:
return {
'day': self.day,
'hour': self.hour,
'minute': self.minute,
}
@classmethod
def from_dict(cls, d: dict) -> 'DayConfig':
return cls(
day=d.get('day', 0),
hour=d.get('hour', 0),
minute=d.get('minute', 0),
)
@dataclass
class ChoreSchedule(BaseModel):
child_id: str
task_id: str
mode: Literal['days', 'interval']
# mode='days' fields
day_configs: list = field(default_factory=list) # list of DayConfig dicts
default_hour: int = 8 # master deadline hour for 'days' mode
default_minute: int = 0 # master deadline minute for 'days' mode
# mode='interval' fields
interval_days: int = 2 # 17
anchor_date: str = "" # ISO date string e.g. "2026-02-25"; "" = use today
interval_has_deadline: bool = True # False = "Anytime" (no deadline)
interval_hour: int = 0
interval_minute: int = 0
@classmethod
def from_dict(cls, d: dict) -> 'ChoreSchedule':
return cls(
child_id=d.get('child_id'),
task_id=d.get('task_id'),
mode=d.get('mode', 'days'),
day_configs=d.get('day_configs', []),
default_hour=d.get('default_hour', 8),
default_minute=d.get('default_minute', 0),
interval_days=d.get('interval_days', 2),
anchor_date=d.get('anchor_date', ''),
interval_has_deadline=d.get('interval_has_deadline', True),
interval_hour=d.get('interval_hour', 0),
interval_minute=d.get('interval_minute', 0),
id=d.get('id'),
created_at=d.get('created_at'),
updated_at=d.get('updated_at'),
)
def to_dict(self) -> dict:
base = super().to_dict()
base.update({
'child_id': self.child_id,
'task_id': self.task_id,
'mode': self.mode,
'day_configs': self.day_configs,
'default_hour': self.default_hour,
'default_minute': self.default_minute,
'interval_days': self.interval_days,
'anchor_date': self.anchor_date,
'interval_has_deadline': self.interval_has_deadline,
'interval_hour': self.interval_hour,
'interval_minute': self.interval_minute,
})
return base