def add_post(request): args = {} args['user'] = get_object_or_404(ourUser,id=request.user.id) form = post_form() if request.POST: form = post_form(request.POST) if form.is_valid(): #tie the post to the wall and define the user for the post user = get_object_or_404(ourUser, username=request.user.username) community_wall = list(communityWall.objects.filter(community=user.community).exclude(wall_name="deleted")) #makes a post object with commit=false to allow for editing #setting attributes post = form.save(commit=False) args = post.post_handler(community_wall[0], user) return HttpResponseRedirect('/user/home/') else: #if there is an error, asks user to fix it args = {} args.update(csrf(request)) args['form'] = form args['error'] = 1 return render_to_response('add_post.html', args) else: args.update(csrf(request)) args['form'] = form return render_to_response('add_post.html', args)
def home_view(request): args = {} args['user'] = get_object_or_404(ourUser,id=request.user.id) if request.POST: form = post_form(request.POST) if form.is_valid(): #tie the post to the wall and define the user for the post user = get_object_or_404(ourUser, username=request.user.username) community_wall = list(communityWall.objects.filter(community=user.community).exclude(wall_name="deleted")) #makes a post object with commit=false to allow for editing #setting attributes post = form.save(commit=False) args = post.post_handler(community_wall[0], user) return HttpResponseRedirect('/user/home/') else: #if there is an error, asks user to fix it return HttpResponseRedirect('/user/home/') else: args.update(csrf(request)) args['form'] = post_form(request.POST) #get ourUser from the request user = ourUser.objects.get(username=request.user.username) order_by = request.GET.get('order_by') if order_by: community_tools = Tool.objects.filter(community=user.community).filter(is_active=True).order_by(order_by)[:5] else: community_tools = Tool.objects.filter(community=user.community).filter(is_active=True)[:5] has_tools = bool(community_tools) args['user'] = user args['tools'] = community_tools args['has_tools'] = has_tools community = user.community args['comm'] = community #get posts user_community = user.community community_wall = communityWall.objects.filter(community=user_community).exclude(wall_name="deleted") args['posts'] = Post.objects.filter(wall=community_wall).order_by('-timestamp_post') return render(request,'home.html',args)