コード例 #1
0
ファイル: views.py プロジェクト: bsaif86/bootcamp-1
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()
コード例 #2
0
ファイル: views.py プロジェクト: vitorfs/bootcamp
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()
コード例 #3
0
ファイル: views.py プロジェクト: veritas44/bootcamp
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()
コード例 #4
0
 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
コード例 #5
0
 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