Exemplo n.º 1
0
def reply(request):
	sent_from = request.user
	#sent with ajax request
	if request.method == 'POST' and request.is_ajax():
		new_message = MessageForm(request.POST)
		id = request.POST.get('name')
		#gets the message that this one is replying to
		old_message = Message.objects.get(id=id)
		#the old message's 'from' becomes this message's 'to'
		send_to = old_message.sent_from
		if new_message.is_valid():
			subject = new_message.cleaned_data['subject']
			message = new_message.cleaned_data['message']
			new_msg = Message(send_to=send_to, sent_from=sent_from, subject=subject, message=message, is_sent=True)
			#indicates which message this one is replying to
			new_msg.is_reply = old_message
			new_msg.save()
			return HttpResponse('sent')
	return HttpResponse('...')