Python django.core.urlresolvers.get_resolver() Examples

The following are 6 code examples of django.core.urlresolvers.get_resolver(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.core.urlresolvers , or try the search function .
Example #1
Source File: views.py    From GTDWeb with GNU General Public License v2.0 6 votes vote down vote up
def get_context_data(self, **kwargs):
        view = self.kwargs['view']
        urlconf = urlresolvers.get_urlconf()
        if urlresolvers.get_resolver(urlconf)._is_callback(view):
            mod, func = urlresolvers.get_mod_func(view)
            view_func = getattr(import_module(mod), func)
        else:
            raise Http404
        title, body, metadata = utils.parse_docstring(view_func.__doc__)
        if title:
            title = utils.parse_rst(title, 'view', _('view:') + view)
        if body:
            body = utils.parse_rst(body, 'view', _('view:') + view)
        for key in metadata:
            metadata[key] = utils.parse_rst(metadata[key], 'model', _('view:') + view)
        kwargs.update({
            'name': view,
            'summary': title,
            'body': body,
            'meta': metadata,
        })
        return super(ViewDetailView, self).get_context_data(**kwargs) 
Example #2
Source File: views.py    From openhgsenti with Apache License 2.0 6 votes vote down vote up
def get_context_data(self, **kwargs):
        view = self.kwargs['view']
        urlconf = urlresolvers.get_urlconf()
        if urlresolvers.get_resolver(urlconf)._is_callback(view):
            mod, func = urlresolvers.get_mod_func(view)
            view_func = getattr(import_module(mod), func)
        else:
            raise Http404
        title, body, metadata = utils.parse_docstring(view_func.__doc__)
        if title:
            title = utils.parse_rst(title, 'view', _('view:') + view)
        if body:
            body = utils.parse_rst(body, 'view', _('view:') + view)
        for key in metadata:
            metadata[key] = utils.parse_rst(metadata[key], 'model', _('view:') + view)
        kwargs.update({
            'name': view,
            'summary': title,
            'body': body,
            'meta': metadata,
        })
        return super(ViewDetailView, self).get_context_data(**kwargs) 
Example #3
Source File: transactions.py    From sentry-python with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def resolve(
        self,
        path,  # type: str
        urlconf=None,  # type: Union[None, Tuple[URLPattern, URLPattern, URLResolver], Tuple[URLPattern]]
    ):
        # type: (...) -> str
        resolver = get_resolver(urlconf)
        match = self._resolve(resolver, path)
        return match or path 
Example #4
Source File: patch_resolvers.py    From gro-api with GNU General Public License v2.0 5 votes vote down vote up
def outer_get_resolver(urlconf):
    return inner_get_resolver(urlconf, system_layout.current_value)

# Monkey patching `django.core.urlresolvers.get_resolver` doesn't completely
# solve the problem in Django 1.8.3 because
# `django.core.handlers.base.BaseHandler` creates a new
# `django.core.urlresolvers.RegexURLResolver` on every request. This is
# addressed by ticket #14200 (https://code.djangoproject.com/ticket/14200).
# A patch for this problem has been written and accepted, and should appear in
# the next Django release. Until then, we essentially apply the accepted patch
# ourselves by monkey patching `BaseHandler.get_response`. 
Example #5
Source File: patch_resolvers.py    From gro-api with GNU General Public License v2.0 5 votes vote down vote up
def patch_resolvers():
    urlresolvers.get_resolver = outer_get_resolver
    BaseHandler.get_response = new_get_response
    if PATCH_SWAGGER and not hasattr(UrlParser, 'old_get_apis'):
        UrlParser.old_get_apis = UrlParser.get_apis
        UrlParser.get_apis = new_get_apis 
Example #6
Source File: renderers.py    From drf-json-api with MIT License 5 votes vote down vote up
def url_to_template(self, view_name, request, template_name):
        resolver = urlresolvers.get_resolver(None)
        info = resolver.reverse_dict[view_name]

        path_template = info[0][0][0]
        # FIXME: what happens when URL has more than one dynamic values?
        # e.g. nested relations: manufacturer/%(id)s/cars/%(card_id)s
        path = path_template % {info[0][0][1][0]: '{%s}' % template_name}

        parsed_url = urlparse(request.build_absolute_uri())

        return urlunparse(
            [parsed_url.scheme, parsed_url.netloc, path, '', '', '']
        )