Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wd 8766 Your Exams page logic overhaul #13651

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion templates/credentials/schedule.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h1 class="p-heading--2"><strong>Schedule your exam</strong></h1>
</section>

<script>
{% if timezone %}
{% if timezone and timezone!="" %}
const timezone = "{{ timezone }}";
{% else %}
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
Expand Down
3 changes: 2 additions & 1 deletion webapp/shop/api/ua_contracts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def post_assessment_reservation(
starts_at,
country_code,
) -> dict:
return self._request(
req = self._request(
method="get",
path="v1/cue/schedule",
json={
Expand All @@ -374,6 +374,7 @@ def post_assessment_reservation(
},
error_rules=["default"],
).json()
return req

def delete_assessment_reservation(self, contract_item_id) -> dict:
self._request(
Expand Down
95 changes: 77 additions & 18 deletions webapp/shop/cred/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@
"scheduled": "Scheduled",
"processed": "Complete",
"canceled": "Cancelled",
"finalized": "Complete",
"provisioning": "In Progress",
"provisioned": "In Progress",
"in_progress": "In Progress",
"completed": "Complete",
"grading": "Complete",
"graded": "Complete",
"archiving": "Complete",
"archived": "Complete",
"canceling": "Cancelled",
}


Expand Down Expand Up @@ -107,10 +117,21 @@ 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 +145,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 All @@ -134,7 +155,7 @@ def cred_schedule(ua_contracts_api, trueability_api, **_):
exam = {
"name": "CUE: Linux",
"date": starts_at.strftime("%d %b %Y"),
"time": starts_at.strftime("%I:%M %p %Z"),
"time": starts_at.strftime("%I:%M %p ") + timezone,
"uuid": uuid,
"contract_item_id": contract_item_id,
}
Expand Down Expand Up @@ -210,17 +231,6 @@ def cred_your_exams(ua_contracts_api, trueability_api, **kwargs):
exam_contract.get("id") or exam_contract["contractItem"]["id"]
)

if (
"effectivenessContext" in exam_contract
and "status" in exam_contract["effectivenessContext"]
and exam_contract["effectivenessContext"]["status"]
== "expired"
):
exams_expired.append(
{"name": name, "state": "Expired", "actions": []}
)
continue

if "reservation" in exam_contract["cueContext"]:
response = trueability_api.get_assessment_reservation(
exam_contract["cueContext"]["reservation"]["IDs"][-1]
Expand All @@ -240,7 +250,12 @@ def cred_your_exams(ua_contracts_api, trueability_api, **kwargs):
utc = pytz.timezone("UTC")
now = utc.localize(datetime.utcnow())
end = starts_at + timedelta(minutes=75)
state = RESERVATION_STATES.get(r["state"], r["state"])
if "assessment" in r and r["assessment"] is not None:
state = RESERVATION_STATES.get(
r["assessment"]["state"], r["state"]
)
else:
state = RESERVATION_STATES.get(r["state"], r["state"])

if assessment_id and now > starts_at and now < end:
actions.extend(
Expand All @@ -265,8 +280,36 @@ def cred_your_exams(ua_contracts_api, trueability_api, **kwargs):
"actions": actions,
}
)
elif (
assessment_id
and now < starts_at
and now > starts_at - timedelta(minutes=30)
):
actions.extend(
[
{
"text": "Take exam",
"href": "/credentials/exam?"
f"id={ assessment_id }",
"button_class": "p-button",
}
]
)

elif state == "Scheduled":
exams_in_progress.append(
{
"name": name,
"date": starts_at.strftime("%d %b %Y"),
"time": starts_at.strftime("%I:%M %p %Z"),
"timezone": timezone,
"state": "In progress",
"uuid": r["uuid"],
"actions": actions,
}
)
elif state == "Scheduled" and starts_at > now + timedelta(
minutes=30
):
actions.extend(
[
{
Expand Down Expand Up @@ -303,6 +346,13 @@ def cred_your_exams(ua_contracts_api, trueability_api, **kwargs):
}
)
elif state == "Cancelled":
actions = [
{
"text": "Take",
"button_class": "p-button--base",
"href": "",
}
]
exams_cancelled.append(
{
"name": name,
Expand All @@ -314,6 +364,15 @@ def cred_your_exams(ua_contracts_api, trueability_api, **kwargs):
"actions": actions,
}
)
elif (
"effectivenessContext" in exam_contract
and "status" in exam_contract["effectivenessContext"]
and exam_contract["effectivenessContext"]["status"]
== "expired"
):
exams_expired.append(
{"name": name, "state": "Expired", "actions": []}
)
else:
actions = [
{
Expand Down
Loading