I have "document_delete" in my view, which calls "is_draft owner":
This is the "is_draft_owner":
def is_draft_owner(id = None, user = None):
if id and user:
return user.pk is Draft.objects.get(id = id).user_id
else:
return False
def document_delete(request):
if is_draft_owner(request.POST['id'], request.user):
draft = Draft.objects.get(id = request.POST['id'])
draft.delete()
return HttpResponse("done")
This is the view for the page:
@login_required
def posting_draft(request):
user = request.user
user_drafts = Draft.objects.filter(user = user) # Order by date last oppened
drafts = dict()
for d in user_drafts:
drafts[d.title] = d.id
alertnum = get_alertnum(user)
return render_to_response('Posting/Pages/posting_draft.html', {'STATIC_URL':STATIC_URL, 'draft_l' : drafts, 'selected':"dr", 'alertnum': alertnum})
Somehow, when I don't call "is_draft_owner", everything works. When I do call it, I get this:
[12/Aug/2012 00:53:45] "GET /posting/drafts HTTP/1.1" 200 2783
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 86, in run
self.finish_response()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 127, in finish_response
self.write(data)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 210, in write
self.send_headers()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 268, in send_headers
self.send_preamble()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 192, in send_preamble
'Date: %s\r\n' % format_date_time(time.time())
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 324, in write
self.flush()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 49948)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 582, in process_request_thread
self.finish_request(request, client_address)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/core/servers/basehttp.py", line 139, in __init__
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 640, in __init__
self.finish()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 693, in finish
self.wfile.flush()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
----------------------------------------
and, Just in case, the javascript file that uses this code:
function delete_draft(id, name) {
var text = 'Are you sure you want to delete "' + name + '"?';
var confirm = noty({
text: text,
layout: 'center',
type: 'confirm',
modal: true,
buttons: [
{addClass: 'btn btn-danger', text: 'Cancel', onClick: function($noty) {
$noty.close();
}
},
{addClass: 'btn btn-primary', text: 'Delete', onClick: function($noty) {
$.post('/ajax/drafts/delete', {id:id}, function(data) {
document.location.reload(true);
});
document.location.reload(true);
}
}
]});
}
I think, but don't know, that the page is calling the delete document fine, but then breaking on the reload. This seems to make sense from the logs when I'm using google chrome (because when I reload again, it's been deleted), but is not true for Firefox, it seems. I am running development server, but these problems persist and I can't put them off (Some people say this is a problem with the dev server, but I can't even develop when it's like this).