def process_request(self, request): MULTISITE_CMS_URLS = getattr(settings, 'MULTISITE_CMS_URLS', {}) MULTISITE_CMS_ALIASES = getattr(settings, 'MULTISITE_CMS_ALIASES', {}) MULTISITE_CMS_FALLBACK = getattr(settings, 'MULTISITE_CMS_FALLBACK', '') try: parsed = urlparse.urlparse(request.build_absolute_uri()) host = parsed.hostname.split(':')[0] urlconf = None try: urlconf = MULTISITE_CMS_URLS[host] except KeyError: for domain, hosts in MULTISITE_CMS_ALIASES.items(): if host in hosts and domain in MULTISITE_CMS_URLS: urlconf = MULTISITE_CMS_URLS[domain] break if (not urlconf and MULTISITE_CMS_FALLBACK and MULTISITE_CMS_FALLBACK in MULTISITE_CMS_URLS.keys()): urlconf = MULTISITE_CMS_URLS[MULTISITE_CMS_FALLBACK] if urlconf: request.urlconf = urlconf # sets urlconf for current thread, so that code that does not know # about the request (e.g MyModel.get_absolute_url()) get the correct # urlconf. set_urlconf(urlconf) try: # In django CMS 3.4.2 this allows us to save a few queries thanks to per-site appresolvers caching reload_urlconf(clear_cache=False) except TypeError: reload_urlconf() except KeyError: # use default urlconf (settings.ROOT_URLCONF) set_urlconf(None)
def create(self): page, created = self.create_page( ) # Create page (and page title) in default language self.create_title(page) # Create page title in all other languages # # We publish the page before self.fill_content() # # Maybe the create process will try to find the published # page instance (e.g.: get_absolute_url() may be called) self.publish(page) if created: # Add plugins only on new created pages # otherwise we will add more and more plugins # on every run! for placeholder_slot in self.placeholder_slots: self.fill_content( page, placeholder_slot) # Add content to the created page. # Publish again, to make the filled content available: self.publish(page) # Force to reload the url configuration. # Important for unittests to "find" all plugins ;) apphook_reload.reload_urlconf() return page, created
def process_request(self, request): domain = self._get_domain(request) urlconf = self._get_urlconf(domain) # sets urlconf for current thread, so that code that does not know # about the request (e.g MyModel.get_absolute_url()) get the correct # urlconf. # urlconf might be None, in that case, the default is set set_urlconf(urlconf) reload_urlconf()
def test_sitemap_with_unpublished(self): pages = self.get_pages() self.get_posts() sitemap = BlogSitemap() self.assertEqual(len(sitemap.items()), 4) # unpublish all the pages for page in pages: page.unpublish('en') page.unpublish('it') reload_urlconf() self.assertEqual(len(sitemap.items()), 0)
def create(self): for count in range(1, self.count + 1): self.current_count = count for level in range(1, self.levels + 1): self.current_level = level log.info("Level: %i current count: %i" % (self.current_level, self.current_count)) page, created = super().create( ) # Create page (and page title) in default language self.page_data[(self.current_level, self.current_count)] = page # Force to reload the url configuration. # Important for unittests to "find" all plugins ;) apphook_reload.reload_urlconf() return self.page_data