euscan-ng/euscanwww/annoying/utils.py
Corentin Chary 482e54cfce euscanwww: import new website
Signed-off-by: Corentin Chary <corentincj@iksaif.net>
2011-04-13 08:50:24 +02:00

27 lines
754 B
Python

from django.http import HttpResponse
from django.utils.encoding import iri_to_uri
class HttpResponseReload(HttpResponse):
"""
Reload page and stay on the same page from where request was made.
example:
def simple_view(request):
if request.POST:
form = CommentForm(request.POST):
if form.is_valid():
form.save()
return HttpResponseReload(request)
else:
form = CommentForm()
return render_to_response('some_template.html', {'form': form})
"""
status_code = 302
def __init__(self, request):
HttpResponse.__init__(self)
referer = request.META.get('HTTP_REFERER')
self['Location'] = iri_to_uri(referer or "/")