def test_urlconf_registry(self): """Test urlconf_registry basic functions.""" reg.register_urlconf('Documents', 'example.documents.urls', label='Display documents') reg.get_urlconf('Documents') try: reg.register_urlconf('Documents', 'example.documents.urls', label='Display documents') except reg.UrlconfAlreadyRegistered: pass reg.registry = [] try: reg.get_urlconf('Documents') except reg.UrlconfNotFound: pass reg.register_urlconf('Documents', 'example.documents.urls', label='Display documents') self.assertEqual(reg.get_choices(), [('', 'No delegation'), ('Documents', 'Display documents')])
def delegate(self, request, context, delegation=True): # if there is a delegation to another view, # call this view instead. current_page = context['current_page'] path = context['path'] delegate_path = path.replace( current_page.get_complete_slug(hideroot=False), "") # it seems that the urlconf path have to start with a slash if len(delegate_path) == 0: delegate_path = "/" if delegate_path.startswith("//"): delegate_path = delegate_path[1:] urlconf = get_urlconf(current_page.delegate_to) try: result = resolve(delegate_path, urlconf) except Resolver404: raise Http404 if result: view, args, kwargs = result kwargs.update(context) return view(request, *args, **kwargs)