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

Exam models date_created updates #12413

Merged
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
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