Skip to content

Commit

Permalink
feat(models): enhance string representation for Booking and OtfClass
Browse files Browse the repository at this point in the history
Update date format in __str__ methods for better readability.
Include booking status in Booking and class availability in OtfClass
to provide more detailed information in string output.
  • Loading branch information
NodeJSmith committed Jan 8, 2025
1 parent 81a0a2b commit b31a008
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/otf_api/models/bookings.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ class Booking(OtfItemBase):
is_home_studio: bool | None = Field(None, description="Custom helper field to determine if at home studio")

def __str__(self) -> str:
class_starts_at_str = self.otf_class.starts_at_local.strftime("%Y-%m-%d %H:%M:%S")
starts_at_str = self.otf_class.starts_at_local.strftime("%a %b %d, %I:%M %p")
class_name = self.otf_class.name
coach_name = self.otf_class.coach.name
return f"{class_starts_at_str} {class_name} with {coach_name}"
booked_str = self.status.value

return f"Booking: {starts_at_str} {class_name} - {coach_name} ({booked_str})"


class BookingList(OtfItemBase):
Expand Down
13 changes: 11 additions & 2 deletions src/otf_api/models/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,18 @@ class OtfClass(OtfItemBase, OtfClassTimeMixin):
is_booked: bool | None = Field(None, description="Custom helper field to determine if class is already booked")

def __str__(self) -> str:
starts_at_str = self.starts_at_local.strftime("%Y-%m-%d %H:%M:%S")
starts_at_str = self.starts_at_local.strftime("%a %b %d, %I:%M %p")
coach_name = self.coach.first_name
return f"{starts_at_str} {self.name} with {coach_name}"
booked_str = ""
if self.is_booked:
booked_str = "Booked"
elif self.has_availability:
booked_str = "Available"
elif self.waitlist_available:
booked_str = "Waitlist Available"
else:
booked_str = "Full"
return f"Class: {starts_at_str} {self.name} - {coach_name} ({booked_str})"

@property
def has_availability(self) -> bool:
Expand Down

0 comments on commit b31a008

Please sign in to comment.