Skip to content

data_containers

Storage Containers for the Application

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]]

CampsiteLocation #

Bases: CamplyModel

Campsite Location Storage

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

    latitude: Optional[float] = None
    longitude: Optional[float] = None

ListedCampsite #

Bases: CamplyModel

A Campsite Meant to Be Listed

Source code in camply/containers/data_containers.py
class ListedCampsite(CamplyModel):
    """
    A Campsite Meant to Be Listed
    """

    name: str
    id: int
    facility_id: int

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

WebhookBody #

Bases: CamplyModel

Webhook Body

Source code in camply/containers/data_containers.py
class WebhookBody(CamplyModel):
    """
    Webhook Body
    """

    campsites: List[AvailableCampsite]
    timestamp: datetime.datetime = Field(
        default_factory=partial(datetime.datetime.now, tz=datetime.timezone.utc)
    )