propagates query string parameters when login in (so that link with direct coment id are properly propagated)
--- a/src/cm/middleware.py Thu Jul 15 16:54:29 2010 +0200
+++ b/src/cm/middleware.py Thu Jul 15 16:55:31 2010 +0200
@@ -2,6 +2,7 @@
from django.conf import settings
from django.http import HttpResponseServerError,HttpResponseRedirect
from django.core.urlresolvers import reverse
+from urllib import urlencode
class CmMiddleware(object):
@@ -11,7 +12,8 @@
traceback.print_exc()
if type(exception) == UnauthorizedException:
if request.user.is_anonymous():
- login_url = reverse('login') + '?next=%s' %request.META['PATH_INFO']
+ query = urlencode({'next': request.META['PATH_INFO'], 'q' : request.META['QUERY_STRING'] })
+ login_url = reverse('login') + '?' + query
return HttpResponseRedirect(login_url)
else:
redirect_url = reverse('unauthorized')
--- a/src/cm/templates/site/login_form.html Thu Jul 15 16:54:29 2010 +0200
+++ b/src/cm/templates/site/login_form.html Thu Jul 15 16:55:31 2010 +0200
@@ -27,6 +27,9 @@
{% if request.GET.next %}
<input type="hidden" name="next" value="{{ request.GET.next }}">
{% endif %}
+{% if request.GET.q %}
+<input type="hidden" name="q" value="{{ request.GET.q }}">
+{% endif %}
</form>
--- a/src/cm/views/user.py Thu Jul 15 16:54:29 2010 +0200
+++ b/src/cm/views/user.py Thu Jul 15 16:55:31 2010 +0200
@@ -544,8 +544,12 @@
display_message(request, _(u"You're logged in!"))
next = request.POST.get('next', None)
+ q = request.POST.get('q', None)
if next and next.startswith('/'):
- return HttpResponseRedirect(next)
+ if q:
+ return HttpResponseRedirect(next + '?' + q)
+ else:
+ return HttpResponseRedirect(next)
else:
return HttpResponseRedirect(reverse('index'))