mirror of
https://github.com/jazzband/django-dbtemplates.git
synced 2026-03-16 22:20:28 +00:00
Made loader and cache backends site-aware. The filesystem cache backend now saves the files under <dir>/<site_domain>/<file_name>. The Django cache backend the Site id in the cache key. Template is now saved explicitly to backend if not existent in cache (e.g. if deleted manually or invalidated). Bumped version to 0.5.4.
git-svn-id: https://django-dbtemplates.googlecode.com/svn/trunk@88 cfb8ba98-e953-0410-9cff-959ffddf5974 committer: leidel <leidel@cfb8ba98-e953-0410-9cff-959ffddf5974> --HG-- extra : convert_revision : 564571948adb06cdda915b665aa61d00b3118ed0
This commit is contained in:
parent
7fafcbd72b
commit
b7011dce7e
7 changed files with 24 additions and 10 deletions
|
|
@ -1,2 +1,2 @@
|
|||
VERSION = (0, 5, 3)
|
||||
VERSION = (0, 5, 4)
|
||||
__version__ = '.'.join(map(str, VERSION))
|
||||
|
|
@ -40,7 +40,7 @@ class DjangoCacheBackend(BaseCacheBackend):
|
|||
A cache backend that uses Django's cache mechanism.
|
||||
"""
|
||||
def _cache_key(self, name):
|
||||
return 'dbtemplates::%s' % name
|
||||
return 'dbtemplates::%s::%s' % (name, self.site.pk)
|
||||
|
||||
def load(self, name):
|
||||
cache_key = self._cache_key(name)
|
||||
|
|
@ -65,11 +65,11 @@ class FileSystemBackend(BaseCacheBackend):
|
|||
if not os.path.isdir(self.cache_dir):
|
||||
pass
|
||||
except:
|
||||
raise ImproperlyConfigured('You\'re using the dbtemplates\' file system cache backend without having set the DBTEMPLATES_CACHE_DIR setting to a valid value. Make sure the directory exists and is writeable for the user your Django instance is running with.')
|
||||
raise ImproperlyConfigured("You're using the dbtemplates file system cache backend without having set the DBTEMPLATES_CACHE_DIR setting to a valid value. Make sure the directory exists and is writeable for the user your Django instance is running with.")
|
||||
super(FileSystemBackend, self).__init__()
|
||||
|
||||
def _filepath(self, name):
|
||||
return os.path.join(self.cache_dir, name)
|
||||
return os.path.join(self.cache_dir, self.site.domain, name)
|
||||
|
||||
def load(self, name):
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
from django.conf import settings
|
||||
from django.contrib.sites.models import Site
|
||||
from django.template import TemplateDoesNotExist
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
|
|
@ -12,17 +13,21 @@ def load_template_source(template_name, template_dirs=None):
|
|||
it falls back to query the database field ``name`` with the template path
|
||||
and ``sites`` with the current site.
|
||||
"""
|
||||
display_name = 'db:%s:%s' % (settings.DATABASE_ENGINE, template_name)
|
||||
site = Site.objects.get_current()
|
||||
display_name = 'db:%s:%s:%s' % (settings.DATABASE_ENGINE,
|
||||
template_name, site.domain)
|
||||
if backend:
|
||||
try:
|
||||
backend_template = backend.load(template_name)
|
||||
if backend_template is not None:
|
||||
if backend_template:
|
||||
return backend_template, template_name
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
template = Template.objects.get(name__exact=template_name,
|
||||
sites__pk=settings.SITE_ID)
|
||||
template = Template.on_site.get(name__exact=template_name)
|
||||
# Save in cache backend explicitly if manually deleted or invalidated
|
||||
if backend:
|
||||
backend.save(template_name, template.content)
|
||||
return (template.content, display_name)
|
||||
except:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class Command(NoArgsCommand):
|
|||
path = os.path.join(dirpath, f)
|
||||
name = path.split(templatedir)[1][1:]
|
||||
try:
|
||||
t = Template.objects.get(name__exact=name)
|
||||
t = Template.on_site.get(name__exact=name)
|
||||
except Template.DoesNotExist:
|
||||
if force == False:
|
||||
confirm = raw_input(
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ from django.db import models
|
|||
from django.conf import settings
|
||||
from django.db.models import signals
|
||||
from django.contrib.sites.models import Site
|
||||
from django.contrib.sites.managers import CurrentSiteManager
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.template import TemplateDoesNotExist
|
||||
from django.template.loader import find_template_source
|
||||
|
|
@ -20,6 +21,9 @@ class Template(models.Model):
|
|||
creation_date = models.DateTimeField(_('creation date'), default=datetime.now)
|
||||
last_changed = models.DateTimeField(_('last changed'), default=datetime.now)
|
||||
|
||||
objects = models.Manager()
|
||||
on_site = CurrentSiteManager('sites')
|
||||
|
||||
class Meta:
|
||||
db_table = 'django_template'
|
||||
verbose_name = _('template')
|
||||
|
|
|
|||
|
|
@ -82,3 +82,8 @@ INSTALLED_APPS = (
|
|||
'django.contrib.flatpages',
|
||||
'dbtemplates',
|
||||
)
|
||||
|
||||
# Uncomment the following two settings to use the file system cache backend.
|
||||
# It will cache in the directory "cache" inside the example project directory.
|
||||
# DBTEMPLATES_CACHE_BACKEND = "dbtemplates.cache.FileSystemBackend"
|
||||
# DBTEMPLATES_CACHE_DIR = "cache"
|
||||
|
|
|
|||
2
setup.py
2
setup.py
|
|
@ -8,7 +8,7 @@ setup(
|
|||
author='Jannis Leidel',
|
||||
author_email='jannis@leidel.info',
|
||||
url='http://github.com/jezdez/django-dbtemplates/wikis/',
|
||||
download_url='http://github.com/jezdez/django-dbtemplates/zipball/0.5.3',
|
||||
download_url='http://github.com/jezdez/django-dbtemplates/zipball/0.5.4',
|
||||
packages=[
|
||||
'dbtemplates',
|
||||
'dbtemplates.management',
|
||||
|
|
|
|||
Loading…
Reference in a new issue