Spaces:
Runtime error
Runtime error
Download schemas/task.py from MaheenGhouri/fullstack_todo_app: direct link, hf CLI and curl.
- Browser
- Download file 2.02 kB
-
https://huggingface.co/spaces/MaheenGhouri/fullstack_todo_app/resolve/main/schemas/task.py
- Command line
-
hf download hf://spaces/MaheenGhouri/fullstack_todo_app/schemas/task.py
-
curl -L -o task.py https://huggingface.co/spaces/MaheenGhouri/fullstack_todo_app/resolve/main/schemas/task.py
2.02 kB
| from pydantic import BaseModel, field_validator | |
| from datetime import datetime | |
| from typing import Optional | |
| import uuid | |
| def parse_date_string(value): | |
| """Parse date string to datetime""" | |
| if isinstance(value, datetime): | |
| return value | |
| if isinstance(value, str): | |
| # Handle YYYY-MM-DD format from HTML date input | |
| if len(value) == 10 and '-' in value: | |
| try: | |
| return datetime.strptime(value, '%Y-%m-%d') | |
| except ValueError: | |
| pass | |
| # Try ISO format | |
| try: | |
| return datetime.fromisoformat(value.replace('Z', '+00:00')) | |
| except ValueError: | |
| pass | |
| return None | |
| class TaskBase(BaseModel): | |
| title: str | |
| description: Optional[str] = None | |
| status: Optional[str] = "todo" # "todo", "done" | |
| priority: Optional[str] = "medium" # "low", "medium", "high" | |
| due_date: Optional[datetime] = None | |
| def validate_due_date(cls, v): | |
| if v is None: | |
| return None | |
| parsed = parse_date_string(v) | |
| if parsed is None and isinstance(v, str): | |
| # Return string for frontend, let Pydantic handle conversion | |
| return None | |
| return parsed | |
| class TaskCreate(TaskBase): | |
| pass | |
| class TaskUpdate(BaseModel): | |
| title: Optional[str] = None | |
| description: Optional[str] = None | |
| status: Optional[str] = None # "todo", "done" | |
| priority: Optional[str] = None # "low", "medium", "high" | |
| due_date: Optional[datetime] = None | |
| def validate_due_date(cls, v): | |
| if v is None: | |
| return None | |
| parsed = parse_date_string(v) | |
| if parsed is None and isinstance(v, str): | |
| return None | |
| return parsed | |
| class TaskResponse(TaskBase): | |
| id: uuid.UUID | |
| created_at: datetime | |
| updated_at: datetime | |
| user_id: uuid.UUID | |
| class Config: | |
| from_attributes = True |