def postreply(request, topicid, threadid): if not request.user.is_authenticated() or not request.user.is_active: return HttpResponseRedirect('/homepage/') lan = setlanguage(request) user = request.user username = user.username userprofile = UserProfile.objects.get(user=user) if lan == 'en': form = ForumSearchForm_en if lan == 'cn': form = ForumSearchForm_cn form_post = ReplyPostForm() state = [] allcategory = ThreadCategory.objects.all().order_by('pid') displayed_topic = Thread.objects.get(id=topicid) displayed_thread = ThreadContent.objects.get(id=threadid) if request.method == 'POST': form_post = ReplyPostForm(request.POST) if form_post.is_valid(): # if lan == 'en': # state.append('Successfully Posted!') # if lan == 'cn': # state.append('成功送出!') cd = form_post.cleaned_data thread = Reply.objects.create(following_thread=displayed_topic, # following_reply=displayed_thread, Content=cd['content'], posted_by=userprofile, posted_on=datetime.datetime.now(), ) displayed_topic.reply_number = displayed_topic.reply_number+1 displayed_topic.update_on=datetime.datetime.now() displayed_topic.update_by=userprofile displayed_topic.save() url = '/discussion/thread/'+threadid+'/' return HttpResponseRedirect(url) return render_to_response('discussion_postreplyview.html',{'allcategory':allcategory, 'displayed_topic':displayed_topic, 'displayed_thread':displayed_thread, 'state':state, 'lan':lan, 'form':form, 'form_post':form_post}, RequestContext(request))