Skip to content

Commit

Permalink
Merge pull request #12413 from nucleogenesis/timzeonefordatecraetedexams
Browse files Browse the repository at this point in the history
Exam models date_created updates
  • Loading branch information
rtibbles authored Jul 3, 2024
2 parents 00d9db7 + 6141620 commit f5df846
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
5 changes: 4 additions & 1 deletion kolibri/core/exams/api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime

from django.http import Http404
from django.utils.timezone import now
from django_filters.rest_framework import DjangoFilterBackend
Expand Down Expand Up @@ -152,9 +154,10 @@ def list(self, request, *args, **kwargs):

# Consolidate the exam_queryset and draft_queryset
# and sort them by reverse date_created
dt_utc_aware = datetime.datetime.fromtimestamp(0, datetime.timezone.utc)
all_objects = sorted(
[*exam_objects, *draft_objects],
key=lambda x: x["date_created"],
key=lambda x: x["date_created"] or dt_utc_aware,
reverse=True,
)

Expand Down
19 changes: 19 additions & 0 deletions kolibri/core/exams/migrations/0009_alter_exam_date_created.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.2.25 on 2024-07-03 21:46
import django.utils.timezone
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
("exams", "0008_draft_exams"),
]

operations = [
migrations.AlterField(
model_name="exam",
name="date_created",
field=models.DateTimeField(default=django.utils.timezone.now),
),
]
6 changes: 3 additions & 3 deletions kolibri/core/exams/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ class Meta:
"""
data_model_version = models.SmallIntegerField(default=3)

date_created = models.DateTimeField(auto_now_add=True, null=True)

def __str__(self):
return self.title

Expand Down Expand Up @@ -196,6 +194,8 @@ class DraftExam(AbstractExam):
assignments = JSONField(default=list, blank=True)
learner_ids = JSONField(default=list, blank=True)

date_created = models.DateTimeField(auto_now_add=True, null=True)

def to_exam(self):
"""
Convert this draft exam to an exam object.
Expand Down Expand Up @@ -235,7 +235,7 @@ class Exam(AbstractExam, AbstractFacilityDataModel):
# Is this exam currently active and visible to students to whom it is assigned?
active = models.BooleanField(default=False)

date_created = models.DateTimeField(null=True)
date_created = models.DateTimeField(default=timezone.now)

# To be set True when the quiz is first set to active=True
date_activated = models.DateTimeField(default=None, null=True, blank=True)
Expand Down

0 comments on commit f5df846

Please sign in to comment.