Пример #1
0
def send_message2(request):
    #print request
    if request.method=="POST":
        if request.GET.has_key("username"):
            username=request.GET['username']
            to_user=User.objects.get(username=username)
            from_user=request.user
            content=request.POST["content"]
            content=content.strip()
            message=Message(content=content,from_user=from_user,to_user=to_user)
            message.save()
            
            if request.META.has_key("HTTP_REFERER") :
                return HttpResponseRedirect(request.META["HTTP_REFERER"])
            
            return HttpResponseRedirect("/user/"+from_user.username)
            
            
    
    variables=RequestContext(request,{})
    return render_to_response("message_form.html",variables)
Пример #2
0
def send_message(request):
    from_user=request.user
    
    if request.method=="POST":
        form = MessageForm(request.POST)
        if form.is_valid():
            
                to_user=form.cleaned_data['to_user']
            
               
        
                message=Message(content=form.cleaned_data['content'],from_user=from_user,to_user=to_user)
                
                message.save()
                return HttpResponseRedirect("/")
    
    else :
        form=MessageForm({"from_user":from_user.username})
    
    variables=RequestContext(request,{'form':form,'user':request.user})
    
    return render_to_response("message.html",variables)