2019-05-15 18:23:48 +02:00
|
|
|
# fargo - document box
|
|
|
|
# Copyright (C) 2016-2019 Entr'ouvert
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU Affero General Public License as published
|
|
|
|
# by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2018-03-22 00:20:41 +01:00
|
|
|
from django.utils.http import urlencode
|
2018-04-05 22:21:04 +02:00
|
|
|
from django.utils.six.moves.urllib import parse as urlparse
|
2018-03-22 00:20:41 +01:00
|
|
|
|
|
|
|
|
2018-03-29 17:00:50 +02:00
|
|
|
def make_url(__url, **kwargs):
|
2018-03-22 00:20:41 +01:00
|
|
|
request = kwargs.pop('request', None)
|
2018-03-29 17:00:50 +02:00
|
|
|
parsed = urlparse.urlparse(__url)
|
2018-03-22 00:20:41 +01:00
|
|
|
query = urlparse.parse_qs(parsed.query)
|
2018-04-05 22:21:04 +02:00
|
|
|
for key, value in kwargs.items():
|
2018-03-22 00:20:41 +01:00
|
|
|
if value is not None:
|
|
|
|
query[key] = value
|
|
|
|
parsed = parsed[:4] + (urlencode(query),) + parsed[5:]
|
|
|
|
url = urlparse.urlunparse(parsed)
|
|
|
|
if request:
|
|
|
|
return request.build_absolute_uri(url)
|
|
|
|
return url
|