oncall-engine/engine/common/timezones.py
Joey Orlando 74b919ee3e
shift swap requests model + CRUD endpoints (#2597)
# What this PR does

This PR should allow us to start working on _most_ of the remaining
tasks for this feature set.
- Adds a basic `ShiftSwapRequest` model + CRUD endpoints. 
- Adds a `POST /api/internal/v1/shift_swaps/<id>/take` endpoint which
allows a benefactor to take a request (only when certain conditions
about the ssr are met)

Closes #2587 

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required) will be done in #2589
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required) (will update once we ship the finalized feature set)
2023-07-21 19:35:19 +00:00

21 lines
665 B
Python

import pytz
from common.api_helpers.exceptions import BadRequest
def is_valid_timezone(timezone: str):
try:
return pytz.timezone(timezone)
except pytz.UnknownTimeZoneError:
return False
def raise_exception_if_not_valid_timezone(timezone, exception_class=BadRequest):
"""
Like `is_valid_timezone` but throws specified "exception_class" class
(default `common.api_helpers.exceptions.BadRequest`) if not a valid timezone.
**NOTE**: if `exception_class` is provided, it should take a `detail` kwarg in its constructor
"""
if not is_valid_timezone(timezone):
raise exception_class(detail="Invalid timezone")