def _set_permissions(patterns, exclude_permissions): for pattern in patterns: if isinstance(pattern, RegexURLResolver): if pattern.namespace in exclude_permissions: continue _set_permissions(pattern.url_patterns, exclude_permissions) else: from cms.utils.decorators import cms_perms if DJANGO_1_9: pattern._callback = cms_perms(pattern.callback) else: pattern.callback = cms_perms(pattern.callback)
def get_app_patterns(): """ Get a list of patterns for all hooked apps. How this works: By looking through all titles with an app hook (application_urls) we find all urlconf modules we have to hook into titles. If we use the ML URL Middleware, we namespace those patterns with the title language. All 'normal' patterns from the urlconf get re-written by prefixing them with the title path and then included into the cms url patterns. """ from cms.models import Title try: current_site = Site.objects.get_current() except Site.DoesNotExist: current_site = None included = [] # we don't have a request here so get_page_queryset() can't be used, # so use public() queryset. # This can be done because url patterns are used just in frontend title_qs = Title.objects.public().filter(page__site=current_site) hooked_applications = {} # Loop over all titles with an application hooked to them for title in title_qs.exclude(page__application_urls=None).exclude(page__application_urls='').select_related(): path = title.path mix_id = "%s:%s:%s" % (path + "/", title.page.application_urls, title.language) if mix_id in included: # don't add the same thing twice continue if not settings.APPEND_SLASH: path += '/' if title.page_id not in hooked_applications: hooked_applications[title.page_id] = {} app = apphook_pool.get_apphook(title.page.application_urls) app_ns = app.app_name, title.page.application_namespace with force_language(title.language): hooked_applications[title.page_id][title.language] = (app_ns, get_patterns_for_title(path, title), app) included.append(mix_id) # Build the app patterns to be included in the cms urlconfs app_patterns = [] for page_id in hooked_applications.keys(): resolver = None for lang in hooked_applications[page_id].keys(): (app_ns, inst_ns), current_patterns, app = hooked_applications[page_id][lang] if not resolver: resolver = AppRegexURLResolver(r'', 'app_resolver', app_name=app_ns, namespace=inst_ns) resolver.page_id = page_id if app.permissions: from cms.utils.decorators import cms_perms for pat in current_patterns: pat._callback = cms_perms(pat.callback) extra_patterns = patterns('', *current_patterns) resolver.url_patterns_dict[lang] = extra_patterns app_patterns.append(resolver) APP_RESOLVERS.append(resolver) return app_patterns
def get_app_patterns(): """ Get a list of patterns for all hooked apps. How this works: By looking through all titles with an app hook (application_urls) we find all urlconf modules we have to hook into titles. If we use the ML URL Middleware, we namespace those patterns with the title language. All 'normal' patterns from the urlconf get re-written by prefixing them with the title path and then included into the cms url patterns. """ from cms.models import Title try: current_site = Site.objects.get_current() except Site.DoesNotExist: current_site = None included = [] # we don't have a request here so get_page_queryset() can't be used, # so use public() queryset. # This can be done because url patterns are used just in frontend title_qs = Title.objects.public().filter(page__site=current_site) hooked_applications = {} # Loop over all titles with an application hooked to them for title in title_qs.exclude(page__application_urls=None).exclude( page__application_urls='').select_related(): path = title.path mix_id = "%s:%s:%s" % (path + "/", title.page.application_urls, title.language) if mix_id in included: # don't add the same thing twice continue if not settings.APPEND_SLASH: path += '/' if title.page_id not in hooked_applications: hooked_applications[title.page_id] = {} app = apphook_pool.get_apphook(title.page.application_urls) app_ns = app.app_name, title.page.application_namespace with force_language(title.language): hooked_applications[title.page_id][title.language] = ( app_ns, get_patterns_for_title(path, title), app) included.append(mix_id) # Build the app patterns to be included in the cms urlconfs app_patterns = [] for page_id in hooked_applications.keys(): resolver = None for lang in hooked_applications[page_id].keys(): (app_ns, inst_ns ), current_patterns, app = hooked_applications[page_id][lang] if not resolver: resolver = AppRegexURLResolver(r'', 'app_resolver', app_name=app_ns, namespace=inst_ns) resolver.page_id = page_id if app.permissions: from cms.utils.decorators import cms_perms for pat in current_patterns: pat._callback = cms_perms(pat.callback) extra_patterns = patterns('', *current_patterns) resolver.url_patterns_dict[lang] = extra_patterns app_patterns.append(resolver) APP_RESOLVERS.append(resolver) return app_patterns