def clear_template_tag_caches(): """Clear the template tags caches. This allows changes to the list of available template tags to be reflected in any new templates by emptying all the caches and forcing the available list of tags to be rebuilt. """ if libraries is not None: # Django >= 1.6, <= 1.8 libraries.clear() try: # Django == 1.6 # # We'll import templatetags_modules here because we want the most # recent copy of templatetags_modules. from django.template.base import templatetags_modules del(templatetags_modules[:]) except ImportError: if get_templatetags_modules is not None: # Django >= 1.7, <= 1.8 get_templatetags_modules.cache_clear() if engines: # Django >= 1.8 engines._engines.clear() Engine.get_default.cache_clear()
def clear_template_tag_caches(): """Clear the template tags caches. This allows changes to the list of available template tags to be reflected in any new templates by emptying all the caches and forcing the available list of tags to be rebuilt. """ if libraries is not None: # Django >= 1.6, <= 1.8 libraries.clear() try: # Django == 1.6 # # We'll import templatetags_modules here because we want the most # recent copy of templatetags_modules. from django.template.base import templatetags_modules del (templatetags_modules[:]) except ImportError: if get_templatetags_modules is not None: # Django >= 1.7, <= 1.8 get_templatetags_modules.cache_clear() if engines: # Django >= 1.8 engines._engines.clear() Engine.get_default.cache_clear()
def _reset_templatetags_cache(self): """Clears the Django templatetags_modules cache.""" # We'll import templatetags_modules here because # we want the most recent copy of templatetags_modules from django.template.base import get_templatetags_modules # Wipe out the contents. if hasattr(get_templatetags_modules, 'cache_clear'): # Django >= 1.7 get_templatetags_modules.cache_clear() else: # Django < 1.7 from django.template.base import templatetags_modules del (templatetags_modules[:]) # And reload the cache get_templatetags_modules()
def update_installed_apps(**kwargs): if kwargs['setting'] == 'INSTALLED_APPS': # Rebuild any AppDirectoriesFinder instance. from django.contrib.staticfiles.finders import get_finder get_finder.cache_clear() # Rebuild management commands cache from django.core.management import get_commands get_commands.cache_clear() # Rebuild templatetags module cache. from django.template.base import get_templatetags_modules get_templatetags_modules.cache_clear() # Rebuild get_app_template_dirs cache. from django.template.utils import get_app_template_dirs get_app_template_dirs.cache_clear() # Rebuild translations cache. from django.utils.translation import trans_real trans_real._translations = {}
def _reset_templatetags_cache(self): """Clears the Django templatetags_modules cache.""" # We'll import templatetags_modules here because # we want the most recent copy of templatetags_modules from django.template.base import get_templatetags_modules # Wipe out the contents. if hasattr(get_templatetags_modules, 'cache_clear'): # Django >= 1.7 get_templatetags_modules.cache_clear() else: # Django < 1.7 from django.template.base import templatetags_modules del(templatetags_modules[:]) # And reload the cache get_templatetags_modules()
def update_installed_apps(**kwargs): if kwargs['setting'] == 'INSTALLED_APPS': # Rebuild any AppDirectoriesFinder instance. from django.contrib.staticfiles.finders import get_finder get_finder.cache_clear() # Rebuild management commands cache from django.core.management import get_commands get_commands.cache_clear() # Rebuild templatetags module cache. from django.template.base import get_templatetags_modules get_templatetags_modules.cache_clear() # Rebuild get_app_template_dirs cache. from django.template.utils import get_app_template_dirs get_app_template_dirs.cache_clear() # Rebuild translations cache. from django.utils.translation import trans_real trans_real._translations = {}
def reload_settings(settings, databases=None): """Special routine to reload django settings. Including: urlconf module, context processor, templatetags settings, database settings. """ if databases: settings.DATABASES.update(databases) # check if there's settings to reload if hasattr(settings, 'ROOT_URLCONF'): if settings.ROOT_URLCONF in sys.modules: imp.reload(sys.modules[settings.ROOT_URLCONF]) import django if hasattr(django, 'setup'): django.setup() import_module(settings.ROOT_URLCONF) set_urlconf(settings.ROOT_URLCONF) settings.LANGUAGE_CODE = 'en' # all tests should be run with English by default # Make the ConnectionHandler use the new settings, otherwise the ConnectionHandler will have old configuraton. from django.db.utils import ConnectionHandler import django.db from django.db.utils import load_backend import django.db.transaction import django.db.models import django.db.models.sql.query import django.core.management.commands.syncdb import django.db.models.sql.compiler import django.db.backends import django.db.backends.mysql.base import django.core.management.commands.loaddata # all modules which imported django.db.connections should be changed to get new ConnectionHanlder django.db.models.sql.compiler.connections = django.db.models.connections = \ django.core.management.commands.loaddata.connections = \ django.db.backends.connections = django.db.backends.mysql.base.connections = \ django.core.management.commands.syncdb.connections = django.db.transaction.connections = \ django.db.connections = django.db.models.base.connections = django.db.models.sql.query.connections = \ ConnectionHandler(settings.DATABASES) # default django connection and backend should be also changed django.db.connection = django.db.connections[django.db.DEFAULT_DB_ALIAS] django.db.backend = load_backend(django.db.connection.settings_dict['ENGINE']) import django.core.cache django.core.cache.cache = django.core.cache._create_cache(django.core.cache.DEFAULT_CACHE_ALIAS) # clear django urls cache clear_url_caches() # clear django contextprocessors cache context._standard_context_processors = None # clear django templatetags cache base.templatetags_modules = None # reload translation files imp.reload(translation) imp.reload(trans_real) # clear django template loaders cache loader.template_source_loaders = None from django.template.loaders import app_directories imp.reload(app_directories) from django.template.base import get_templatetags_modules get_templatetags_modules.cache_clear() import django.apps import django import django.template django.template.engines.__dict__.pop('templates', None) django.template.engines._templates = None django.template.engines._engines = {} if django.apps.apps.ready: django.apps.apps.set_installed_apps(settings.INSTALLED_APPS) django.setup()
def reload_settings(settings, databases=None): """Special routine to reload django settings. Including: urlconf module, context processor, templatetags settings, database settings. """ if databases: settings.DATABASES.update(databases) # check if there's settings to reload if hasattr(settings, 'ROOT_URLCONF'): if settings.ROOT_URLCONF in sys.modules: imp.reload(sys.modules[settings.ROOT_URLCONF]) import django if hasattr(django, 'setup'): django.setup() import_module(settings.ROOT_URLCONF) set_urlconf(settings.ROOT_URLCONF) settings.LANGUAGE_CODE = 'en' # all tests should be run with English by default # Make the ConnectionHandler use the new settings, otherwise the ConnectionHandler will have old configuraton. from django.db.utils import ConnectionHandler import django.db from django.db.utils import load_backend import django.db.transaction import django.db.models import django.db.models.sql.query import django.core.management.commands.syncdb import django.db.models.sql.compiler import django.db.backends import django.db.backends.mysql.base import django.core.management.commands.loaddata # all modules which imported django.db.connections should be changed to get new ConnectionHanlder django.db.models.sql.compiler.connections = django.db.models.connections = \ django.core.management.commands.loaddata.connections = \ django.db.backends.connections = django.db.backends.mysql.base.connections = \ django.core.management.commands.syncdb.connections = django.db.transaction.connections = \ django.db.connections = django.db.models.base.connections = django.db.models.sql.query.connections = \ ConnectionHandler(settings.DATABASES) # default django connection and backend should be also changed django.db.connection = django.db.connections[ django.db.DEFAULT_DB_ALIAS] django.db.backend = load_backend( django.db.connection.settings_dict['ENGINE']) import django.core.cache django.core.cache.cache = django.core.cache._create_cache( django.core.cache.DEFAULT_CACHE_ALIAS) # clear django urls cache clear_url_caches() # clear django contextprocessors cache context._standard_context_processors = None # clear django templatetags cache base.templatetags_modules = None # reload translation files imp.reload(translation) imp.reload(trans_real) # clear django template loaders cache loader.template_source_loaders = None from django.template.loaders import app_directories imp.reload(app_directories) from django.template.base import get_templatetags_modules get_templatetags_modules.cache_clear() import django.apps import django import django.template django.template.engines.__dict__.pop('templates', None) django.template.engines._templates = None django.template.engines._engines = {} if django.apps.apps.ready: django.apps.apps.set_installed_apps(settings.INSTALLED_APPS) django.setup()