Author: leidel
Date: Fri Dec 26 09:39:48 2008
New Revision: 88

Modified:
    trunk/dbtemplates/__init__.py
    trunk/dbtemplates/cache.py
    trunk/dbtemplates/loader.py
    trunk/dbtemplates/management/commands/sync_templates.py
    trunk/dbtemplates/models.py
    trunk/example/settings.py
    trunk/setup.py

Log:
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.

Modified: trunk/dbtemplates/__init__.py
==============================================================================
--- trunk/dbtemplates/__init__.py       (original)
+++ trunk/dbtemplates/__init__.py       Fri Dec 26 09:39:48 2008
@@ -1,2 +1,2 @@
-VERSION = (0, 5, 3)
+VERSION = (0, 5, 4)
  __version__ = '.'.join(map(str, VERSION))

Modified: trunk/dbtemplates/cache.py
==============================================================================
--- trunk/dbtemplates/cache.py  (original)
+++ trunk/dbtemplates/cache.py  Fri Dec 26 09:39:48 2008
@@ -40,7 +40,7 @@
      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 @@
              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:

Modified: trunk/dbtemplates/loader.py
==============================================================================
--- trunk/dbtemplates/loader.py (original)
+++ trunk/dbtemplates/loader.py Fri Dec 26 09:39:48 2008
@@ -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 @@
      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

Modified: trunk/dbtemplates/management/commands/sync_templates.py
==============================================================================
--- trunk/dbtemplates/management/commands/sync_templates.py     (original)
+++ trunk/dbtemplates/management/commands/sync_templates.py     Fri Dec 26  
09:39:48 2008
@@ -44,7 +44,7 @@
                      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(

Modified: trunk/dbtemplates/models.py
==============================================================================
--- trunk/dbtemplates/models.py (original)
+++ trunk/dbtemplates/models.py Fri Dec 26 09:39:48 2008
@@ -4,6 +4,7 @@
  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
@@ -19,6 +20,9 @@
      sites = models.ManyToManyField(Site, default=[settings.SITE_ID])
      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'

Modified: trunk/example/settings.py
==============================================================================
--- trunk/example/settings.py   (original)
+++ trunk/example/settings.py   Fri Dec 26 09:39:48 2008
@@ -82,3 +82,8 @@
      '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"

Modified: trunk/setup.py
==============================================================================
--- trunk/setup.py      (original)
+++ trunk/setup.py      Fri Dec 26 09:39:48 2008
@@ -8,7 +8,7 @@
      author='Jannis Leidel',
      author_email='[email protected]',
      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',

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pinax-updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pinax-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to