Skip to content

Commit 4315986

Browse files
committed
Another django 5.2 fix
1 parent 0e4d53c commit 4315986

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2.5.1
2+
====================
3+
* Add another Django 5.2 fix
4+
15
2.5.0 (2025-12-08)
26
====================
37
* Adds compatibility with Django 5.2

courseaffils/lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def in_course_or_404(username, group_or_course):
4747
raise Http404(response_body)
4848

4949

50-
ANONYMIZE_KEY = 'ccnmtl.courseaffils.anonymize'
50+
ANONYMIZE_KEY = 'ctl.courseaffils.anonymize'
5151

5252

5353
def handle_public_name(user, request):

courseaffils/middleware.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
except ImportError:
2525
pass
2626

27-
SESSION_KEY = 'ccnmtl.courseaffils.course'
27+
SESSION_KEY = 'ctl.courseaffils.course'
2828

2929

3030
def has_anonymous_path(current_path):
@@ -178,7 +178,7 @@ def process_request(self, request, override_view=None):
178178

179179
if chosen_course and \
180180
(chosen_course in available_courses or request.user.is_staff):
181-
request.session[SESSION_KEY] = chosen_course
181+
request.session[SESSION_KEY] = chosen_course.pk
182182
self.decorate_request(request, chosen_course)
183183
return None
184184

courseaffils/tests/test_middleware.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,30 @@
99
from django.test import TestCase
1010

1111

12-
class StubRequest(object):
13-
COOKIES = dict()
14-
GET = dict()
15-
POST = dict()
16-
environ = dict()
17-
18-
def __init__(self, c):
19-
self.path = "/foo/bar"
12+
class StubRequest:
13+
def __init__(self, c=None, path='/foo/bar', method='GET'):
14+
self.path = path
15+
self.method = method
16+
self.COOKIES = {}
17+
self.GET = {}
18+
self.POST = {}
19+
self.environ = {}
20+
self.session = {}
21+
2022
if c:
21-
self.session = {'ccnmtl.courseaffils.course': c}
22-
else:
23-
self.session = dict()
23+
if hasattr(c, 'pk'):
24+
self.session = {'ctl.courseaffils.course': c.pk}
25+
else:
26+
self.session = {'ctl.courseaffils.course': c}
2427

2528
def get_full_path(self):
2629
return self.path
2730

31+
def is_secure(self):
32+
return False
33+
2834

29-
class StubResponse(object):
35+
class StubResponse:
3036
content = ""
3137

3238

@@ -62,12 +68,12 @@ def test_is_anonymous_path(self):
6268
assert is_anonymous_path("/static/")
6369

6470
def test_already_selected_course(self):
65-
assert already_selected_course(StubRequest(True))
66-
assert not already_selected_course(StubRequest(False))
71+
assert already_selected_course(StubRequest(1))
72+
assert not already_selected_course(StubRequest(0))
6773

6874
def test_cmm_process_response(self):
6975
c = CourseManagerMiddleware(self)
70-
assert c.process_response(StubRequest(True), "foo") == "foo"
76+
assert c.process_response(StubRequest(1), "foo") == "foo"
7177

7278
def test_cmm_process_response_anon(self):
7379
c = CourseManagerMiddleware(self)

courseaffils/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from django.utils.http import urlquote as quote
1919

2020

21-
SESSION_KEY = 'ccnmtl.courseaffils.course'
21+
SESSION_KEY = 'ctl.courseaffils.course'
2222

2323

2424
def get_courses_for_user(user):

0 commit comments

Comments
 (0)