forked from django-wiki/django-wiki
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from edx/saleem-latif/WL-322
WL-322: Update django wiki to support multi-tenancy
- Loading branch information
Showing
5 changed files
with
72 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ def build_media_pattern(base_folder, file_extension): | |
|
||
setup( | ||
name = "django-wiki", | ||
version = "0.0.5", | ||
version = "0.0.6", | ||
author = "Benjamin Bach", | ||
author_email = "[email protected]", | ||
description = ("A wiki system written for the Django framework."), | ||
|
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 @@ | ||
from middleware import get_current_request |
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,62 @@ | ||
import threading | ||
import importlib | ||
|
||
from django.conf import settings | ||
|
||
if getattr(settings, "WIKI_REQUEST_CACHE_MIDDLEWARE_CLASS", None): | ||
class_name = settings.WIKI_REQUEST_CACHE_MIDDLEWARE_CLASS.split(".")[-1] | ||
module = ".".join(settings.WIKI_REQUEST_CACHE_MIDDLEWARE_CLASS.split('.')[:-1]) | ||
RequestCache = getattr(importlib.import_module(module), class_name) | ||
else: | ||
class _RequestCache(threading.local): | ||
""" | ||
A thread-local for storing the per-request cache. | ||
""" | ||
def __init__(self): | ||
super(_RequestCache, self).__init__() | ||
self.data = {} | ||
self.request = None | ||
|
||
|
||
REQUEST_CACHE = _RequestCache() | ||
|
||
|
||
class RequestCache(object): | ||
@classmethod | ||
def get_request_cache(cls, name=None): | ||
""" | ||
This method is deprecated. Please use :func:`request_cache.get_cache`. | ||
""" | ||
if name is None: | ||
return REQUEST_CACHE | ||
else: | ||
return REQUEST_CACHE.data.setdefault(name, {}) | ||
|
||
@classmethod | ||
def get_current_request(cls): | ||
""" | ||
This method is deprecated. Please use :func:`request_cache.get_request`. | ||
""" | ||
return REQUEST_CACHE.request | ||
|
||
@classmethod | ||
def clear_request_cache(cls): | ||
""" | ||
Empty the request cache. | ||
""" | ||
REQUEST_CACHE.data = {} | ||
REQUEST_CACHE.request = None | ||
|
||
def process_request(self, request): | ||
self.clear_request_cache() | ||
REQUEST_CACHE.request = request | ||
return None | ||
|
||
def process_response(self, request, response): | ||
self.clear_request_cache() | ||
return response | ||
|
||
|
||
def get_current_request(): | ||
"""Return the request associated with the current thread.""" | ||
return RequestCache.get_current_request() |
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