Beispiel #1
0
def new(request):
    if request.method == 'POST':
        from_user = request.user
        to_user_username = request.POST.get('to')
        try:
            to_user = User.objects.get(username=to_user_username)

        except Exception:
            try:
                to_user_username = to_user_username[
                    to_user_username.rfind('(')+1:len(to_user_username)-1]
                to_user = User.objects.get(username=to_user_username)

            except Exception:
                return redirect('/messages/new/')

        message = request.POST.get('message')
        if len(message.strip()) == 0:
            return redirect('/messages/new/')

        if from_user != to_user:
            Message.send_message(from_user, to_user, message)

        return redirect('/messages/{0}/'.format(to_user_username))

    else:
        conversations = Message.get_conversations(user=request.user)
        return render(request, 'messenger/new.html',
                      {'conversations': conversations})
Beispiel #2
0
def quickMessage(request):
    if request.method == 'POST':
        from_user = request.user
        to_user_username = request.POST.get('to')
        print "from", from_user
        print "to", to_user_username
        try:
            to_user = User.objects.get(username=to_user_username)
 
        except Exception:
            try:
                to_user_username = to_user_username[
                    to_user_username.rfind('(')+1:len(to_user_username)-1]
                to_user = User.objects.get(username=to_user_username)
 
            except Exception:
                messages.add_message(request, messages.ERROR,
                                 'User ' + to_user_username + " could not be found on the system, fatal error. Please contact the Project manager")
                return network(request)
 
        message = request.POST.get('message')
        if len(message.strip()) == 0:
            messages.add_message(request, messages.ERROR,
                                 "Cannot send an empty message")
            return network(request)
 
        if from_user != to_user:
            Message.send_message(from_user, to_user, message)
        messages.add_message(request, messages.SUCCESS,
                                 'Your message has been sent')
        return network(request)

    else:
        return network(request)
Beispiel #3
0
def new(request):
    if request.method == 'POST':
        from_user = request.user
        to_user_username = request.POST.get('to')
        try:
            to_user = User.objects.get(username=to_user_username)

        except Exception:
            try:
                to_user_username = to_user_username[
                    to_user_username.rfind('(')+1:len(to_user_username)-1]
                to_user = User.objects.get(username=to_user_username)

            except Exception:
                return redirect('/messages/new/')

        message = request.POST.get('message')
        if len(message.strip()) == 0:
            return redirect('/messages/new/')

        if from_user != to_user:
            Message.send_message(from_user, to_user, message)

        return redirect('/messages/{0}/'.format(to_user_username))

    else:
        conversations = Message.get_conversations(user=request.user)
        return render(request, 'messenger/new.html',
                      {'conversations': conversations})
Beispiel #4
0
 def test_sending_new_message(self):
     new_message = Message.send_message(
         self.other_user, self.user, "A short message")
     self.assertTrue(isinstance(new_message, Message))
     self.assertEqual(Message.get_conversations(self.other_user)[0]['last'],
                      new_message.date)
     self.assertEqual(new_message.message, "A short message")
Beispiel #5
0
def send(request):
    # 发送消息message
    if request.method == 'POST':
        from_user = request.user
        to_user_username = request.POST.get('to')
        # 根据用户名获取用户
        to_user = User.objects.get(username=to_user_username)
        message = request.POST.get('message')
        if len(message.strip()) == 0:
            return HttpResponse()

        # 收件人不能和发件人一样
        if from_user != to_user:
            # 构造messag,发送
            msg = Message.send_message(from_user, to_user, message)

            # 返回的是一段html渲染好的代码
            return render(request, 'messenger/includes/partial_message.html',
                          {'message': msg})

        return HttpResponse()
    else:
        # 如果是get请求,直接返回bad request
        # 注意这种写法
        return HttpResponseBadRequest()
Beispiel #6
0
def send(request):
    if request.method == 'POST':
        from_user = request.user
        to_user_username = request.POST.get('to')
        to_user = User.objects.get(username=to_user_username)
        message = request.POST.get('message')
        if len(message.strip()) == 0:
            return HttpResponse()
        if from_user != to_user:
            msg = Message.send_message(from_user, to_user, message)
            return render(request, 'messenger/includes/partial_message.html', {'message': msg})
        return HttpResponse()
    else:
        return HttpResponseBadRequest()
Beispiel #7
0
        except Exception, e:
            try:
                to_user_username = to_user_username[
                    to_user_username.rfind('(') + 1:len(to_user_username) - 1]
                to_user = User.objects.get(username=to_user_username)

            except Exception, e:
                return redirect('/messages/new/')

        message = request.POST.get('message')
        if len(message.strip()) == 0:
            return redirect('/messages/new/')

        if from_user != to_user:
            Message.send_message(from_user, to_user, message)

        return redirect(u'/messages/{0}/'.format(to_user_username))

    else:
        conversations = Message.get_conversations(user=request.user)
        return render(request, 'messenger/new.html',
                      {'conversations': conversations})


@login_required
@ajax_required
def delete(request):
    return HttpResponse()

Beispiel #8
0
    if request.method == 'POST':
        from_user = request.user
        to_user_username = request.POST.get('to')
        try:
            to_user = User.objects.get(username=to_user_username)
        except Exception, e:
            try:
                to_user_username = to_user_username[to_user_username.rfind('(')+1:len(to_user_username)-1]
                to_user = User.objects.get(username=to_user_username)
            except Exception, e:
                return redirect('/messages/new/')
        message = request.POST.get('message')
        if len(message.strip()) == 0:
            return redirect('/messages/new/')
        if from_user != to_user:
            Message.send_message(from_user, to_user, message)
        return redirect(u'/messages/{0}/'.format(to_user_username))
    else:
        conversations = Message.get_conversations(user=request.user)
        return render(request, 'messenger/new.html', {'conversations': conversations})

@login_required
@ajax_required
def delete(request):
    return HttpResponse()

@login_required
@ajax_required
def send(request):
    if request.method == 'POST':
        from_user = request.user