Beispiel #1
0
def edit_message(request, message_id):
    message = Message.objects.get(id = message_id)
    if request.method=='GET':
        data = {
                'form' : MessageForm (instance = message),
                'user' : request.user,
        }
        data.update(csrf(request))
        return render_to_response('standard_form.html', data)
    elif request.method=='POST':
        message_form = MessageForm(request.POST, instance = message)
        data = {
                'form' : message_form,
                'user' : request.user,
        }
        data.update(csrf(request))
        if message_form.is_valid():
            message_form.save()
            return redirect('my_messages')
        else:
            return render_to_response('standard_form.html', data)
Beispiel #2
0
def edit_message(request, message_id):
    message = Message.objects.get(id=message_id)
    if request.method == 'GET':
        data = {
            'form': MessageForm(instance=message),
            'user': request.user,
        }
        data.update(csrf(request))
        return render_to_response('standard_form.html', data)
    elif request.method == 'POST':
        message_form = MessageForm(request.POST, instance=message)
        data = {
            'form': message_form,
            'user': request.user,
        }
        data.update(csrf(request))
        if message_form.is_valid():
            message_form.save()
            return redirect('my_messages')
        else:
            return render_to_response('standard_form.html', data)
Beispiel #3
0
def new_message(request):
    if request.method == 'GET':
        data = {
                'form' : MessageForm,
                'user' : request.user,
        }
        data.update(csrf(request))
        return render_to_response('new_message.html', data)
    else:
        data = {
                'form' : MessageForm(request.POST),
                'user' : request.user,
        }
        data.update(csrf(request))
        f = MessageForm(request.POST)
        # Check to see if form is valid
        if f.is_valid():
            message = f.save(commit=False)
            message.teacher = Teacher.objects.get(user=request.user)
            message.save()
            return redirect('my_messages')
        else:
            return render_to_response('new_message.html', data)
Beispiel #4
0
def new_message(request):
    if request.method == 'GET':
        data = {
            'form': MessageForm,
            'user': request.user,
        }
        data.update(csrf(request))
        return render_to_response('new_message.html', data)
    else:
        data = {
            'form': MessageForm(request.POST),
            'user': request.user,
        }
        data.update(csrf(request))
        f = MessageForm(request.POST)
        # Check to see if form is valid
        if f.is_valid():
            message = f.save(commit=False)
            message.teacher = Teacher.objects.get(user=request.user)
            message.save()
            return redirect('my_messages')
        else:
            return render_to_response('new_message.html', data)