django.conf.settings.ROOT_URLCONF

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

200 Examples 7

Example 1

Project: dynamic-models
Source File: utils.py
View license
def reregister_in_admin(admin_site, model, admin_class=None):
    " (re)registers a dynamic model in the given admin site "

    # We use our own unregister, to ensure that the correct
    # existing model is found 
    # (Django's unregister doesn't expect the model class to change)
    unregister_from_admin(admin_site, model)
    admin_site.register(model, admin_class)

    # Reload the URL conf and clear the URL cache
    # It's important to use the same string as ROOT_URLCONF
    reload(import_module(settings.ROOT_URLCONF))
    clear_url_caches()

Example 2

Project: django-daydreamer
Source File: base.py
View license
    def get_resolver(self, request):
        """
        Returns a django.core.urlresolvers.RegexURLResolver for the request's
        urlconf, falling back to the global urlconf fom settings.
        
        """
        urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF)
        urlresolvers.set_urlconf(urlconf)
        return urlresolvers.RegexURLResolver(r'^/', urlconf)

Example 3

Project: panya
Source File: items.py
View license
    def is_active(self, request):
        urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF)
        resolver = RegexURLResolver(r'^/', urlconf)

        url_name = self.resolve_pattern_name(resolver, request.path)
        return url_name in self.matching_pattern_names

Example 4

Project: django-rest-framework
Source File: schemas.py
View license
    def __init__(self, patterns=None, urlconf=None):
        if patterns is None:
            if urlconf is None:
                # Use the default Django URL conf
                urlconf = settings.ROOT_URLCONF

            # Load the given URLconf module
            if isinstance(urlconf, six.string_types):
                urls = import_module(urlconf)
            else:
                urls = urlconf
            patterns = urls.urlpatterns

        self.patterns = patterns

Example 5

Project: splunk-webframework
Source File: jsurls.py
View license
def create_javascript_urlpatterns():
    js_patterns = SortedDict()
    handle_url_module(js_patterns, settings.ROOT_URLCONF)
    
    dirpath = path.join(settings.STATIC_ROOT, settings.JS_CACHE_DIR)
    filepath = path.join(settings.STATIC_ROOT, settings.JS_CACHE_DIR, "urlresolver.js")
    
    tmpl = loader.get_template('splunkdj:jsurls.html')
    ctx = Context({ 'patterns': json.dumps(js_patterns), 'mount': settings.MOUNT })
    rendered = tmpl.render(ctx)
    
    if not path.exists(dirpath):
        makedirs(dirpath)
    
    output_file = open(filepath, 'w')
    output_file.write(rendered)
    output_file.flush()
    
    output_file.close()

Example 6

Project: ANALYSE
Source File: tests.py
View license
    @unittest.skipUnless(settings.ROOT_URLCONF == 'cms.urls', 'Test only valid in cms')
    @patch("edxmako.middleware.REQUEST_CONTEXT")
    def test_render_to_string_when_no_global_context_cms(self, context_mock):
        """
        Test render_to_string() when makomiddleware has not initialized
        the threadlocal REQUEST_CONTEXT.context. This is meant to run in CMS.
        """
        del context_mock.context
        self.assertIn("We're having trouble rendering your component", render_to_string("html_error.html", None))

Example 7

Project: canvas
Source File: middleware.py
View license
    def process_request(self, request):
        if self.show_toolbar(request):
            if self.override_url:
                original_urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF)
                debug_toolbar.urls.urlpatterns += patterns('',
                    ('', include(original_urlconf)),
                )
                self.override_url = False
            request.urlconf = 'debug_toolbar.urls'

            self.debug_toolbars[request] = DebugToolbar(request)
            for panel in self.debug_toolbars[request].panels:
                panel.process_request(request)

Example 8

Project: HealthStarter
Source File: views.py
View license
    def get_context_data(self, **kwargs):
        views = []
        urlconf = import_module(settings.ROOT_URLCONF)
        view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
        for (func, regex, namespace, name) in view_functions:
            views.append({
                'full_name': '%s.%s' % (func.__module__, getattr(func, '__name__', func.__class__.__name__)),
                'url': simplify_regex(regex),
                'url_name': ':'.join((namespace or []) + (name and [name] or [])),
                'namespace': ':'.join((namespace or [])),
                'name': name,
            })
        kwargs.update({'views': views})
        return super(ViewIndexView, self).get_context_data(**kwargs)

Example 9

Project: django-compositepks
Source File: testcases.py
View license
    def _post_teardown(self):
        """ Performs any post-test things. This includes:

            * Putting back the original ROOT_URLCONF if it was changed.
        """
        if hasattr(self, '_old_root_urlconf'):
            settings.ROOT_URLCONF = self._old_root_urlconf
            clear_url_caches()

Example 10

Project: django-mini
Source File: tests.py
View license
    @patch('django.conf.settings')
    def test_configure_urlconf(self, settings):
        # Check our built-in URL module is configured.
        patterns = [(r'^test/', 'myapp.views.test')]
        djangomini.configure_urlconf(patterns)

        self.assertEqual(settings.ROOT_URLCONF, djangomini._rooturlconf)

Example 11

Project: tendenci
Source File: helpers.py
View license
def reload_urlconf(urlconf=None):

    from imp import reload  # python 3 needs this import.

    if urlconf is None:
        from django.conf import settings

        urlconf = settings.ROOT_URLCONF

    if HELPDESK_URLCONF in sys.modules:
        reload(sys.modules[HELPDESK_URLCONF])

    if urlconf in sys.modules:
        reload(sys.modules[urlconf])

    from django.core.urlresolvers import clear_url_caches
    clear_url_caches()

Example 12

Project: PyClassLessons
Source File: urlresolvers.py
View license
@lru_cache.lru_cache(maxsize=None)
def get_resolver(urlconf):
    if urlconf is None:
        from django.conf import settings
        urlconf = settings.ROOT_URLCONF
    return RegexURLResolver(r'^/', urlconf)

Example 13

Project: localwiki-backend-server
Source File: views.py
View license
    @staticmethod
    def get_cache_key(*args, **kwargs):
        from django.core.urlresolvers import get_urlconf
        from pages.models import name_to_url
        import urllib
        urlconf = get_urlconf() or settings.ROOT_URLCONF
        region = CacheMixin.get_region_slug_param(*args, **kwargs)
        slug = kwargs.get('slug')
        # Control characters and whitespace not allowed in memcached keys
        date1 = name_to_url(kwargs.get('date1', ''))
        date2 = name_to_url(kwargs.get('date2', ''))
        version1 = name_to_url(kwargs.get('version1', ''))
        version2 = name_to_url(kwargs.get('version2', ''))
        return 'diff:%s/%s/%s/%s/%s/%s/%s' % (urlconf, name_to_url(region), date1, date2, version1, version2, slugify(slug).replace(' ', '_'))

Example 14

Project: Django--an-app-at-a-time
Source File: views.py
View license
    def get_context_data(self, **kwargs):
        views = []
        urlconf = import_module(settings.ROOT_URLCONF)
        view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
        for (func, regex, namespace, name) in view_functions:
            views.append({
                'full_name': '%s.%s' % (func.__module__, getattr(func, '__name__', func.__class__.__name__)),
                'url': simplify_regex(regex),
                'url_name': ':'.join((namespace or []) + (name and [name] or [])),
                'namespace': ':'.join((namespace or [])),
                'name': name,
            })
        kwargs.update({'views': views})
        return super(ViewIndexView, self).get_context_data(**kwargs)

Example 15

Project: localwiki-backend-server
Source File: views.py
View license
    @staticmethod
    def get_cache_key(*args, **kwargs):
        from django.core.urlresolvers import get_urlconf
        from pages.models import name_to_url

        urlconf = get_urlconf() or settings.ROOT_URLCONF
        region = CacheMixin.get_region_slug_param(*args, **kwargs)
        # Control characters and whitespace not allowed in memcached keys
        return 'map:%s/%s/main_map' % (urlconf, name_to_url(region))

Example 16

View license
@lru_cache.lru_cache(maxsize=None)
def get_resolver(urlconf):
    if urlconf is None:
        from django.conf import settings
        urlconf = settings.ROOT_URLCONF
    return RegexURLResolver(r'^/', urlconf)

Example 17

Project: HealthStarter
Source File: urlresolvers.py
View license
@lru_cache.lru_cache(maxsize=None)
def get_resolver(urlconf=None):
    if urlconf is None:
        from django.conf import settings
        urlconf = settings.ROOT_URLCONF
    return RegexURLResolver(r'^/', urlconf)

Example 18

Project: django-pki
Source File: middleware.py
View license
def resolver(request):
    """
    Returns a RegexURLResolver for the request's urlconf.

    If the request does not have a urlconf object, then the default of
    settings.ROOT_URLCONF is used.
    """
    from django.conf import settings
    urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF)
    return RegexURLResolver(r'^/', urlconf)

Example 19

Project: django-widgy
Source File: signalhandlers.py
View license
@receiver(widgy_pre_index)
def patch_url_conf(sender, **kwargs):
    from .middleware import PatchUrlconfMiddleware
    root_urlconf = import_module(settings.ROOT_URLCONF)
    urlconf = PatchUrlconfMiddleware.get_urlconf(root_urlconf)
    set_urlconf(urlconf)

Example 20

Project: django-cms
Source File: test_apphooks.py
View license
    def reload_urls(self):
        from django.conf import settings

        url_modules = [
            'cms.urls',
            'cms.test_utils.project.second_cms_urls_for_apphook_tests',
            settings.ROOT_URLCONF,
        ]

        clear_app_resolvers()
        clear_url_caches()

        for module in url_modules:
            if module in sys.modules:
                del sys.modules[module]

Example 21

Project: django
Source File: locale.py
View license
    def process_request(self, request):
        urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF)
        i18n_patterns_used, prefixed_default_language = is_language_prefix_patterns_used(urlconf)
        language = translation.get_language_from_request(request, check_path=i18n_patterns_used)
        language_from_path = translation.get_language_from_path(request.path_info)
        if not language_from_path and i18n_patterns_used and not prefixed_default_language:
            language = settings.LANGUAGE_CODE
        translation.activate(language)
        request.LANGUAGE_CODE = translation.get_language()

Example 22

Project: django-mini
Source File: djangomini.py
View license
def configure_urlconf(patterns):
    """Sets up Django's settings.ROOT_URLCONF patterns."""
    from django.conf import settings

    # Has to be hashable or a string naming a module.
    # Make a real module for compatibility.
    mod = imp.new_module(_rooturlconf)
    mod.urlpatterns = patterns
    sys.modules[_rooturlconf] = mod
    settings.ROOT_URLCONF = _rooturlconf

Example 23

Project: django
Source File: resolvers.py
View license
@lru_cache.lru_cache(maxsize=None)
def get_resolver(urlconf=None):
    if urlconf is None:
        from django.conf import settings
        urlconf = settings.ROOT_URLCONF
    return RegexURLResolver(r'^/', urlconf)

Example 24

Project: avos
Source File: helpers.py
View license
    def _reload_urls(self):
        """CLeans up URLs.

        Clears out the URL caches, reloads the root urls module, and
        re-triggers the autodiscovery mechanism for Horizon. Allows URLs
        to be re-calculated after registering new dashboards. Useful
        only for testing and should never be used on a live site.
        """
        urlresolvers.clear_url_caches()
        reload(import_module(settings.ROOT_URLCONF))
        base.Horizon._urls()

Example 25

Project: hue
Source File: testcases.py
View license
    def _urlconf_setup(self):
        set_urlconf(None)
        if hasattr(self, 'urls'):
            self._old_root_urlconf = settings.ROOT_URLCONF
            settings.ROOT_URLCONF = self.urls
            clear_url_caches()

Example 26

Project: localwiki-backend-server
Source File: views.py
View license
    @staticmethod
    def get_cache_key(*args, **kwargs):
        from django.core.urlresolvers import get_urlconf
        from pages.models import name_to_url

        urlconf = get_urlconf() or settings.ROOT_URLCONF
        slug = kwargs.get('slug')
        region = CacheMixin.get_region_slug_param(*args, **kwargs)
        # Control characters and whitespace not allowed in memcached keys
        return 'tags:%s/%s/%s' % (urlconf, name_to_url(region), slugify(slug).replace(' ', '_'))

Example 27

Project: PyClassLessons
Source File: views.py
View license
    def get_context_data(self, **kwargs):
        views = []
        urlconf = import_module(settings.ROOT_URLCONF)
        view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
        for (func, regex, namespace, name) in view_functions:
            views.append({
                'full_name': '%s.%s' % (func.__module__, getattr(func, '__name__', func.__class__.__name__)),
                'url': simplify_regex(regex),
                'url_name': ':'.join((namespace or []) + (name and [name] or [])),
                'namespace': ':'.join((namespace or [])),
                'name': name,
            })
        kwargs.update({'views': views})
        return super(ViewIndexView, self).get_context_data(**kwargs)

Example 28

View license
def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None, current_app=None):
    original_kwargs = kwargs
    if urlconf is None:
        urlconf = get_urlconf() or settings.ROOT_URLCONF
        # We behave differently if we're using the no-region urlconf with the
        # no-region django-hosts host.
        if urlconf == 'main.urls_no_region':
            if kwargs and kwargs.get('region'):
                del kwargs['region']
    try:
        return django_reverse(viewname, urlconf=urlconf, args=args, kwargs=kwargs, prefix=prefix, current_app=current_app)
    except NoReverseMatch as e:
        if urlconf == 'main.urls_no_region':
            # Try the base urlconf and original kwargs
            host = settings.DEFAULT_HOST
            return reverse_full(host, viewname, view_args=args, view_kwargs=original_kwargs)
        else:
            raise e

Example 29

Project: localwiki-backend-server
Source File: cache.py
View license
def varnish_invalidate_page(p):
    current_urlconf = get_urlconf() or settings.ROOT_URLCONF

    if p.region.regionsettings.domain:
        # Has a domain, ugh. Need to clear two URLs on two hosts, in this case
        set_urlconf('main.urls_no_region')
        varnish_invalidate_url(p.get_absolute_url(), hostname=p.region.regionsettings.domain)

        # Now invalidate main path on LocalWiki hub
        set_urlconf('main.urls')
        varnish_invalidate_url(p.get_absolute_url())
    else:
        varnish_invalidate_url(p.get_absolute_url())

    set_urlconf(current_urlconf)

Example 30

View license
    def __init__(self, drf_router=None):
        self.endpoints = []
        self.drf_router = drf_router
        try:
            root_urlconf = import_string(settings.ROOT_URLCONF)
        except ImportError:
            # Handle a case when there's no dot in ROOT_URLCONF
            root_urlconf = import_module(settings.ROOT_URLCONF)
        if hasattr(root_urlconf, 'urls'):
            self.get_all_view_names(root_urlconf.urls.urlpatterns)
        else:
            self.get_all_view_names(root_urlconf.urlpatterns)

Example 31

Project: transurlvania
Source File: urlresolvers.py
View license
def get_resolver(urlconf, lang):
    if urlconf is None:
        from django.conf import settings
        urlconf = settings.ROOT_URLCONF
    key = (urlconf, lang)
    if key not in _resolvers:
        _resolvers[key] = MultilangRegexURLResolver(r'^/', urlconf)
    return _resolvers[key]

Example 32

Project: ANALYSE
Source File: tests.py
View license
    @unittest.skipUnless(settings.ROOT_URLCONF == 'cms.urls', 'Test only valid in cms')
    @patch("edxmako.middleware.REQUEST_CONTEXT")
    def test_render_to_string_when_no_global_context_cms(self, context_mock):
        """
        Test render_to_string() when makomiddleware has not initialized
        the threadlocal REQUEST_CONTEXT.context. This is meant to run in CMS.
        """
        del context_mock.context
        self.assertIn("We're having trouble rendering your component", render_to_string("html_error.html", None))

Example 33

Project: synnefo
Source File: volumes.py
View license
    def reload_urlconf(self):
        if 'synnefo.volume.urls' in sys.modules:
            reload(sys.modules['synnefo.volume.urls'])
        if settings.ROOT_URLCONF in sys.modules:
            reload(sys.modules[settings.ROOT_URLCONF])
        return import_module(settings.ROOT_URLCONF)

Example 34

View license
    def __init__(self, drf_router=None):
        self.endpoints = []
        self.drf_router = drf_router
        try:
            root_urlconf = import_string(settings.ROOT_URLCONF)
        except ImportError:
            # Handle a case when there's no dot in ROOT_URLCONF
            root_urlconf = import_module(settings.ROOT_URLCONF)
        if hasattr(root_urlconf, 'urls'):
            self.get_all_view_names(root_urlconf.urls.urlpatterns)
        else:
            self.get_all_view_names(root_urlconf.urlpatterns)

Example 35

Project: aldryn-events
Source File: base.py
View license
    def reload_urls(self):
        """
        Clean up url related things (caches, app resolvers, modules).
        Taken from cms.
        :return: None
        """
        clear_app_resolvers()
        clear_url_caches()
        url_modules = [
            'cms.urls',
            'aldryn_events.urls',
            settings.ROOT_URLCONF
        ]

        for module in url_modules:
            if module in sys.modules:
                del sys.modules[module]

Example 36

Project: soapfish
Source File: django_test.py
View license
    def setUp(self):  # noqa
        # XXX: Python 2.6 and unittest2 still call this method for skipped class.
        if django is None:
            self.skipTest('Django is not installed.')

        self.service = echo_service()
        settings.ROOT_URLCONF = urlconf(urlpatterns=(url(r'^ws/$', django_dispatcher(self.service)),))
        self.client = Client()

Example 37

Project: jmbo
Source File: items.py
View license
    def is_active(self, request):
        urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF)
        resolver = RegexURLResolver(r'^/', urlconf)

        url_name = self.resolve_pattern_name(resolver, request.path)
        return url_name in self.matching_pattern_names

Example 38

Project: django-widgy
Source File: middleware.py
View license
    def process_request(self, request):
        root_urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF)
        if isinstance(root_urlconf, six.string_types):
            root_urlconf = import_module(root_urlconf)
        request.urlconf = self.get_urlconf(root_urlconf, self.get_pages(logged_in=request.user.is_authenticated()))
        request._patch_urlconf_middleware_urlconf = request.urlconf

Example 39

Project: cgstudiomap
Source File: views.py
View license
    def get_context_data(self, **kwargs):
        views = []
        urlconf = import_module(settings.ROOT_URLCONF)
        view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
        for (func, regex, namespace, name) in view_functions:
            views.append({
                'full_name': '%s.%s' % (func.__module__, getattr(func, '__name__', func.__class__.__name__)),
                'url': simplify_regex(regex),
                'url_name': ':'.join((namespace or []) + (name and [name] or [])),
                'namespace': ':'.join((namespace or [])),
                'name': name,
            })
        kwargs.update({'views': views})
        return super(ViewIndexView, self).get_context_data(**kwargs)

Example 40

Project: drawquest-web
Source File: middleware.py
View license
    def process_request(self, request):
        if self.show_toolbar(request):
            if self.override_url:
                original_urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF)
                debug_toolbar.urls.urlpatterns += patterns('',
                    ('', include(original_urlconf)),
                )
                self.override_url = False
            request.urlconf = 'debug_toolbar.urls'

            self.debug_toolbars[request] = DebugToolbar(request)
            for panel in self.debug_toolbars[request].panels:
                panel.process_request(request)

Example 41

Project: cgstudiomap
Source File: urlresolvers.py
View license
@lru_cache.lru_cache(maxsize=None)
def get_resolver(urlconf=None):
    if urlconf is None:
        from django.conf import settings
        urlconf = settings.ROOT_URLCONF
    return RegexURLResolver(r'^/', urlconf)

Example 42

Project: geraldo
Source File: testcases.py
View license
    def _post_teardown(self):
        """ Performs any post-test things. This includes:

            * Putting back the original ROOT_URLCONF if it was changed.
        """
        if hasattr(self, '_old_root_urlconf'):
            settings.ROOT_URLCONF = self._old_root_urlconf
            clear_url_caches()

Example 43

Project: django-cms
Source File: apphook_reload.py
View license
def reload_urlconf(urlconf=None, new_revision=None):
    from cms.appresolver import clear_app_resolvers, get_app_patterns

    if 'cms.urls' in sys.modules:
        reload(sys.modules['cms.urls'])
    if urlconf is None:
        urlconf = settings.ROOT_URLCONF
    if urlconf in sys.modules:
        reload(sys.modules[urlconf])
    clear_app_resolvers()
    clear_url_caches()
    get_app_patterns()
    if new_revision is not None:
        set_local_revision(new_revision)

Example 44

Project: django
Source File: views.py
View license
    def get_context_data(self, **kwargs):
        views = []
        urlconf = import_module(settings.ROOT_URLCONF)
        view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
        for (func, regex, namespace, name) in view_functions:
            views.append({
                'full_name': self._get_full_name(func),
                'url': simplify_regex(regex),
                'url_name': ':'.join((namespace or []) + (name and [name] or [])),
                'namespace': ':'.join((namespace or [])),
                'name': name,
            })
        kwargs.update({'views': views})
        return super(ViewIndexView, self).get_context_data(**kwargs)

Example 45

Project: geraldo
Source File: testcases.py
View license
    def _post_teardown(self):
        """ Performs any post-test things. This includes:

            * Putting back the original ROOT_URLCONF if it was changed.
        """
        if hasattr(self, '_old_root_urlconf'):
            settings.ROOT_URLCONF = self._old_root_urlconf
            clear_url_caches()

Example 46

Project: geraldo
Source File: testcases.py
View license
    def _post_teardown(self):
        """ Performs any post-test things. This includes:

            * Putting back the original ROOT_URLCONF if it was changed.
        """
        if hasattr(self, '_old_root_urlconf'):
            settings.ROOT_URLCONF = self._old_root_urlconf
            clear_url_caches()

Example 47

View license
def reload_url_conf():
    # Reload URLs to pick up the overridden settings
    if settings.ROOT_URLCONF in sys.modules:
        reload(sys.modules[settings.ROOT_URLCONF])
    import_module(settings.ROOT_URLCONF)
    clear_url_caches()

Example 48

Project: decode-Django
Source File: urlresolvers.py
View license
def get_resolver(urlconf):
    # 如果为空, 导入 settings 中的 ROOT_URLCONF
    if urlconf is None:
        from django.conf import settings
        urlconf = settings.ROOT_URLCONF
    return RegexURLResolver(r'^/', urlconf)

Example 49

Project: avos
Source File: base.py
View license
    def _reload_urls(self):
        """Clears out the URL caches, reloads the root urls module, and
        re-triggers the autodiscovery mechanism for Horizon. Allows URLs
        to be re-calculated after registering new dashboards. Useful
        only for testing and should never be used on a live site.
        """
        urlresolvers.clear_url_caches()
        reload(import_module(settings.ROOT_URLCONF))
        base.Horizon._urls()

Example 50

Project: talk.org
Source File: tests.py
View license
    def setUp(self):
        settings.ROOT_URLCONF = 'django.contrib.formtools.test_urls'
        # Create a FormPreview instance to share between tests
        self.preview = preview.FormPreview(TestForm)
        input_template = '<input type="hidden" name="%s" value="%s" />'
        self.input = input_template % (self.preview.unused_name('stage'), "%d")