Commits

Jason Moiron committed 6199415

preliminary 1.3 support; *NOTE* if you are using with 1.3, transaction support is BROKEN in 1.3

  • Participants
  • Parent commits 8b2be68

Comments (0)

Files changed (8)

File johnny/backends/__init__.py

 <http://github.com/mmalone/django-caching/blob/master/app/cache.py>`_.
 """
 
-__all__ = ['memcached', 'locmem']
+__all__ = ['memcached', 'locmem', 'filebased']
 

File johnny/backends/locmem.py

 
 from django.core.cache.backends import locmem
 from django.utils.encoding import smart_str
+import django
 import sys
 
 class CacheClass(locmem.CacheClass):
             timeout = sys.maxint
         return super(CacheClass, self).set(smart_str(key), value, timeout)
 
-
+if django.VERSION[:2] > (1, 2):
+    class LocMemCache(CacheClass):
+        pass

File johnny/backends/memcached.py

 
 from django.core.cache.backends import memcached
 from django.utils.encoding import smart_str
+import django
 
 class CacheClass(memcached.CacheClass):
     """By checking ``timeout is None`` rather than ``not timeout``, this
         if timeout == 0: return 0
         return super(CacheClass, self)._get_memcache_timeout(timeout)
 
+if django.VERSION[:2] > (1, 2):
+    class MemcachedCache(memcached.MemcachedCache):
+        def _get_memcache_timeout(self, timeout=None):
+            if timeout == 0: return 0
+            return super(MemcachedCache, self)._get_memcache_timeout(timeout)
+
+    class PyLibMCCache(memcached.PyLibMCCache):
+        def _get_memcache_timeout(self, timeout=None):
+            if timeout == 0: return 0
+            return super(PyLibMCCache, self)._get_memcache_timeout(timeout)

File johnny/cache.py

 
     def get_tables(where_node, tables):
         for child in where_node.children:
-            if isinstance(child, WhereNode) and child.children:
+            if isinstance(child, WhereNode):# and child.children:
                 tables = get_tables(child, tables)
                 continue
             for item in child:

File johnny/tests/cache.py

         new_count = written_books.count()
         self.failUnless(new_count != count)
         self.failUnless(q.get() == False)
+        PersonType.objects.filter(title='NonAuthor').order_by('-title')[:5]
+
+    def test_foreign_key_delete_cascade(self):
+        """From #32, test that if you have 'Foo' and 'Bar', with bar.foo => Foo,
+        and you delete foo, bar.foo is also deleted, which means you have to
+        invalidate Bar when deletions are made in Foo (but not changes)."""
 
 
 class TransactionSupportTest(TransactionQueryCacheBase):

File johnny/tests/testapp/models.py

 from django.db import models
 from django.db.models import permalink
 from django.conf import settings
-from django.contrib.auth.models import User
 from django.utils.translation import ugettext_lazy as _
 
 #from basic.people.models import Person
 
+class User(models.Model):
+    """User model."""
+    first_name = models.CharField('first name', blank=True, max_length=128)
+    last_name = models.CharField('last name', blank=True, max_length=128)
+    username = models.CharField('username', blank=True, max_length=128)
+
+    def __repr__(self):
+        return '<User: %s %s>' % (self.first_name, self.last_name)
+
 class PersonType(models.Model):
     """Person type model."""
     title = models.CharField(_('title'), max_length=100)
         (1, 'Male'),
         (2, 'Female'),
     )
+    user = models.ForeignKey(User, blank=True, null=True)
     first_name = models.CharField(_('first name'), blank=True, max_length=100)
     middle_name = models.CharField(_('middle name'), blank=True, max_length=100)
     last_name = models.CharField(_('last name'), blank=True, max_length=100)
     slug = models.SlugField(_('slug'), unique=True)
-    user = models.ForeignKey(User, blank=True, null=True, help_text='If the person is an existing user of your site.')
     gender = models.PositiveSmallIntegerField(_('gender'), choices=GENDER_CHOICES, blank=True, null=True)
     mugshot = models.FileField(_('mugshot'), upload_to='mugshots', blank=True)
     mugshot_credit = models.CharField(_('mugshot credit'), blank=True, max_length=200)
     def get_absolute_url(self):
         return ('book_detail', None, { 'slug': self.book.slug })
 
-
 class Page(models.Model):
     """Page model"""
     user = models.ForeignKey(User)
     class Meta:
         db_table = u'ミルク'
 
+
+
 # Django settings for proj project.
 
+import django
+
 DEBUG = True
 TEMPLATE_DEBUG = DEBUG
 
 ADMINS = ()
 
 MANAGERS = ADMINS
+
 DATABASE_ENGINE = 'sqlite3'     # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
 DATABASE_NAME = 'johnny-db.sql' # Or path to database file if using sqlite3.
 DATABASE_USER = ''              # Not used with sqlite3.
 # trailing slash.
 # Examples: "http://foo.com/media/", "/media/".
 ADMIN_MEDIA_PREFIX = '/media/'
-#CACHE_BACKEND="johnny.backends.filebased:///tmp/johnny_cache.cc"
-CACHE_BACKEND="johnny.backends.locmem://"
-#CACHE_BACKEND="johnny.backends.memcached://localhost:11211/"
+if django.VERSION[:2] < (1, 3):
+    CACHE_BACKEND="johnny.backends.locmem://"
+    #CACHE_BACKEND="johnny.backends.memcached://localhost:11211/"
+    #CACHE_BACKEND="johnny.backends.filebased:///tmp/johnny_cache.cc"
+else:
+    CACHE = { 'default' : { 'BACKEND': 'johnny.backends.locmem.LocMemCache' }}
 
 
 # Make this unique, and don't share it with anybody.
 )
 
 INSTALLED_APPS = (
-    #'django.contrib.contenttypes',
     #'django.contrib.auth',
     #'django.contrib.sessions',
     #'django.contrib.sites',
 from setuptools import setup
 #from distutils.core import setup
 
-version = '0.3'
+version = '0.2.1'
 
 setup(name='johnny-cache',
       version=version,