def send_message(request): """AJAX Functional view to recieve just the minimum information, process and create the new message and return the new data to be attached to the conversation stream.""" sender = request.user recipient_username = request.POST.get("to") recipient = get_user_model().objects.get(username=recipient_username) message = request.POST.get("message") if len(message.strip()) == 0: return HttpResponse() if sender != recipient: msg = Message.send_message(sender, recipient, message) return render(request, "messager/single_message.html", {"message": msg}) return HttpResponse()
def send_message(request): """AJAX Functional view to recieve just the minimum information, process and create the new message and return the new data to be attached to the conversation stream.""" sender = request.user recipient_username = request.POST.get('to') recipient = get_user_model().objects.get(username=recipient_username) message = request.POST.get('message') if len(message.strip()) == 0: return HttpResponse() if sender != recipient: msg = Message.send_message(sender, recipient, message) return render(request, 'messager/single_message.html', {'message': msg}) return HttpResponse()
def send_message(request): """AJAX Functional view to recieve just the minimum information, process and create the new message and return the new data to be attached to the conversation stream.""" if request.method == 'POST': sender = request.user recipient_username = request.POST.get('to') recipient = get_user_model().objects.get(username=recipient_username) message = request.POST.get('message') if len(message.strip()) == 0: return HttpResponse() if sender != recipient: msg = Message.send_message(sender, recipient, message) return render(request, 'messager/single_message.html', {'message': msg}) return HttpResponse() else: return HttpResponseBadRequest()
def test_sending_new_message(self): initial_count = Message.objects.count() Message.send_message(self.other_user, self.user, "A follow up answer message.") assert Message.objects.count() == initial_count + 1
def test_sending_new_message(self): initial_count = Message.objects.count() Message.send_message( self.other_user, self.user, "A follow up answer message." ) assert Message.objects.count() == initial_count + 1