Пример #1
0
def normalize_image_url(url):
    """
    takes an s3 url or relative url and returns the part that is saved in the
    database (relative to the storage root).
    """
    if url.startswith('http://') or url.startswith('https://'):
        url = URL(url).path
        bucket = '/{}/'.format(timelapse_storage.bucket_name)
        if url.startswith(bucket):
            url = url[len(bucket):]
        if url.startswith(timelapse_storage.location):
            url = url[len(timelapse_storage.location):]
    if hasattr(timelapse_storage, 'base_url') and url.startswith(timelapse_storage.base_url):
        url = url[len(timelapse_storage.base_url):]
    if url.startswith('/'):
        url = url[1:]
    return url
Пример #2
0
def normalize_image_url(url):
    """
    takes an s3 url or relative url and returns the part that is saved in the
    database (relative to the storage root).
    """
    if url.startswith("http://") or url.startswith("https://"):
        url = URL(url).path
        bucket = "/{}/".format(timelapse_storage.bucket_name)
        if url.startswith(bucket):
            url = url[len(bucket):]
        if url.startswith(timelapse_storage.location):
            url = url[len(timelapse_storage.location):]
    if hasattr(timelapse_storage, "base_url") and url.startswith(
            timelapse_storage.base_url):
        url = url[len(timelapse_storage.base_url):]
    if url.startswith("/"):
        url = url[1:]
    return url