예제 #1
0
def store_message(request):
    if request.method == 'POST':
        form = messagesForm(request.POST)
        name = request.user.username

        if (form.is_valid()):
            cd = form.cleaned_data
            if User.objects.filter(username=cd['messageTo']).count():
                wd = clientMessages(messageFrom=name,
                                    messageTo=cd['messageTo'],
                                    driverMessage=cd['driverMessage'])
                wd.save()
                print(name, "Sent message.")
                return HttpResponseRedirect(
                    '/messanger/')  # Redirect after POST
            else:
                print(name + "attempted to send message but no user exists...")
                return HttpResponseRedirect(
                    '/message_error/'
                )  # Redirect after POST if no user exists to send message to
        else:
            print(name + " form not filled...")
            return HttpResponseRedirect(
                '/messanger/')  # Redirect after POST, if form isnt valid
    print("failed to save message render profile")
    return render(request, 'profile.html')
예제 #2
0
def create_message(request):
    form = messagesForm()

    term = request.user.username
    if not term:
        return render_to_response('store_message.html', {'error': True})
    data = clientMessages.objects.filter(messageTo=term).order_by('-time')

    return render(request, 'store_message.html', {
        'form': form,
        'term': term,
        'mdata': data
    })
예제 #3
0
def store_message(request):
    if request.method == 'POST':
        form = messagesForm(request.POST)
        name = request.user.username

        if (form.is_valid()):
            cd = form.cleaned_data
            wd = clientMessages(messageFrom=name,
                                messageTo=cd['messageTo'],
                                driverMessage=cd['driverMessage'])
            wd.save()
            print(name, "Sent message.")
            return HttpResponseRedirect('/messanger/')  # Redirect after POST
        else:
            return render(request, 'store_message.html', {'form': form})
    return render(request, 'profile.html')
예제 #4
0
def create_message(request):
    form = messagesForm()

    term = request.user.username
    if not term:
        return render(
            request, 'store_message.html', {
                'form': form,
                'term': term,
                'mdata': data,
                'error': True,
                'msg': 'No match found for...'
            })

        data = clientMessages.objects.filter(messageTo=term).order_by('-time')

    return render(request, 'store_message.html', {
        'form': form,
        'term': term,
        'mdata': data
    })