Implement `reverse_lazy()'

This commit is contained in:
Daniel Izquierdo 2012-02-21 15:55:39 +09:00
parent 6f4fab81d2
commit f17f3886f4

View File

@ -1,3 +1,4 @@
import django
from django.utils.encoding import smart_unicode
from django.utils.xmlutils import SimplerXMLGenerator
from django.core.urlresolvers import resolve, reverse as django_reverse
@ -181,3 +182,13 @@ def reverse(viewname, request, *args, **kwargs):
*request* to build a fully qualified URL.
"""
return request.build_absolute_uri(django_reverse(viewname, *args, **kwargs))
if django.VERSION >= (1, 4):
from django.core.urlresolvers import reverse_lazy as django_reverse_lazy
def reverse_lazy(viewname, request, *args, **kwargs):
"""
Do the same as :py:func:`django.core.urlresolvers.reverse_lazy` but using
*request* to build a fully qualified URL.
"""
return request.build_absolute_uri(django_reverse_lazy(viewname, *args, **kwargs))