django.urls.clear_url_caches - python examples

Here are the examples of the python api django.urls.clear_url_caches taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

4 Examples 7

3 View Complete Implementation : signals.py
Copyright MIT License
Author : bpgc-cte
@receiver(setting_changed)
def root_urlconf_changed(**kwargs):
    if kwargs['setting'] == 'ROOT_URLCONF':
        from django.urls import clear_url_caches, set_urlconf
        clear_url_caches()
        set_urlconf(None)

0 View Complete Implementation : test_locale_middleware.py
Copyright MIT License
Author : learningequality
    def setUp(self):
        # Make sure the cache is empty before we are doing our tests.
        clear_url_caches()

0 View Complete Implementation : test_locale_middleware.py
Copyright MIT License
Author : learningequality
    def tearDown(self):
        # Make sure we will leave an empty cache for other testcases.
        clear_url_caches()

0 View Complete Implementation : middleware.py
Copyright MIT License
Author : lorinkoz
    def __call__(self, request):
        hostname = remove_www(request.get_host().split(":")[0])
        connection.set_schema_to_public()

        # Checking for static tenants
        for schema, data in settings.TENANTS.items():
            if schema in ["public", "default"]:
                continue
            if hostname in data["DOMAINS"]:
                tenant = SchemaDescriptor.create(schema_name=schema, domain_url=hostname)
                request.tenant = tenant
                if "URLCONF" in data:
                    request.urlconf = data["URLCONF"]
                connection.set_schema(request.tenant)
                return self.get_response(request)

        # Checking for dynamic tenants
        else:
            DomainModel = get_domain_model()
            prefix = request.path.split("/")[1]
            try:
                domain = DomainModel.objects.select_related("tenant").get(domain=hostname, folder=prefix)
            except DomainModel.DoesNotExist:
                try:
                    domain = DomainModel.objects.select_related("tenant").get(domain=hostname, folder="")
                except DomainModel.DoesNotExist:
                    raise self.TENANT_NOT_FOUND_EXCEPTION("No tenant for hostname '%s'" % hostname)
            tenant = domain.tenant
            tenant.domain_url = hostname
            tenant.folder = None
            request.urlconf = settings.TENANTS["default"]["URLCONF"]
            request.strip_tenant_from_path = lambda x: x
            if prefix and domain.folder == prefix:
                dynamic_path = settings.TENANTS["default"]["URLCONF"] + "_dynamically_tenant_prefixed"
                if not sys.modules.get(dynamic_path):
                    spec = find_spec(settings.TENANTS["default"]["URLCONF"])
                    prefixed_url_module = module_from_spec(spec)
                    spec.loader.exec_module(prefixed_url_module)
                    prefixed_url_module.urlpatterns = tenant_patterns(
                        *import_string(settings.TENANTS["default"]["URLCONF"] + ".urlpatterns")
                    )
                    sys.modules[dynamic_path] = prefixed_url_module
                    del spec
                tenant.folder = prefix
                request.urlconf = dynamic_path
                request.strip_tenant_from_path = lambda x: re.sub(r"^/{}/".format(prefix), "/", x)
                clear_url_caches()  # Required to remove previous tenant prefix from cache (#8)
            request.tenant = tenant
            connection.set_schema(request.tenant)
            return self.get_response(request)