Exemple #1
0
    def _deserialize(self, value: str, attr: str,
                     data: dict) -> Optional[SimpleHoursPeriod]:
        """Deserialize to a SimpleHoursPeriod object."""
        if value == "all":
            return None

        try:
            return SimpleHoursPeriod.from_short_form(value)
        except ValueError:
            raise ValidationError("Invalid time period")
Exemple #2
0
    def _deserialize(
        self,
        value: str,
        attr: Optional[str],
        data: DataType,
        **kwargs: Any,
    ) -> Optional[SimpleHoursPeriod]:
        """Deserialize to a SimpleHoursPeriod object."""
        if value == "all":
            return None

        try:
            return SimpleHoursPeriod.from_short_form(value)
        except ValueError as exc:
            raise ValidationError("Invalid time period") from exc