コード例 #1
0
def reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None):
    """ Reverse url, but try to use subdomain to designate site where possible.
    This means 'site1' will not get url 'hostname/site/site1' but rather
    'challenge.hostname'
    """
    args = args or []
    kwargs = kwargs or {}

    if settings.SUBDOMAIN_IS_PROJECTNAME:

        if args:
            challenge_short_name = args[0]
        else:
            challenge_short_name = kwargs.get("challenge_short_name",
                                              settings.MAIN_PROJECT_NAME)

        protocol, domainname = settings.MAIN_HOST_NAME.split("//")

        if challenge_short_name.lower() == settings.MAIN_PROJECT_NAME.lower():
            base_url = f"{protocol}//{domainname}"
        else:
            base_url = f"{protocol}//{challenge_short_name}.{domainname}"

        site_url = reverse_org("challenge-homepage",
                               args=[challenge_short_name])

        target_url = reverse_org(
            viewname,
            urlconf=urlconf,
            args=args,
            kwargs=kwargs,
            current_app=current_app,
        )

        if target_url.startswith(site_url):
            target_url = target_url.replace(site_url, "/")

        return urljoin(base_url.lower(), target_url)

    else:

        return reverse_org(
            viewname,
            urlconf=urlconf,
            args=args,
            kwargs=kwargs,
            current_app=current_app,
        )
コード例 #2
0
ファイル: utils.py プロジェクト: zaherweb/grand-challenge.org
def reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None):
    """Reverse lookup for the viewname taking into account subdomains."""
    kwargs = kwargs or {}

    scheme = settings.DEFAULT_SCHEME

    host = Site.objects.get_current().domain.lower()
    domain = f"{scheme}://{host}"

    if "rendering_subdomain" in kwargs:
        region = kwargs.pop("rendering_subdomain")
        domain = f"{scheme}://{region}.{host}"
        urlconf = urlconf or settings.RENDERING_SUBDOMAIN_URL_CONF
    elif "challenge_short_name" in kwargs:
        challenge_short_name = kwargs.pop("challenge_short_name")
        domain = f"{scheme}://{challenge_short_name}.{host}"
        urlconf = urlconf or settings.CHALLENGE_SUBDOMAIN_URL_CONF
    else:
        urlconf = urlconf or settings.ROOT_URLCONF

    path = reverse_org(
        viewname,
        urlconf=urlconf,
        args=args,
        kwargs=kwargs,
        current_app=current_app,
    )

    return urljoin(domain.lower(), path)
コード例 #3
0
def reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None):
    """ Reverse url, but try to use subdomain to designate site where possible.
    This means 'site1' will not get url 'hostname/site/site1' but rather
    'challenge.hostname'
    """
    kwargs = kwargs or {}

    scheme = settings.DEFAULT_SCHEME

    host = Site.objects.get_current().domain.lower()
    domain = f"{scheme}://{host}"

    if "challenge_short_name" in kwargs:
        challenge_short_name = kwargs.pop("challenge_short_name")
        domain = f"{scheme}://{challenge_short_name}.{host}"
        urlconf = urlconf or settings.SUBDOMAIN_URL_CONF
    else:
        urlconf = urlconf or settings.ROOT_URLCONF

    if "views.flatpage" in viewname.lower() and "url" in kwargs:
        # Fix for a long standing bug in django flatpages
        # https://code.djangoproject.com/ticket/15658
        kwargs.update({"url": kwargs["url"].lstrip("/")})

    path = reverse_org(
        viewname,
        urlconf=urlconf,
        args=args,
        kwargs=kwargs,
        current_app=current_app,
    )

    return urljoin(domain.lower(), path)
コード例 #4
0
def reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None):
    """ Reverse url, but try to use subdomain to designate site where possible.
    This means 'site1' will not get url 'hostname/site/site1' but rather
    'challenge.hostname'
    """
    kwargs = kwargs or {}

    scheme = settings.DEFAULT_SCHEME

    host = Site.objects.get_current().domain.lower()
    domain = f"{scheme}://{host}"

    if "challenge_short_name" in kwargs:
        challenge_short_name = kwargs.pop("challenge_short_name")
        if challenge_short_name.lower() != settings.MAIN_PROJECT_NAME.lower():
            domain = f"{scheme}://{challenge_short_name}.{host}"

        urlconf = urlconf or settings.SUBDOMAIN_URL_CONF
    else:
        urlconf = urlconf or settings.ROOT_URLCONF

    path = reverse_org(
        viewname,
        urlconf=urlconf,
        args=args,
        kwargs=kwargs,
        current_app=current_app,
    )

    return urljoin(domain.lower(), path)
コード例 #5
0
def reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None):
    """ Reverse url, but try to use subdomain to designate site where possible.
    This means 'site1' will not get url 'hostname/site/site1' but rather
    'challenge.hostname'
    """
    if args is not None:
        challenge_short_name = args[0]
    elif kwargs is not None and 'challenge_short_name' in kwargs:
        challenge_short_name = kwargs['challenge_short_name']
    else:
        challenge_short_name = None

    if settings.SUBDOMAIN_IS_PROJECTNAME and challenge_short_name:

        protocol, domainname = settings.MAIN_HOST_NAME.split("//")

        base_url = f"{protocol}//{challenge_short_name}.{domainname}".lower()

        site_url = reverse_org('challenge-homepage',
                               args=[challenge_short_name])

        target_url = reverse_org(
            viewname,
            urlconf=urlconf,
            args=args,
            kwargs=kwargs,
            current_app=current_app,
        )

        if target_url.startswith(site_url):
            target_url = target_url.replace(site_url, "/")

        return urljoin(base_url, target_url)

    else:
        return reverse_org(
            viewname,
            urlconf=urlconf,
            args=args,
            kwargs=kwargs,
            current_app=current_app,
        )