2012-09-20 16:06:27 +04:00
|
|
|
"""
|
|
|
|
Provide reverse functions that return fully qualified URLs
|
|
|
|
"""
|
2013-02-05 00:55:35 +04:00
|
|
|
from __future__ import unicode_literals
|
2012-09-20 16:06:27 +04:00
|
|
|
from django.core.urlresolvers import reverse as django_reverse
|
2014-10-01 16:09:14 +04:00
|
|
|
from django.utils import six
|
2012-09-20 16:06:27 +04:00
|
|
|
from django.utils.functional import lazy
|
|
|
|
|
|
|
|
|
2012-10-29 21:08:38 +04:00
|
|
|
def reverse(viewname, args=None, kwargs=None, request=None, format=None, **extra):
|
2012-09-20 16:06:27 +04:00
|
|
|
"""
|
|
|
|
Same as `django.core.urlresolvers.reverse`, but optionally takes a request
|
|
|
|
and returns a fully qualified URL, using the request to get the base URL.
|
|
|
|
"""
|
2012-10-29 21:08:38 +04:00
|
|
|
if format is not None:
|
|
|
|
kwargs = kwargs or {}
|
|
|
|
kwargs['format'] = format
|
|
|
|
url = django_reverse(viewname, args=args, kwargs=kwargs, **extra)
|
2012-09-20 16:06:27 +04:00
|
|
|
if request:
|
|
|
|
return request.build_absolute_uri(url)
|
|
|
|
return url
|
|
|
|
|
|
|
|
|
2014-10-01 16:09:14 +04:00
|
|
|
reverse_lazy = lazy(reverse, six.text_type)
|