def reverse(viewname, subdomain=UNSET, scheme=None, args=None, kwargs=None, current_app=None): """ Reverses a URL from the given parameters, in a similar fashion to :meth:`django.core.urlresolvers.reverse`. :param viewname: the name of URL :param subdomain: the subdomain to use for URL reversing :param scheme: the scheme to use when generating the full URL :param args: positional arguments used for URL reversing :param kwargs: named arguments used for URL reversing :param current_app: hint for the currently executing application """ if subdomain is not UNSET: urlconf = settings.SUBDOMAIN_URLCONFS.get(subdomain, settings.ROOT_URLCONF) path = simple_reverse(viewname, urlconf=urlconf, args=args, kwargs=kwargs, current_app=current_app) else: path = None for subdomain, urlconf in settings.SUBDOMAIN_URLCONFS.items(): try: path = simple_reverse(viewname, urlconf=urlconf, args=args, kwargs=kwargs, current_app=current_app) except NoReverseMatch: path = None else: break if not path: raise NoReverseMatch( "Reverse for '%s' with arguments '%s' and keyword " "arguments '%s' not found." % (viewname, args, kwargs)) domain = get_domain() if subdomain is not None: domain = '%s.%s' % (subdomain, domain) return urljoin(domain, path, scheme=scheme)
def reverse(viewname, subdomain=None, scheme=None, args=None, kwargs=None, current_app=None): """ Reverses a URL from the given parameters, in a similar fashion to :meth:`django.core.urlresolvers.reverse`. :param viewname: the name of URL :param subdomain: the subdomain to use for URL reversing :param scheme: the scheme to use when generating the full URL :param args: positional arguments used for URL reversing :param kwargs: named arguments used for URL reversing :param current_app: hint for the currently executing application """ urlconf = settings.SUBDOMAIN_URLCONFS.get(subdomain, settings.ROOT_URLCONF) domain = get_domain() if subdomain is not None: domain = '%s.%s' % (subdomain, domain) path = simple_reverse(viewname, urlconf=urlconf, args=args, kwargs=kwargs, current_app=current_app) return urljoin(domain, path, scheme=scheme)
def reverse(viewname, subdomain=None, scheme=None, args=None, kwargs=None, current_app=None): """ Reverses a URL from the given parameters, in a similar fashion to :meth:`django.core.urlresolvers.reverse`. :param viewname: the name of URL :param subdomain: the subdomain to use for URL reversing :param scheme: the scheme to use when generating the full URL :param args: positional arguments used for URL reversing :param kwargs: named arguments used for URL reversing :param current_app: hint for the currently executing application """ urlconf = None for pattern, urls in settings.SUBDOMAIN_URLCONFS: matches = re.match(pattern, subdomain) if matches: urlconf = urls break domain = get_domain() if subdomain is not None: domain = '%s.%s' % (subdomain, domain) path = simple_reverse(viewname, urlconf=urlconf, args=args, kwargs=kwargs, current_app=current_app) return urljoin(domain, path, scheme=scheme)
def reverse(viewname, subdomain=UNSET, scheme=None, args=None, kwargs=None, current_app=None): """ Reverses a URL from the given parameters, in a similar fashion to :meth:`django.core.urlresolvers.reverse`. :param viewname: the name of URL :param subdomain: the subdomain to use for URL reversing :param scheme: the scheme to use when generating the full URL :param args: positional arguments used for URL reversing :param kwargs: named arguments used for URL reversing :param current_app: hint for the currently executing application """ if subdomain is not UNSET: urlconf = settings.SUBDOMAIN_URLCONFS.get(subdomain, settings.ROOT_URLCONF) path = simple_reverse(viewname, urlconf=urlconf, args=args, kwargs=kwargs, current_app=current_app) else: path = None for subdomain, urlconf in settings.SUBDOMAIN_URLCONFS.iteritems(): try: path = simple_reverse(viewname, urlconf=urlconf, args=args, kwargs=kwargs, current_app=current_app) except NoReverseMatch: path = None else: break if not path: raise NoReverseMatch("Reverse for '%s' with arguments '%s' and keyword " "arguments '%s' not found." % (viewname, args, kwargs)) domain = get_domain() if subdomain is not None: domain = '%s.%s' % (subdomain, domain) return urljoin(domain, path, scheme=scheme)
def reverse(viewname, subdomain=None, scheme=None, ssl=False, args=None, kwargs=None, current_app=None, request=None): """ Reverses a URL from the given parameters, in a similar fashion to :meth:`django.core.urlresolvers.reverse`. :param viewname: the name of URL :param subdomain: the subdomain to use for URL reversing :param scheme: the scheme to use when generating the full URL, defaults to the value of ``settings.DEFAULT_URL_SCHEME`` :param args: positional arguments used for URL reversing :param kwargs: named arguments used for URL reversing :param current_app: hint for the currently executing application """ urlconf = settings.SUBDOMAIN_URLCONFS.get(subdomain, settings.ROOT_URLCONF) if scheme is None: scheme = getattr(settings, 'DEFAULT_URL_SCHEME', 'http') domain = get_domain(request) if subdomain is not None: domain = '%s.%s' % (subdomain, domain) path = simple_reverse(viewname, urlconf=urlconf, args=args, kwargs=kwargs, current_app=current_app) if request and domain == request.get_host(): if scheme == '' or ((scheme == 'http' and not request.is_secure()) or (scheme == 'https' and request.is_secure())): return path if ssl and not settings.DEBUG: scheme = 'https' return urljoin(domain, path, scheme=scheme)
def reverse(viewname, subdomain=None, scheme=None, ssl=False, args=None, kwargs=None, current_app=None, request=None): """ Reverses a URL from the given parameters, in a similar fashion to :meth:`django.core.urlresolvers.reverse`. :param viewname: the name of URL :param subdomain: the subdomain to use for URL reversing :param scheme: the scheme to use when generating the full URL, defaults to the value of ``settings.DEFAULT_URL_SCHEME`` :param args: positional arguments used for URL reversing :param kwargs: named arguments used for URL reversing :param current_app: hint for the currently executing application """ urlconf = settings.SUBDOMAIN_URLCONFS.get(subdomain, settings.ROOT_URLCONF) if scheme is None: scheme = getattr(settings, 'DEFAULT_URL_SCHEME', 'http') domain = get_domain(request) if subdomain is not None: domain = '%s.%s' % (subdomain, domain) path = simple_reverse(viewname, urlconf=urlconf, args=args, kwargs=kwargs, current_app=current_app) if request and domain == request.get_host(): if scheme is '' or ( (scheme is 'http' and not request.is_secure()) or (scheme is 'https' and request.is_secure())): return path if ssl and not settings.DEBUG: scheme = 'https' return urljoin(domain, path, scheme=scheme)