Make explicit cache purge on survey votes
authorMagnus Hagander <magnus@hagander.net>
Sat, 19 Oct 2013 13:09:47 +0000 (15:09 +0200)
committerMagnus Hagander <magnus@hagander.net>
Sat, 19 Oct 2013 13:09:47 +0000 (15:09 +0200)
It should have been done through the model, but that is somehow not working.
Therefor, make an immediate purge of the results to the specific survey that
is being voted on.

pgweb/survey/views.py

index 65f0afc63ac91fa12198d4999563ccff02745142..68e84b5a78e42a50126bff5fe3dc51d3b5041b41 100644 (file)
@@ -5,7 +5,7 @@ from django.template.defaultfilters import slugify
 from django.views.decorators.csrf import csrf_exempt
 
 from pgweb.util.contexts import NavContext
-from pgweb.util.misc import get_client_ip
+from pgweb.util.misc import get_client_ip, varnish_purge
 from pgweb.util.helpers import HttpServerError
 
 from models import Survey, SurveyAnswer, SurveyLock
@@ -54,5 +54,10 @@ def vote(request, surveyid):
        setattr(answers, attrname, getattr(answers, attrname)+1)
        answers.save()
 
+       # Do explicit varnish purge, since it seems that the model doesn't
+       # do it properly. Possibly because of the cute stuff we do with
+       # getattr/setattr above.
+       varnish_purge("/community/survey/%s/" % surveyid)
+
        return HttpResponseRedirect("/community/survey/%s/" % surveyid)