Commit 6a003988 by Usman Khalid

Cache keys should be unicode.

parent f76efd8c
...@@ -5,6 +5,7 @@ from .. import exceptions ...@@ -5,6 +5,7 @@ from .. import exceptions
from django.conf import settings from django.conf import settings
import django.core.cache import django.core.cache
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils.encoding import smart_text
class Backend(BaseBackend): class Backend(BaseBackend):
...@@ -71,8 +72,8 @@ def make_upload_url_available(url_key_name, timeout): ...@@ -71,8 +72,8 @@ def make_upload_url_available(url_key_name, timeout):
url_key_name (str): key that uniquely identifies the upload url url_key_name (str): key that uniquely identifies the upload url
timeout (int): time in seconds before the url expires timeout (int): time in seconds before the url expires
""" """
return get_cache().set( get_cache().set(
get_upload_cache_key(url_key_name), smart_text(get_upload_cache_key(url_key_name)),
1, timeout 1, timeout
) )
...@@ -84,8 +85,8 @@ def make_download_url_available(url_key_name, timeout): ...@@ -84,8 +85,8 @@ def make_download_url_available(url_key_name, timeout):
url_key_name (str): key that uniquely identifies the url url_key_name (str): key that uniquely identifies the url
timeout (int): time in seconds before the url expires timeout (int): time in seconds before the url expires
""" """
return get_cache().set( get_cache().set(
get_download_cache_key(url_key_name), smart_text(get_download_cache_key(url_key_name)),
1, timeout 1, timeout
) )
...@@ -93,13 +94,13 @@ def is_upload_url_available(url_key_name): ...@@ -93,13 +94,13 @@ def is_upload_url_available(url_key_name):
""" """
Return True if the corresponding upload URL is available. Return True if the corresponding upload URL is available.
""" """
return get_cache().get(get_upload_cache_key(url_key_name)) is not None return get_cache().get(smart_text(get_upload_cache_key(url_key_name))) is not None
def is_download_url_available(url_key_name): def is_download_url_available(url_key_name):
""" """
Return True if the corresponding download URL is available. Return True if the corresponding download URL is available.
""" """
return get_cache().get(get_download_cache_key(url_key_name)) is not None return get_cache().get(smart_text(get_download_cache_key(url_key_name))) is not None
def get_upload_cache_key(url_key_name): def get_upload_cache_key(url_key_name):
return "upload/" + url_key_name return "upload/" + url_key_name
......
...@@ -17,6 +17,8 @@ def filesystem_storage(request, key): ...@@ -17,6 +17,8 @@ def filesystem_storage(request, key):
""" """
Uploading and download files to the local filesystem backend. Uploading and download files to the local filesystem backend.
""" """
if isinstance(key, unicode):
key = key.encode("utf-8")
if request.method == "PUT": if request.method == "PUT":
if not is_upload_url_available(key): if not is_upload_url_available(key):
raise Http404() raise Http404()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment