This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
2018-11-14 18:14:14 +00:00
|
|
|
"""URL-related utils"""
|
|
|
|
from urllib.parse import urlparse
|
|
|
|
|
2020-05-08 14:10:27 +00:00
|
|
|
from django.http import HttpResponse
|
|
|
|
from django.shortcuts import redirect, reverse
|
|
|
|
from django.utils.http import urlencode
|
|
|
|
|
2018-11-14 18:14:14 +00:00
|
|
|
|
|
|
|
def is_url_absolute(url):
|
|
|
|
"""Check if domain is absolute to prevent user from being redirect somewhere else"""
|
|
|
|
return bool(urlparse(url).netloc)
|
2020-05-08 14:10:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
def redirect_with_qs(view: str, get_query_set=None, **kwargs) -> HttpResponse:
|
|
|
|
"""Wrapper to redirect whilst keeping GET Parameters"""
|
|
|
|
target = reverse(view, kwargs=kwargs)
|
|
|
|
if get_query_set:
|
|
|
|
target += "?" + urlencode(get_query_set.items())
|
|
|
|
return redirect(target)
|