Example #1
0
def follower_stream(request):
    context = dict()
    context['page_name'] = "Follower Stream"
    p = get_object_or_404(Profile, profile_user = request.user)

    if request.method == "POST":
        # create post
        new_post = Post()
        new_post_form = PostForm(request.POST, instance=new_post)
        new_post.post_date_time = timezone.now()
        new_post.post_profile = p

        if not new_post_form.is_valid():
            context['post_form'] = new_post_form
            return render(request, 'socialnetwork/follower_stream.html', context)

        new_post_form.save()
        context['message'] = "Post created"
    

    # display all posts
    context['post_form'] = PostForm()
    all_posts = Post.objects.order_by('post_date_time').reverse()
    # context['all_posts'] = all_posts.filter(post_profile__in = p.following.all())
    return render(request, 'socialnetwork/global_stream.html', context)
Example #2
0
def create_post(request):
    post = Post(user=request.user)
    postForm = PostForm(request.POST, instance=post)
    if not postForm.is_valid():
        context = {'form': postForm}
        return render(request, 'socialnetwork/global.html', context)

    post.post_text = postForm.cleaned_data['post_input_text']
    post.post_date_time = timezone.now()

    post.post_profile = Profile(user=request.user)
    postForm.save()
    context = {
        'form': PostForm(),
        'posts': reversed(Post.objects.all().order_by('post_date_time'))
    }
    return render(request, 'socialnetwork/global.html', context)