src/ldt/ldt/utils/url.py
changeset 1194 8e20df96315b
parent 1187 73403060f297
child 1398 f40668870c7a
--- a/src/ldt/ldt/utils/url.py	Thu May 23 00:17:02 2013 +0200
+++ b/src/ldt/ldt/utils/url.py	Fri May 24 02:20:46 2013 +0200
@@ -1,11 +1,13 @@
 from django.contrib.staticfiles.storage import staticfiles_storage
-from django.core.urlresolvers import reverse
+from django.core.urlresolvers import reverse, get_script_prefix
+from django.utils.encoding import iri_to_uri
 from ldt.utils.web_url_management import get_web_url
 from ldt import settings
 from django.conf import settings as djangosettings
 import httplib2
 import re
 import urlparse
+from django.utils.http import urlquote
 
 def static(path):
     return staticfiles_storage.url(path)
@@ -45,4 +47,19 @@
 
 
 def is_absolute(url):
-    return bool(urlparse.urlparse(url).scheme)
\ No newline at end of file
+    return bool(urlparse.urlparse(url).scheme)
+
+###
+# 
+#
+def reverse_prefix(viewname, urlconf=None, args=None, kwargs=None, prefix=None, current_app=None):
+    
+    url = reverse(viewname,urlconf,args,kwargs,prefix,current_app)
+    prefix = get_script_prefix()
+    quoted_prefix = urlquote(prefix)
+    clean_prefix = iri_to_uri(prefix)
+    
+    if url.startswith(quoted_prefix):
+        return clean_prefix + url[len(quoted_prefix):]
+    else:
+        return url