Exemple #1
0
def get_absolute_url(path: str = '/', site_id: str = None):
    """
    Retrieve the absolute URL by incorporating the provided path with the site
    scheme and domain from the Django Sites settings.

    Parameters
    ----------
    path
        Path of the URL. By default, this is '/'.
    site_id
        Site ID string.

    Returns
    -------
    str
        The absolute URL.
    """
    if is_absolute_url(path):
        return path
    if site_id:
        site = sites.get_by_id(site_id)
    else:
        site = sites.get_current()
    return build_absolute_url(scheme=site.scheme,
                              domain=site.domain,
                              path=path)
Exemple #2
0
def make_path_remove_lang(value, language):
    site = get_current()
    current_language = language
    url = '/'.join(value.split('/')[2:-1])
    lang_path = "{0}://{1}/{2}/{3}/".format(
        str(site.scheme), str(site.domain), str(current_language), str(url))
    return lang_path
Exemple #3
0
def get_absolute_url(path):
    """Return a path as an absolute url.
    """
    if is_absolute_url(path):
        return path
    site = sites.get_current()
    return build_url(path, scheme=site.scheme, domain=site.domain)
Exemple #4
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        if settings.MEDIA_URL.startswith("/"):
            site = sites.get_current()
            url_tmpl = "{scheme}//{domain}{url}"
            scheme = site.scheme and "{0}:".format(site.scheme) or ""
            self.base_url = url_tmpl.format(scheme=scheme, domain=site.domain, url=settings.MEDIA_URL)
Exemple #5
0
def get_absolute_url(path, site_id=None):
    """Return a path as an absolute url."""
    if is_absolute_url(path):
        return path
    if site_id:
        site = sites.get_by_id(site_id)
    else:
        site = sites.get_current()
    return build_url(path, scheme=site.scheme, domain=site.domain)
Exemple #6
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        if settings.MEDIA_URL.startswith("/"):
            site = sites.get_current()
            url_tmpl = "{scheme}//{domain}{url}"
            scheme = site.scheme and "{0}:".format(site.scheme) or ""
            self.base_url = url_tmpl.format(scheme=scheme, domain=site.domain,
                                            url=settings.MEDIA_URL)
Exemple #7
0
def get_absolute_url(path, site_id=None):
    """Return a path as an absolute url.
    """
    if is_absolute_url(path):
        return path
    if site_id:
        site = sites.get_by_id(site_id)
    else:
        site = sites.get_current()
    return build_url(path, scheme=site.scheme, domain=site.domain)
Exemple #8
0
def test_get_absolute_url():
    site = sites.get_current()
    assert get_absolute_url("http://domain/path") == "http://domain/path"
    assert get_absolute_url("/path") == build_url("/path",
                                                  domain=site.domain,
                                                  scheme=site.scheme)
Exemple #9
0
def test_get_absolute_url():
    site = sites.get_current()
    assert get_absolute_url("http://domain/path") == "http://domain/path"
    assert get_absolute_url("/path") == build_url("/path", domain=site.domain, scheme=site.scheme)
Exemple #10
0
def get_absolute_url(path):
    """Return a path as an absolute url."""
    if is_absolute_url(path):
        return path
    site = sites.get_current()
    return build_url(path, scheme=site.scheme, domain=site.domain)
Exemple #11
0
import hashlib
import urllib
import shortuuid
from multiprocessing.dummy import Pool

from django.conf import settings
from django.core.mail import send_mail
from django.http import HttpResponseRedirect
from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _

from django_sites import get_current

current_site = get_current()
pool = Pool(processes=2)

CLIENT_PARAMS_SPACE = "0123456789abcdefghijk" + \
                      "lmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

Errors = {"invalid_client": [_("Missing Access Key"),
                             _("Invalid Access Key")],
          "invalid_request": [_("Missing Redirect Url"),
                              _("Invalid Redirect Url"),
                              _("Missing Authorization Code"),
                              _("Invalid Authorization Code"),
                              _("Missing Secret Key"),
                              _("Invalid Secret Key"),
                              _("Missing Access Token"),
                              _("Invalid Access Token")],
          "invalid_data": [_("Either Access Key or Redirect Url is Invalid")]}