Skip to content

Commit

Permalink
improvements: migrate to django 5.0.3 and channels 3.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
trangiabach committed Mar 24, 2024
1 parent dc613a9 commit 3dc57d5
Show file tree
Hide file tree
Showing 7 changed files with 1,285 additions and 1,189 deletions.
4 changes: 2 additions & 2 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 Down
2,445 changes: 1,271 additions & 1,174 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

0 comments on commit 3dc57d5

Please sign in to comment.