bhartiyashesh / django-voting

Automatically exported from code.google.com/p/django-voting
Other
0 stars 0 forks source link

Djangologging breaks xmlhttprequest_vote_on_object() #23

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The middleware of Django-logging will append log history html markup to any
response of content-type text/html.  Currently, no mimetype is specified in
the HttpResponse() obj returned by xmlhttprequest_vote_on_object() or by
json_error_response().  This causes the djangologging middleware to append
html junk to the json responses of these methods, breaking many json parsers.

The very simple (two line) solution is to add the
mimetype="application/json" argument to the HttpResponse() constructor
called at the end of these two methods (lines 102 and 152 of views.py in
trunc).  Doing so will cause the djangologging middleware to ignore the
json responses of these methods (leaving clean json).  This is also more
correct behavior and in compliance with standards.

What steps will reproduce the problem?
1. Using Pinax's default installation "complete project" (to use an example
of an implementation where xmlhttprequest_vote_on_object is used when
djangologging is also turned on) upvote a "bookmark" object.
2. Observe that the number of points/votes does not change.  This is in
spite of the request hitting the server and having the view execute without
error.
3. A reload of the page demonstrates that the upvote was recorded to the
database.  Calling the RESTful ajax URL directly from firebug demonstrates
that the URL returns data that contains extensive HTML and is not parsable
by the javascript code in use by Pinax. 

Original issue reported on code.google.com by leguti...@gmail.com on 25 Feb 2009 at 9:22

GoogleCodeExporter commented 9 years ago
There is a special decorator to avoid that

Original comment by cou...@gmail.com on 25 Jun 2009 at 12:34