示例#1
0
文件: views.py 项目: kns003/myproject
def edit_comment(request,comment_id):
    comment=Comment.objects.get(pk=comment_id)
    if request.method=='POST':
        form=CommentForm(request.POST)
        if form.is_valid():
            comment.text=form.cleaned_data['text']
            comment.save()
            return HttpResponseRedirect('/thread/%s' % comment.thread.id)
    else:
        form=CommentForm()
        form.fields['text'].initial=comment.text
        
    context=RequestContext(request,{'title':'Edit Comment','form':form})
    return render_to_response('addComment.html',locals())
示例#2
0
文件: views.py 项目: kns003/myproject
def add_comment(request,thread_id):
    #logger.debug('username:'******'username'))
    thread = Thread.objects.get(id=thread_id)
    
    if request.method=='POST':
        form=CommentForm(request.POST)
        
        if form.is_valid():    
            thread=Thread.objects.get(id = thread_id)
            comment = Comment.objects.create(
                commented_by = User.objects.get(pk = request.user.id),
                thread = thread,
                text = form.cleaned_data['text'],
                userUpVotes = 0,
                userDownVotes = 0,
                         )
            return HttpResponseRedirect('/thread/%s/' % thread.id)
    else:
        form=CommentForm()
        
    context_variables = RequestContext(request,{'form':form, 'thread': thread ,'threadname':thread.title})
    return render_to_response('addComment.html', locals())