aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/reverse.py
diff options
context:
space:
mode:
authorTom Christie2012-02-25 18:45:17 +0000
committerTom Christie2012-02-25 18:45:17 +0000
commit1cde31c86d9423e9b7a7409c2ef2ba7c0500e47f (patch)
treeea24bce0f24507aa43f408776ccf7324f204256d /djangorestframework/reverse.py
parent5fd4c639d7c64572dd07dc31dcd627bed9469b05 (diff)
downloaddjango-rest-framework-1cde31c86d9423e9b7a7409c2ef2ba7c0500e47f.tar.bz2
Massive merge
Diffstat (limited to 'djangorestframework/reverse.py')
-rw-r--r--djangorestframework/reverse.py21
1 files changed, 9 insertions, 12 deletions
diff --git a/djangorestframework/reverse.py b/djangorestframework/reverse.py
index ad06f966..ba663f98 100644
--- a/djangorestframework/reverse.py
+++ b/djangorestframework/reverse.py
@@ -2,22 +2,19 @@
Provide reverse functions that return fully qualified URLs
"""
from django.core.urlresolvers import reverse as django_reverse
-from djangorestframework.compat import reverse_lazy as django_reverse_lazy
+from django.utils.functional import lazy
-def reverse(viewname, request, *args, **kwargs):
+def reverse(viewname, *args, **kwargs):
"""
- Do the same as `django.core.urlresolvers.reverse` but using
- *request* to build a fully qualified URL.
+ 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.
"""
+ request = kwargs.pop('request', None)
url = django_reverse(viewname, *args, **kwargs)
- return request.build_absolute_uri(url)
+ if request:
+ return request.build_absolute_uri(url)
+ return url
-def reverse_lazy(viewname, request, *args, **kwargs):
- """
- Do the same as `django.core.urlresolvers.reverse_lazy` but using
- *request* to build a fully qualified URL.
- """
- url = django_reverse_lazy(viewname, *args, **kwargs)
- return request.build_absolute_uri(url)
+reverse_lazy = lazy(reverse, str)