Hynek Cernoch avatar Hynek Cernoch committed 6f5c3b0

Added support for tests with multihost_patch and sitemaps (cache flush control)

Comments (0)

Files changed (1)


 from django.conf import settings
 from django.contrib.sites.models import Site
 from django.db.models.loading import app_cache_ready
+from django.db.models.signals import post_delete, post_save
 from threaded_multihost import threadlocals
 from threaded_multihost.threadlocal_settings import get_threadlocal_setting
 import keyedcache
     return site
+def catch_sites(*args, **kwargs):
+    """Listen to sites modifications due to cache flushing"""
+    #keyedcache.cache_delete('SITE', children=True)
+    import keyedcache
+    #print keyedcache.CACHED_KEYS
+    #import pdb; pdb.set_trace()
+    # We can not rely on the domain name of the modified/deleted site when testing. Because it is 'testserver'.
+    # The following would be better, but does not work:
+    keyedcache.cache_delete('SITE', host=kwargs['instance'].domain, children=True)
+    #log.debug('Following sites are cached %s' % filter(lambda x: x.startswith(keyedcache.cache_key('SITE')), keyedcache.CACHED_KEYS))
+post_delete.connect(catch_sites, sender=Site)
+post_save.connect(catch_sites, sender=Site)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.