def model_cleanup(self): create_models() importlib.reload(import_module(settings.ROOT_URLCONF)) app_config = apps.get_app_config("django_models_from_csv") hydrate_models_and_permissions(app_config) apps.clear_cache() clear_url_caches()
def test_urlconf_with_debug_false(settings): settings.DEBUG = False clear_url_caches() reload(config.urls) from config.urls import urlpatterns assert django_debug_toolbar_found(urlpatterns) is False assert media_pattern_found(urlpatterns) is False
def reload(module_name): # TODO: This should be done by the django-specific patches. from django.urls.base import clear_url_caches clear_url_caches() global last_reloaded, RELOAD_PERIOD now = datetime.now() if now - last_reloaded < RELOAD_PERIOD: log('refusing to reload again') return True else: last_reloaded = now try: module = importlib.reload(sys.modules[module_name]) except Exception as ex: log_error(f'optimistic-reload: ' f'error while attempting reload({module_name}): ' f'{ex.__class__.__name__}({ex})') return None if module_name not in _dependency_graph: log_error(f'optimistic-reload: error: not in graph: {module_name}') return None try: ancestral_module_names = _ancestors_in_topological_sort_order( module_name) except Exception as ex: log_error(f'optimistic-reload: error: {ex.__class__.__name__}({ex})') return None log( f'optimistic-reload: reloading {module_name} ' f'and ancestors: {ancestral_module_names}', notify=True) for ancestral_module_name in ancestral_module_names: try: importlib.reload(sys.modules[ancestral_module_name]) except Exception as ex: log_error(f'optimistic-reload: ' f'error while attempting reload({module_name}): ' f'{ex.__class__.__name__}({ex})') return None log(f'Reloaded {len(ancestral_module_names)} ancestors of {module_name}', notify=True) models_modules = [ mod for mod in ancestral_module_names + [module_name] if mod.split('.')[-1] == 'models' ] if models_modules: log(f'models.py present: {sorted(models_modules)}', notify=True) return None return module
def setUp(self): # Defeat singleton hackery for now, until #28 is resolved. Router.model_views = {} Router.route_views = {} Router.model_routes = {} Router.name_models = {} # Ugh, more hackery urls_module.urlpatterns = [] # Without this, tests can influence one another! clear_url_caches()
def attempt_register(self, Model, ModelAdmin): try: admin.site.unregister(Model) except admin.sites.NotRegistered: pass try: admin.site.register(Model, ModelAdmin) except admin.sites.AlreadyRegistered: logger.warning("WARNING! %s admin already exists." % (str(Model))) # If we don't do this, our module will show up in admin but # it will show up as an unclickable thing with on add/change importlib.reload(import_module(settings.ROOT_URLCONF)) clear_url_caches()
def reload_urls(): importlib.reload(importlib.import_module(settings.ROOT_URLCONF)) clear_url_caches()
def tearDown(self): # Without this, tests can influence one another! clear_url_caches()
def reload_urlconf(urlconf=None): if urlconf is None: urlconf = settings.ROOT_URLCONF if urlconf in sys.modules: importlib.reload(sys.modules[urlconf]) clear_url_caches()
def recarregar_urls(): """Recarrega URLConf""" urlconf = settings.ROOT_URLCONF if urlconf in sys.modules: clear_url_caches() reload(sys.modules[urlconf])