Fixed an issue where `get_cache_key` may produce invalid memcached

keys.
This commit is contained in:
Selwin Ong 2012-05-06 20:52:17 +07:00
parent 33c1197ad1
commit bb4e7ce36f
2 changed files with 7 additions and 2 deletions

View file

@ -14,7 +14,7 @@ from django.contrib.sites.models import Site
from dbtemplates.conf import settings
from dbtemplates.models import Template
from dbtemplates.utils.cache import get_cache_backend
from dbtemplates.utils.cache import get_cache_backend, get_cache_key
from dbtemplates.utils.template import (get_template_source,
check_template_syntax)
from dbtemplates.management.commands.sync_templates import (FILES_TO_DATABASE,
@ -142,3 +142,7 @@ class DbTemplatesTestCase(TestCase):
name='good.html', content='{% if foo %}Bar{% endif %}')
self.assertFalse(check_template_syntax(bad_template)[0])
self.assertTrue(check_template_syntax(good_template)[0])
def test_get_cache_name(self):
name = 'name with spaces'
self.assertEqual(get_cache_key(name), 'dbtemplates::name-with-spaces::1')

View file

@ -1,6 +1,7 @@
from django.core.cache import get_cache
from django.contrib.sites.models import Site
from django.template.defaultfilters import slugify
from dbtemplates.conf import settings
@ -13,7 +14,7 @@ cache = get_cache_backend()
def get_cache_key(name):
current_site = Site.objects.get_current()
return 'dbtemplates::%s::%s' % (name, current_site.pk)
return 'dbtemplates::%s::%s' % (slugify(name), current_site.pk)
def get_cache_notfound_key(name):