merge from main

This commit is contained in:
Kenneth Kehl
2023-12-04 07:12:34 -08:00
3 changed files with 38 additions and 2 deletions

View File

@@ -1,5 +1,9 @@
import datetime
from zoneinfo import ZoneInfo
from app.extensions import redis_client
from app.notify_client import NotifyAdminAPIClient, _attach_current_user, cache
from app.utils.csv import get_user_preferred_timezone
class JobApiClient(NotifyAdminAPIClient):
@@ -86,10 +90,26 @@ class JobApiClient(NotifyAdminAPIClient):
def has_jobs(self, service_id):
return bool(self.get_jobs(service_id)["data"])
@classmethod
def convert_user_time_to_utc(cls, scheduled_for):
user_preferred_tz = get_user_preferred_timezone()
user_date = datetime.datetime.fromisoformat(scheduled_for)
scheduled_for = (
user_date.replace(tzinfo=ZoneInfo(user_preferred_tz))
.astimezone(ZoneInfo("UTC"))
.strftime("%Y-%m-%dT%H:%M:%S")
)
return scheduled_for
def create_job(self, job_id, service_id, scheduled_for=None):
data = {"id": job_id}
# make a datetime object in the user's preferred timezone
if scheduled_for:
scheduled_for = JobApiClient.convert_user_time_to_utc(scheduled_for)
data.update({"scheduled_for": scheduled_for})
data = _attach_current_user(data)

View File

@@ -117,6 +117,14 @@ def hide_from_search_engines(f):
return decorated_function
# Function used for debugging.
# Do print(hilite(message)) while debugging, then remove your print statements
def hilite(message):
ansi_green = "\033[32m"
ansi_reset = "\033[0m"
return f"{ansi_green}{message}{ansi_reset}"
# Function to merge two dict or lists with a JSON-like structure into one.
# JSON-like means they can contain all types JSON can: all the main primitives
# plus nested lists or dictionaries.