def ShowReplyForm(request): if request.method == 'POST': form = ReplyForm(request.POST, request.FILES) param = request.GET.get('to', '') if form.is_valid(): g_id = GetLastGet() g_id += 1 username = request.POST["username"] reply_name = username reply_email = User.objects.get(username=username).email reply_body = form.cleaned_data['reply_body'] image = form.cleaned_data['image'] p = Reply(reply_id=g_id, op_post_id=param, reply_name=reply_name, reply_email=reply_email, reply_body=reply_body, image=image) p.save() gid = GlobalId(global_id=g_id) gid.save() # ret = add_reply.delay(g_id, param, reply_name, reply_email, reply_body, image) print "async add_reply\n" print ret.get() return HttpResponseRedirect('') if request.method == 'GET': form = ReplyForm param = request.GET.get('to', '') p = Post.objects.get(post_id=param) r = Reply.objects.filter(op_post_id=param).order_by('-reply_id') return render_to_response('reply.html', { 'param': param, 'form': form, 'p': p, 'r': r, }, context_instance=RequestContext(request))
def add_reply(g_id, param, reply_name, reply_email, reply_body, image): p = Reply(reply_id=g_id, op_post_id=param, reply_name=reply_name, reply_email=reply_email, reply_body=reply_body, image=image) p.save() gid = GlobalId(global_id=g_id) gid.save() return 0