Exemplo n.º 1
0
def post_message(request, chat_id):
    chat = get_object_or_404(Chat, id=chat_id)
    last_message_id = request.POST.get('last_message_id')
    message_form = ChatMessageForm(request.POST or None)
    if message_form.is_valid():
        message = message_form.save(commit=False)
        message.chat = chat
        message.agent = request.user
        message.name = message.get_name()
        message.save()
    if request.is_ajax():
        if last_message_id:
            new_messages = chat.messages.filter(id__gt=last_message_id)
        else:
            new_messages = chat.messages.all()
        new_message_list = []
        for message in new_messages:
            new_message_list.append({
                'name': escape(message.name),
                'message': escape(message.message),
                'pk': message.pk,
                'chat': chat.id,
            })
        return HttpResponse(json.dumps(new_message_list))
    return HttpResponseRedirect(request.META['HTTP_REFERER'])
Exemplo n.º 2
0
def client_post_message(request, chat_uuid):
    """
        Post the message from the end user and return a list of any
        new messages based on the last_messag_id specified.
    """
    chat = get_object_or_404(Chat, hash_key=chat_uuid)
    last_message_id = request.POST.get('last_message_id')
    message_form = ChatMessageForm(request.POST or None)
    if message_form.is_valid():
        message = message_form.save(commit=False)
        message.chat = chat
        message.name = chat.name
        message.save()
    if last_message_id:
        new_messages = chat.messages.filter(id__gt=last_message_id)
    else:
        new_messages = chat.messages.all()
    new_message_list = []
    for message in new_messages:
        new_message_list.append({
            'name': escape(message.name),
            'message': escape(message.message),
            'pk': message.pk,
            'chat': chat.id,
        })
    return HttpResponse(json.dumps(new_message_list))
Exemplo n.º 3
0
def post_message(request, chat_id):
    chat = get_object_or_404(Chat, id=chat_id)
    last_message_id = request.POST.get('last_message_id')
    message_form = ChatMessageForm(request.POST or None)
    if message_form.is_valid():
        message = message_form.save(commit=False)
        message.chat = chat
        message.agent = request.user
        message.name = message.get_name()
        message.save()
    if request.is_ajax():
        if last_message_id:
            new_messages = chat.messages.filter(id__gt=last_message_id)
        else:
            new_messages = chat.messages.all()
        new_message_list = []
        for message in new_messages:
            new_message_list.append({
                'name': escape(message.name),
                'message': escape(message.message),
                'pk': message.pk,
                'chat': chat.id,
            })
        return HttpResponse(json.dumps(new_message_list))
    return HttpResponseRedirect(request.META['HTTP_REFERER'])
Exemplo n.º 4
0
def client_post_message(request, chat_uuid):
    """
        Post the message from the end user and return a list of any
        new messages based on the last_messag_id specified.
    """
    chat = get_object_or_404(Chat, hash_key=chat_uuid)
    last_message_id = request.POST.get('last_message_id')
    message_form = ChatMessageForm(request.POST or None)
    if message_form.is_valid():
        message = message_form.save(commit=False)
        message.chat = chat
        message.name = chat.name
        message.save()
    if last_message_id:
        new_messages = chat.messages.filter(id__gt=last_message_id)
    else:
        new_messages = chat.messages.all()
    new_message_list = []
    for message in new_messages:
        new_message_list.append({
            'name': escape(message.name),
            'message': escape(message.message),
            'pk': message.pk,
            'chat': chat.id,
        })
    return HttpResponse(json.dumps(new_message_list))
Exemplo n.º 5
0
def client_chat(request, chat_uuid):
    chat = get_object_or_404(Chat, hash_key=chat_uuid)
    message_form = ChatMessageForm(request.POST or None)
    if message_form.is_valid():
        message = message_form.save(commit=False)
        message.chat = chat
        message.name = chat.name
        message.save()
        message_form = ChatMessageForm()

    params = {
        'chat': chat,
        'message_form': message_form,
    }
    return render_to_response('live_support/live_support.html', params, context_instance=RequestContext(request))
Exemplo n.º 6
0
def client_chat(request, chat_uuid, talkto):
    chat = get_object_or_404(Chat, hash_key=chat_uuid)
    message_form = ChatMessageForm(request.POST or None)
    if message_form.is_valid():
        message = message_form.save(commit=False)
        message.chat = chat
        message.name = chat.name
        message.save()
        message_form = ChatMessageForm()

    params = {'chat': chat, 'message_form': message_form, 'talkto': talkto}
    return render_to_response('live_support/chat_dedail.html',
                              params,
                              context_instance=RequestContext(request))