-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
import json | ||
from django.http import * | ||
from course_discovery.apps.course_metadata.models import * | ||
from course_discovery.apps.course_metadata.managers import * | ||
|
||
class MagicMiddleware: | ||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
# One-time configuration and initialization. | ||
|
||
def __call__(self, request): | ||
# Code to be executed for each request before | ||
# the view (and later middleware) are called. | ||
|
||
method = request.method | ||
|
||
|
||
if method == 'GET' and not request.GET.get('restriction_type', None): | ||
CourseRun._meta.local_managers.clear() | ||
CourseRun.add_to_class('everything', EverythingRunManagerWithoutRestriction() ) | ||
CourseRun.add_to_class('objects', DraftRunManagerWithoutRestriction.from_queryset(CourseRunQuerySet)()) | ||
|
||
response = self.get_response(request) | ||
|
||
# Code to be executed for each request/response after | ||
# the view is called. | ||
if method == 'GET': | ||
CourseRun._meta.local_managers.clear() | ||
CourseRun.add_to_class('everything', CourseRunQuerySet.as_manager() ) | ||
CourseRun.add_to_class('objects', DraftManager.from_queryset(CourseRunQuerySet)()) | ||
|
||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters