Skip to content

Commit 5b10101

Browse files
committed
add expiration date
1 parent b7877b2 commit 5b10101

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

backend/Pipfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
8+
[dev-packages]
9+
10+
[requires]
11+
python_version = "3.11"

backend/courses/management/commands/cache_course_reviews.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from tqdm import tqdm
22
from django.core.management.base import BaseCommand
33
from django.db import transaction
4+
import django.utils.timezone as timezone
45

56
from courses.models import Course, Section
67
from courses.models import course_reviews, sections_with_reviews
@@ -29,7 +30,6 @@ def handle(self, *args, **options):
2930
self.stdout.write(self.style.SUCCESS("Finished calculating Section review averages."))
3031

3132
def update_courses(self):
32-
print("Starting this lol")
3333
queryset = course_reviews(
3434
Course.objects.all(),
3535
prefix=PREFIX,
@@ -40,6 +40,7 @@ def update_courses(self):
4040
for course in tqdm(queryset, desc="Updating Courses", file=self.stdout):
4141
for field in REVIEW_FIELDS:
4242
setattr(course, field, getattr(course, PREFIX + field))
43+
course.annotation_expiration = timezone.now + timezone.timedelta(days=30)
4344
courses_to_update.append(course)
4445

4546
with transaction.atomic():
@@ -60,6 +61,7 @@ def update_sections(self):
6061
for section in tqdm(queryset, desc="Updating Sections", file=self.stdout):
6162
for field in REVIEW_FIELDS:
6263
setattr(section, field, getattr(section, PREFIX + field))
64+
section.annotation_expiration = timezone.now + timezone.timedelta(days=30)
6365
sections_to_update.append(section)
6466

6567
with transaction.atomic():
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Generated by Django 5.0.2 on 2026-02-20 22:47
2+
3+
import django.utils.timezone
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
("courses", "0071_course_num_activities"),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name="course",
16+
name="annotations_expiration",
17+
field=models.DateTimeField(
18+
default=django.utils.timezone.now,
19+
help_text="\nThe expiration time for the annotations of this course, these fields should be refreshed\nevery month\n",
20+
),
21+
),
22+
migrations.AddField(
23+
model_name="section",
24+
name="annotation_expiration",
25+
field=models.DateTimeField(
26+
default=django.utils.timezone.now,
27+
help_text="\nThe expiration time for the annotations of this section, these fields should be refreshed\nevery month\n",
28+
),
29+
),
30+
]

backend/courses/models.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ def course_reviews(queryset, prefix=""):
130130

131131
class CourseManager(models.Manager):
132132
def get_queryset(self):
133+
queryset = super().get_queryset()
134+
if (queryset.filter(annotation_expiration_lt=timezone.now()).exists()):
135+
return course_reviews(queryset).order_by("full_code", "semester")
133136
return super().get_queryset()
134137

135138

@@ -282,6 +285,16 @@ class Course(models.Model):
282285
"""
283286
),
284287
)
288+
289+
annotations_expiration = models.DateTimeField(
290+
default=timezone.now,
291+
help_text=dedent(
292+
"""
293+
The expiration time for the annotations of this course, these fields should be refreshed
294+
every month
295+
"""
296+
),
297+
)
285298
course_quality = models.DecimalField(max_digits=4, decimal_places=3, null=True, blank=True, help_text=dedent(
286299
"""
287300
The average course quality rating for this course, on a scale from 0 to 5 (precomputed for efficiency).
@@ -838,7 +851,16 @@ class Meta:
838851
default=0,
839852
help_text="The number of active PCA registrations watching this section.",
840853
) # For the set of PCA registrations for this section, use the related field `registrations`.
841-
854+
855+
annotation_expiration = models.DateTimeField(
856+
default=timezone.now,
857+
help_text=dedent(
858+
"""
859+
The expiration time for the annotations of this section, these fields should be refreshed
860+
every month
861+
"""
862+
),
863+
)
842864
course_quality = models.DecimalField(max_digits=4, decimal_places=3, null=True, blank=True)
843865
instructor_quality = models.DecimalField(max_digits=4, decimal_places=3, null=True, blank=True)
844866
difficulty = models.DecimalField(max_digits=4, decimal_places=3, null=True, blank=True)

0 commit comments

Comments
 (0)