def is_valid_path(request, path): urlconf = getattr(request, 'urlconf', None) try: match = resolve(path, urlconf) if match.func == mindtouch_to_kuma_redirect: # mindtouch_to_kuma_redirect matches everything. # Check if it would return a redirect or 404. url = mindtouch_to_kuma_url(request.LANGUAGE_CODE, match.kwargs['path']) return bool(url) else: return True except Resolver404: return False
def is_valid_path(path, language_code, urlconf=None): """ Return True if the given path resolves against the default URL resolver, False otherwise. This is a convenience method to make working with "is this a match?" cases easier, avoiding try...except blocks. Based on Django 1.11.16's is_valid_path from django.urls.is_valid_path, with changes: * If the catch-all mindtouch_to_kuma_redirect was the match, check if it would return a 404. * Adds a required language_code parameter, for mindtouch_to_kuma_url """ try: match = resolve(path, urlconf) if match.func == mindtouch_to_kuma_redirect: # mindtouch_to_kuma_redirect matches everything. # Check if it would return a redirect or 404. url = mindtouch_to_kuma_url(language_code, match.kwargs["path"]) return bool(url) else: return True except Resolver404: return False
def is_valid_path(path, language_code, urlconf=None): """ Return True if the given path resolves against the default URL resolver, False otherwise. This is a convenience method to make working with "is this a match?" cases easier, avoiding try...except blocks. Based on Django 1.11.16's is_valid_path from django.urls.is_valid_path, with changes: * If the catch-all mindtouch_to_kuma_redirect was the match, check if it would return a 404. * Adds a required language_code parameter, for mindtouch_to_kuma_url """ try: match = resolve(path, urlconf) if match.func == mindtouch_to_kuma_redirect: # mindtouch_to_kuma_redirect matches everything. # Check if it would return a redirect or 404. url = mindtouch_to_kuma_url(language_code, match.kwargs['path']) return bool(url) else: return True except Resolver404: return False