From b8e798a1f3751d4098b6d3c67e700d0d9d49154c Mon Sep 17 00:00:00 2001 From: usamabinnadeem-10 Date: Tue, 25 Jun 2024 15:34:16 +0500 Subject: [PATCH 1/3] fix exam statuses --- webapp/shop/cred/views.py | 130 ++++++++++++++------------------------ 1 file changed, 47 insertions(+), 83 deletions(-) diff --git a/webapp/shop/cred/views.py b/webapp/shop/cred/views.py index e0bf9dbffa4..da41cee663d 100644 --- a/webapp/shop/cred/views.py +++ b/webapp/shop/cred/views.py @@ -471,7 +471,7 @@ def cred_your_exams(ua_contracts_api, trueability_api, **kwargs): exam_contract.get("id") or exam_contract["contractItem"]["id"] ) contract_long_id = exam_contract["contractItem"]["contractID"] - + # if exam is scheduled if "reservation" in exam_contract["cueContext"]: response = trueability_api.get_assessment_reservation( exam_contract["cueContext"]["reservation"]["IDs"][-1] @@ -504,63 +504,59 @@ 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) - if "assessment" in r and r["assessment"] is not None: + if assessment_id: 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( - [ - { - "text": "Take exam", - "href": "/credentials/exam?" - f"id={assessment_id}", - "button_class": "p-button--positive", - } - ] + # if assessment is provisioned + if assessment_id: + is_in_window = (now > starts_at and now < end) or ( + now < starts_at + and now > starts_at - timedelta(minutes=30) ) - - 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 ( - 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", - } - ] + provisioned_but_not_taken = ( + is_in_window + and state == RESERVATION_STATES["provisioned"] ) - 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, - } - ) + if ( + state == RESERVATION_STATES["in_progress"] + or provisioned_but_not_taken + ): + actions.extend( + [ + { + "text": "Take exam", + "href": "/credentials/exam?" + f"id={assessment_id}", + "button_class": "p-button--positive", + } + ] + ) + + exam_data = { + "name": name, + "date": starts_at.strftime("%d %b %Y"), + "time": starts_at.strftime("%I:%M %p %Z"), + "timezone": timezone, + "state": state, + "uuid": r["uuid"], + "actions": actions, + } + + if state in [ + RESERVATION_STATES["completed"], + RESERVATION_STATES["finalized"], + RESERVATION_STATES["graded"], + ]: + exams_complete.append(exam_data) + else: + exams_in_progress.append(exam_data) + + # if at least 30 minutes away allow reschedule elif state == "Scheduled": if now + timedelta(minutes=30) < starts_at: actions.extend( @@ -587,40 +583,7 @@ def cred_your_exams(ua_contracts_api, trueability_api, **kwargs): "actions": actions, } ) - elif state in ( - "Completed", - "Graded", - "Grading", - "Finalized", - "Processed", - ): - exams_complete.append( - { - "name": name, - "date": starts_at.strftime("%d %b %Y"), - "time": starts_at.strftime("%I:%M %p %Z"), - "timezone": timezone, - "state": state, - "uuid": r["uuid"], - "actions": actions, - } - ) - elif state in ( - "Cancelled", - "Archiving", - "Archived", - ): - exams_cancelled.append( - { - "name": name, - "date": starts_at.strftime("%d %b %Y"), - "time": starts_at.strftime("%I:%M %p %Z"), - "timezone": timezone, - "state": state, - "uuid": r["uuid"], - "actions": [], - } - ) + # if exam expires elif ( "effectivenessContext" in exam_contract and "status" in exam_contract["effectivenessContext"] @@ -630,6 +593,7 @@ def cred_your_exams(ua_contracts_api, trueability_api, **kwargs): exams_expired.append( {"name": name, "state": "Expired", "actions": []} ) + # if exam is not used and is not expired else: actions = [ { From 5c3ee77980d553fd35f331b2fa1b55aa8381cb81 Mon Sep 17 00:00:00 2001 From: usamabinnadeem-10 Date: Tue, 25 Jun 2024 15:52:34 +0500 Subject: [PATCH 2/3] show ready to be taken --- webapp/shop/cred/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/webapp/shop/cred/views.py b/webapp/shop/cred/views.py index da41cee663d..9c97e5cff46 100644 --- a/webapp/shop/cred/views.py +++ b/webapp/shop/cred/views.py @@ -542,7 +542,9 @@ def cred_your_exams(ua_contracts_api, trueability_api, **kwargs): "date": starts_at.strftime("%d %b %Y"), "time": starts_at.strftime("%I:%M %p %Z"), "timezone": timezone, - "state": state, + "state": "Ready to be taken" + if provisioned_but_not_taken + else state, "uuid": r["uuid"], "actions": actions, } From da1ed3a9111845023924676e77254b3fa137e7ce Mon Sep 17 00:00:00 2001 From: usamabinnadeem-10 Date: Tue, 25 Jun 2024 17:54:37 +0500 Subject: [PATCH 3/3] override archived status and show continue button --- webapp/shop/cred/views.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/webapp/shop/cred/views.py b/webapp/shop/cred/views.py index 9c97e5cff46..d5d5275dbfa 100644 --- a/webapp/shop/cred/views.py +++ b/webapp/shop/cred/views.py @@ -511,16 +511,25 @@ def cred_your_exams(ua_contracts_api, trueability_api, **kwargs): else: state = RESERVATION_STATES.get(r["state"], r["state"]) + state = ( + RESERVATION_STATES["finalized"] + if state + in [ + RESERVATION_STATES["archived"], + RESERVATION_STATES["archiving"], + ] + else state + ) # if assessment is provisioned if assessment_id: is_in_window = (now > starts_at and now < end) or ( now < starts_at and now > starts_at - timedelta(minutes=30) ) - provisioned_but_not_taken = ( - is_in_window - and state == RESERVATION_STATES["provisioned"] - ) + provisioned_but_not_taken = is_in_window and state in [ + RESERVATION_STATES["notified"], + RESERVATION_STATES["provisioned"], + ] if ( state == RESERVATION_STATES["in_progress"] @@ -529,7 +538,10 @@ def cred_your_exams(ua_contracts_api, trueability_api, **kwargs): actions.extend( [ { - "text": "Take exam", + "text": "Continue exam" + if state + == RESERVATION_STATES["in_progress"] + else "Take exam", "href": "/credentials/exam?" f"id={assessment_id}", "button_class": "p-button--positive",