Exemplo n.º 1
0
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))
Exemplo n.º 2
0
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
Exemplo n.º 3
0
def add_post(g_id, author_name, author_email, post_subject, post_body, image):
    p = Post(post_id=g_id, author_name=author_name, author_email=author_email, post_subject=post_subject,
             post_body=post_body, image=image)
    p.save()
    gid = GlobalId(global_id=g_id)
    gid.save()
    return 0
Exemplo n.º 4
0
def ShowPostForm(request):
    if request.method == 'POST':
        form = PostForm(request.POST, request.FILES)
        if form.is_valid():
            g_id = GetLastGet()
            g_id += 1
            username = request.POST["username"]
            author_name = username
            author_email = User.objects.get(username=username).email
            post_subject = form.cleaned_data['post_subject']
            post_body = form.cleaned_data['post_body']
            image = form.cleaned_data['image']

            p = Post(post_id=g_id, author_name=author_name, author_email=author_email, post_subject=post_subject,
                     post_body=post_body, image=image)
            p.save()
            gid = GlobalId(global_id=g_id)
            gid.save()
            # ret = add_post.delay(g_id, author_name, author_email, post_subject, post_body, image)
            print "async add_post\n"
            print ret.get()
            return HttpResponseRedirect('')
    else:
        form = PostForm()
    print "trolololo\n"
    x = mul.apply_async((2, 2))

    print x.get()
    post_list = Post.objects.all().order_by('post_id')
    paginator = Paginator(post_list.reverse(), 5)
    page = request.GET.get('page')
    try:
        posts = paginator.page(page)
    except PageNotAnInteger:
        posts = paginator.page(1)
    except EmptyPage:
        posts = paginator.page(paginator.num_pages)
    return render_to_response('b.html', {
        'form': form,
        'post_list': post_list,
        'posts': posts,
    }, context_instance=RequestContext(request))