Examples and code quality

This commit is contained in:
Nitzan Pomerantz
2025-10-31 00:31:14 +02:00
parent e4aa6487ff
commit 739d4f8578
9 changed files with 508 additions and 27 deletions
+8 -12
View File
@@ -334,34 +334,30 @@ class DealFilters(BaseModel):
@classmethod
def validate_max_rooms(cls, v: Optional[float], info) -> Optional[float]:
"""Ensure max_rooms >= min_rooms if both specified."""
if v is not None and info.data.get("min_rooms") is not None:
if v < info.data["min_rooms"]:
raise ValueError("max_rooms must be >= min_rooms")
if v is not None and info.data.get("min_rooms") is not None and v < info.data["min_rooms"]:
raise ValueError("max_rooms must be >= min_rooms")
return v
@field_validator("max_price")
@classmethod
def validate_max_price(cls, v: Optional[float], info) -> Optional[float]:
"""Ensure max_price >= min_price if both specified."""
if v is not None and info.data.get("min_price") is not None:
if v < info.data["min_price"]:
raise ValueError("max_price must be >= min_price")
if v is not None and info.data.get("min_price") is not None and v < info.data["min_price"]:
raise ValueError("max_price must be >= min_price")
return v
@field_validator("max_area")
@classmethod
def validate_max_area(cls, v: Optional[float], info) -> Optional[float]:
"""Ensure max_area >= min_area if both specified."""
if v is not None and info.data.get("min_area") is not None:
if v < info.data["min_area"]:
raise ValueError("max_area must be >= min_area")
if v is not None and info.data.get("min_area") is not None and v < info.data["min_area"]:
raise ValueError("max_area must be >= min_area")
return v
@field_validator("max_floor")
@classmethod
def validate_max_floor(cls, v: Optional[int], info) -> Optional[int]:
"""Ensure max_floor >= min_floor if both specified."""
if v is not None and info.data.get("min_floor") is not None:
if v < info.data["min_floor"]:
raise ValueError("max_floor must be >= min_floor")
if v is not None and info.data.get("min_floor") is not None and v < info.data["min_floor"]:
raise ValueError("max_floor must be >= min_floor")
return v
+5 -5
View File
@@ -83,11 +83,11 @@ def is_same_building(search_address: str, deal_address: str) -> bool:
return True
# Check if one address is contained in the other (for different formats of same address)
if len(search_address) > 5 and len(deal_address) > 5:
if search_address in deal_address or deal_address in search_address:
return True
return False
return (
len(search_address) > 5
and len(deal_address) > 5
and (search_address in deal_address or deal_address in search_address)
)
def extract_floor_number(floor_str: str) -> int | None: