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

[Improvements] Migrate to Django 5 #308

Merged
merged 6 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM pennlabs/django-base:a142aa6975ee293bbc8a09ef0b81998ce7063dd3
FROM pennlabs/django-base:b269ea1613686b1ac6370154debbb741b012de1a-3.11

LABEL maintainer="Penn Labs"

Expand Down
6 changes: 3 additions & 3 deletions backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dj-database-url = "*"
djangorestframework = "*"
psycopg2 = "*"
sentry-sdk = "*"
django = "==3.1.7"
django = "~=5.0.3"
django-cors-headers = "*"
pyyaml = "*"
uritemplate = "*"
Expand All @@ -36,7 +36,7 @@ celery = "*"
redis = "*"
django-auto-prefetching = "*"
django-rest-live = ">=0.7.0"
channels = "<3"
channels = "==3.0.5"
channels-redis = "*"
uvicorn = {extras = ["standard"],version = "*"}
gunicorn = "*"
Expand All @@ -45,4 +45,4 @@ typing-extensions = "*"
drf-excel = "*"

[requires]
python_version = "3"
python_version = "3.11"
2,447 changes: 1,272 additions & 1,175 deletions backend/Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/officehoursqueue/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@

ALLOWED_HOSTS = ["*"]

CSRF_TRUSTED_ORIGINS = ["http://127.0.0.1:3000", "https://ohq.io"]

# Application definition

INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
Expand Down
2 changes: 1 addition & 1 deletion backend/ohq/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@


websocket_urlpatterns = [
path("api/ws/subscribe/", realtime_router.as_consumer(), name="subscriptions"),
path("api/ws/subscribe/", realtime_router.as_consumer().as_asgi(), name="subscriptions"),
]
8 changes: 4 additions & 4 deletions backend/ohq/statistics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib.auth import get_user_model
from django.db.models import Avg, Case, Count, F, Sum, When
from django.db.models import Avg, Case, Count, F, Sum, When, FloatField, ExpressionWrapper
from django.db.models.functions import TruncDate
from django.utils import timezone

Expand Down Expand Up @@ -217,10 +217,10 @@ def queue_calculate_questions_per_ta_heatmap(queue, weekday, hour):
questions=Count("date", distinct=False),
tas=Count("responded_to_by", distinct=True),
)
.annotate(
q_per_ta=Case(When(tas=0, then=F("questions")), default=1.0 * F("questions") / F("tas"))
.annotate(
q_per_ta=Case(When(tas=0, then=ExpressionWrapper(F("questions"), output_field=FloatField())), default=1.0 * F("questions") / F("tas")),
)
.aggregate(avg=Avg(F("q_per_ta")))
.aggregate(avg=Avg(F("q_per_ta"), output_field=FloatField()))
)

statistic = interval_stats["avg"]
Expand Down
2 changes: 2 additions & 0 deletions backend/tests/ohq/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,12 +609,14 @@ def test_questions_per_ta_computation(self):
self.ta_1_questions_8_week_1 / self.num_tas_8
+ self.ta_1_questions_8_week_2 / self.num_tas_8
) / 2

actual_8 = QueueStatistic.objects.get(
queue=self.queue,
metric=QueueStatistic.METRIC_HEATMAP_QUESTIONS_PER_TA,
day=(yesterday_weekday + 1) % 7 + 1,
hour=8,
).value

self.assertEqual(expected_8, actual_8)

expected_17 = (self.ta_1_questions_17 + self.ta_2_questions_17) / self.num_tas_17
Expand Down
11 changes: 4 additions & 7 deletions backend/tests/ohq/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
from django.urls import reverse
from djangorestframework_camel_case.util import camelize
from rest_framework.test import APIClient
from rest_live.testing import APICommunicator, async_test, get_headers_for_user
from rest_live.testing import async_test, get_headers_for_user

from ohq.models import Announcement, Course, Membership, Question, Queue, Semester
from ohq.serializers import AnnouncementSerializer
from ohq.urls import realtime_router
from channels.testing import WebsocketCommunicator


User = get_user_model()
Expand Down Expand Up @@ -44,9 +45,7 @@ async def asyncSetUp(self):
)

headers = await get_headers_for_user(self.student2)
self.client = APICommunicator(
AuthMiddlewareStack(realtime_router.as_consumer()), "/api/ws/subscribe/", headers
)
self.client = WebsocketCommunicator(AuthMiddlewareStack(realtime_router.as_consumer().as_asgi()), "/ws/subscribe/", headers)
connected, _ = await self.client.connect()
self.assertTrue(connected)

Expand Down Expand Up @@ -120,9 +119,7 @@ async def asyncSetUp(self):
)

headers = await get_headers_for_user(self.student)
self.client = APICommunicator(
AuthMiddlewareStack(realtime_router.as_consumer()), "/api/ws/subscribe/", headers
)
self.client = WebsocketCommunicator(AuthMiddlewareStack(realtime_router.as_consumer().as_asgi()), "/ws/subscribe/", headers)
connected, _ = await self.client.connect()
self.assertTrue(connected)

Expand Down
Loading