Skip to content

Commit

Permalink
set the real exam start time from attempt data
Browse files Browse the repository at this point in the history
Until now, the Attempt.start_time field was set when the attempt record
is created, but the student might not click "Start" in the Numbas
interface until much later.

This adds a signal listening for the cmi.suspend_data SCORM element, and
updates start_time using the 'start' key in that if it's different.
  • Loading branch information
christianp committed Jan 13, 2021
1 parent 293efbb commit 476a3a2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions numbas_lti/models.py
Expand Up @@ -1106,6 +1106,24 @@ def scorm_set_completion_status(sender,instance,created,**kwargs):
else:
Channel('report.attempt').send({'pk':instance.attempt.pk})

@receiver(models.signals.post_save,sender=ScormElement)
def scorm_set_start_time(sender,instance,created,**kwargs):
if instance.key != 'cmi.suspend_data':
return

try:
data = json.loads(instance.value)
if data['start'] is not None:
start_time = timezone.make_aware(datetime.fromtimestamp(data['start']/1000))
else:
return
except (json.JSONDecodeError, KeyError):
return

if start_time != instance.attempt.start_time:
instance.attempt.start_time = start_time
instance.attempt.save(update_fields=['start_time'])

@receiver(models.signals.post_save,sender=Attempt)
def send_receipt_on_completion(sender,instance, **kwargs):
try:
Expand Down

0 comments on commit 476a3a2

Please sign in to comment.