Python django.urls.get_callable() Examples

The following are 8 code examples of django.urls.get_callable(). 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.urls , or try the search function .
Example #1
Source File: url-fixer.py    From coursys with GNU General Public License v3.0 6 votes vote down vote up
def catalogue_resolver(resolver, ns=()):
    #index_full = get_callable('dashboard:index_full')
    view_names = initial_view_names
    resolver._populate()
    for fn in list(resolver.reverse_dict.keys()):
        if isinstance(fn, str) or fn.__name__ in ['RedirectView']:
            continue
        new_name = ':'.join(ns + (fn.__name__,))
        view_names[fn] = new_name

    for n,v in list(resolver.namespace_dict.values()):
        this_ns = ns + (v.namespace,)
        #print this_ns, v
        vns = catalogue_resolver(v, ns=this_ns)
        view_names.update(vns)

    return view_names 
Example #2
Source File: url-fixer.py    From coursys with GNU General Public License v3.0 6 votes vote down vote up
def fix_references(fn, view_names):
    new_content = []
    with open(fn, 'r') as code:
        for line in code:
            m = dot_ref_re.search(line)
            if m:
                dotted = m.group('dotted')
                viewfunc = get_callable(dotted)
                newline = line.replace(dotted, view_names[viewfunc])
            else:
                newline = line
            new_content.append(newline)

            m = function_reverse_re.search(line)
            if m:
                print("function reference reverse() in ", fn)

            m = no_namespace_tag_re.search(line)
            if m:
                print("no namespace on {% url %} in ", fn)

    with open(fn, 'w') as py:
        py.write(''.join(new_content)) 
Example #3
Source File: flags.py    From coursys with GNU General Public License v3.0 5 votes vote down vote up
def get_disabled_view():
    module = settings.FEATUREFLAGS_DISABLED_VIEW
    return get_callable(module) 
Example #4
Source File: csrf.py    From bioforum with MIT License 5 votes vote down vote up
def _get_failure_view():
    """Return the view to be used for CSRF rejections."""
    return get_callable(settings.CSRF_FAILURE_VIEW) 
Example #5
Source File: csrf.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
def _get_failure_view():
    """Return the view to be used for CSRF rejections."""
    return get_callable(settings.CSRF_FAILURE_VIEW) 
Example #6
Source File: csrf.py    From python with Apache License 2.0 5 votes vote down vote up
def _get_failure_view():
    """
    Returns the view to be used for CSRF rejections
    """
    return get_callable(settings.CSRF_FAILURE_VIEW) 
Example #7
Source File: csrf.py    From python2017 with MIT License 5 votes vote down vote up
def _get_failure_view():
    """
    Returns the view to be used for CSRF rejections
    """
    return get_callable(settings.CSRF_FAILURE_VIEW) 
Example #8
Source File: __init__.py    From maas with GNU Affero General Public License v3.0 5 votes vote down vote up
def get_resource_uri_template(self):
    """
    URI template processor.
    See http://bitworking.org/projects/URI-Templates/
    """

    def _convert(template, params=[]):
        """URI template converter"""
        paths = template % dict([p, "{%s}" % p] for p in params)
        return "%s%s" % (get_script_prefix(), paths)

    try:
        resource_uri = self.handler.resource_uri()
        components = [None, [], {}]

        for i, value in enumerate(resource_uri):
            components[i] = value
        lookup_view, args, kwargs = components
        try:
            lookup_view = get_callable(lookup_view)
        except (ImportError, ViewDoesNotExist):
            # Emulate can_fail=True from earlier django versions.
            pass

        possibilities = get_resolver(None).reverse_dict.getlist(lookup_view)
        # The monkey patch is right here: we need to cope with 'possibilities'
        # being a list of tuples with 2 or 3 elements.
        for possibility_data in possibilities:
            possibility = possibility_data[0]
            for result, params in possibility:
                if args:
                    if len(args) != len(params):
                        continue
                    return _convert(result, params)
                else:
                    if set(kwargs.keys()) != set(params):
                        continue
                    return _convert(result, params)
    except Exception:
        return None