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
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))
def post(self, request, blog_id=None, post_id=None): content = request.POST.get("content", "") name = request.POST.get("name", "") # Validation functions for POST data, fail with an HTTP400 if not name or not content or post_id: return HttpResponse(status=400) # Error handling for server errors try: # Identify the blog from passed in blog ID b = BlogModel.objects.get(id=blog_id) # Create a new post and save it p = PostModel(blog=b, content=content, name=name) p.save() except Exception as e: # Return HTTP500 on server error return HttpResponse(status=500) # Return HTTP200 return (HttpResponse())