Skip to content

containers

camply Data Storage Objects

AvailableCampsite #

Bases: CamplyModel

Campsite Storage

This container should be universal regardless of API Provider

Source code in camply/containers/data_containers.py
class AvailableCampsite(CamplyModel):
    """
    Campsite Storage

    This container should be universal regardless of API Provider
    """

    campsite_id: Union[int, str]
    booking_date: datetime.datetime
    booking_end_date: datetime.datetime
    booking_nights: int
    campsite_site_name: str
    campsite_loop_name: Optional[str]
    campsite_type: Optional[str]
    campsite_occupancy: Tuple[int, int]
    campsite_use_type: Optional[str]
    availability_status: str
    recreation_area: str
    recreation_area_id: Union[int, str]
    facility_name: str
    facility_id: Union[int, str]
    booking_url: str
    location: Optional[CampsiteLocation] = None

    permitted_equipment: Optional[List[RecDotGovEquipment]]
    campsite_attributes: Optional[List[RecDotGovAttribute]]

    __unhashable__ = {"permitted_equipment", "campsite_attributes", "location"}

AvailableResource #

Bases: CamplyModel

A resource that is available for booking

Source code in camply/containers/data_containers.py
class AvailableResource(CamplyModel):
    """
    A resource that is available for booking
    """

    resource_id: int
    map_id: int

CampgroundFacility #

Bases: CamplyModel

Campground Facility Data Storage

Source code in camply/containers/data_containers.py
class CampgroundFacility(CamplyModel):
    """
    Campground Facility Data Storage
    """

    facility_name: str
    recreation_area: str
    facility_id: Union[int, str]
    recreation_area_id: Union[int, str]
    map_id: Optional[int]
    coordinates: Optional[Tuple[float, float]]

CamplyModel #

Bases: BaseModel

Hashable Pydantic Model

Source code in camply/containers/base_container.py
class CamplyModel(BaseModel):
    """
    Hashable Pydantic Model
    """

    __unhashable__: Set[str] = set()

    def __hash__(self):
        """
        Hash Method for Pydantic BaseModels
        """
        return hash(self.__class__) + hash(
            tuple(
                value
                for key, value in self.__dict__.items()
                if key not in self.__unhashable__
            )
        )

    def __eq__(self, other: Any) -> bool:
        """
        Exclude Unhashable Fields When Evaluating Equality
        """
        if isinstance(other, CamplyModel):
            return self.dict(exclude=self.__unhashable__) == other.dict(
                exclude=other.__unhashable__
            )
        else:
            return self.dict(exclude=self.__unhashable__) == other

    class Config:
        """
        Camply Wide Configuration
        """

        anystr_strip_whitespace = True

Config #

Camply Wide Configuration

Source code in camply/containers/base_container.py
class Config:
    """
    Camply Wide Configuration
    """

    anystr_strip_whitespace = True

__eq__(other) #

Exclude Unhashable Fields When Evaluating Equality

Source code in camply/containers/base_container.py
def __eq__(self, other: Any) -> bool:
    """
    Exclude Unhashable Fields When Evaluating Equality
    """
    if isinstance(other, CamplyModel):
        return self.dict(exclude=self.__unhashable__) == other.dict(
            exclude=other.__unhashable__
        )
    else:
        return self.dict(exclude=self.__unhashable__) == other

__hash__() #

Hash Method for Pydantic BaseModels

Source code in camply/containers/base_container.py
def __hash__(self):
    """
    Hash Method for Pydantic BaseModels
    """
    return hash(self.__class__) + hash(
        tuple(
            value
            for key, value in self.__dict__.items()
            if key not in self.__unhashable__
        )
    )

RecreationArea #

Bases: CamplyModel

Recreation Area Data Storage

Source code in camply/containers/data_containers.py
class RecreationArea(CamplyModel):
    """
    Recreation Area Data Storage
    """

    recreation_area: str
    recreation_area_id: Union[int, str]
    recreation_area_location: str
    coordinates: Optional[Tuple[float, float]]
    description: Optional[str]

SearchWindow #

Bases: CamplyModel

Search Window for Campsite Search

Source code in camply/containers/data_containers.py
class SearchWindow(CamplyModel):
    """
    Search Window for Campsite Search
    """

    @validator("start_date")
    @classmethod
    def start_date_must_be_in_future(cls, v):
        """
        Validate that start_date is in the future.

        Coerece start date to today's date when it is not in the future.
        """
        current_date = datetime.datetime.now().date()
        if v < current_date:
            return current_date

        return v

    @validator("end_date")
    @classmethod
    def end_date_must_be_in_future(cls, v):
        """
        Validate that end_date is in the future
        """
        current_date = datetime.datetime.now().date()
        if v < current_date:
            raise ValueError("must be in the future")

        return v

    start_date: datetime.date
    end_date: datetime.date

    def get_date_range(self) -> List[datetime.date]:
        """
        Generate a List of Dates Between two Dates

        Returns
        -------
        List[datetime.date]
        """
        return [
            self.start_date + datetime.timedelta(days=x)
            for x in range((self.end_date - self.start_date).days)
        ]

    def get_current_start_date(self) -> datetime.date:
        """
        Return a start date with the current day in mind
        """
        return max((datetime.datetime.now().date(), self.start_date))

end_date_must_be_in_future(v) classmethod #

Validate that end_date is in the future

Source code in camply/containers/data_containers.py
@validator("end_date")
@classmethod
def end_date_must_be_in_future(cls, v):
    """
    Validate that end_date is in the future
    """
    current_date = datetime.datetime.now().date()
    if v < current_date:
        raise ValueError("must be in the future")

    return v

get_current_start_date() #

Return a start date with the current day in mind

Source code in camply/containers/data_containers.py
def get_current_start_date(self) -> datetime.date:
    """
    Return a start date with the current day in mind
    """
    return max((datetime.datetime.now().date(), self.start_date))

get_date_range() #

Generate a List of Dates Between two Dates

Returns:

Type Description
List[date]
Source code in camply/containers/data_containers.py
def get_date_range(self) -> List[datetime.date]:
    """
    Generate a List of Dates Between two Dates

    Returns
    -------
    List[datetime.date]
    """
    return [
        self.start_date + datetime.timedelta(days=x)
        for x in range((self.end_date - self.start_date).days)
    ]

start_date_must_be_in_future(v) classmethod #

Validate that start_date is in the future.

Coerece start date to today's date when it is not in the future.

Source code in camply/containers/data_containers.py
@validator("start_date")
@classmethod
def start_date_must_be_in_future(cls, v):
    """
    Validate that start_date is in the future.

    Coerece start date to today's date when it is not in the future.
    """
    current_date = datetime.datetime.now().date()
    if v < current_date:
        return current_date

    return v