Skip to content

Commit

Permalink
fix: add conditions for minimum timedelta in scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
abhigyanghosh30 committed Jan 4, 2024
1 parent 722fea2 commit fbcd8a0
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions webapp/shop/cred/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime, timedelta
import math
import sched
import pytz
import flask
import json
Expand Down Expand Up @@ -107,10 +108,20 @@ def cred_schedule(ua_contracts_api, trueability_api, **_):

timezone = data["timezone"]
tz_info = pytz.timezone(timezone)
scheduled_time = f"{data['date']}T{data['time']}"
starts_at = tz_info.localize(
datetime.strptime(scheduled_time, "%Y-%m-%dT%H:%M")
scheduled_time = datetime.strptime(
f"{data['date']}T{data['time']}", "%Y-%m-%dT%H:%M"
)
if scheduled_time < datetime.now():
error = "You cannot schedule an exam in the past."
return flask.render_template(
"/credentials/schedule.html", error=error
)
if scheduled_time < now + timedelta(minutes=30):
error = "You cannot schedule an exam less than 30 minutes in the future."
return flask.render_template(
"/credentials/schedule.html", error=error
)
starts_at = tz_info.localize(scheduled_time)
contract_item_id = data["contractItemID"]
first_name, last_name = get_user_first_last_name()
country_code = TIMEZONE_COUNTRIES[timezone]
Expand All @@ -124,7 +135,7 @@ def cred_schedule(ua_contracts_api, trueability_api, **_):
country_code,
)

if response and "error" in response:
if response and "reservation" not in response:
error = response["message"]
return flask.render_template(
"/credentials/schedule.html", error=error
Expand Down

0 comments on commit fbcd8a0

Please sign in to comment.