Example #1
0
def post_listing(request):

    if request.method == 'POST':
        new_post = request.POST.get('new_post')
        if new_post:
            post = Post()
            post.message = new_post
            post.created_datetime = timezone.now()
            post.created_by = request.user
            post.save()

    posts = Post.objects.all()
    #posts = Post.objects.filter().order_by('-likes')
    page = request.GET.get('page')
    paginator = Paginator(posts, 5)
    try:
        posts = paginator.page(page)
    except PageNotAnInteger:
        posts = paginator.page(1)
    except EmptyPage:
        posts = paginator.page(paginator.num_pages)

    context = {
        'posts': posts,
        }
    return render(request, 'posts/post_listing.html', context)
Example #2
0
    def test_post(self):
        post = Post()
        
        user = User.objects.create_user('Testy McTest', '*****@*****.**', 'testpassword')
        user.save()
        
        group = Group()
        group.name = "Test Group"
        group.save()
        
        membership = Membership()
        membership.user = User.objects.get(id = user.id)
        membership.group = Group.objects.get(id = group.id)
        membership.save()
        
        post.author = Membership.objects.get(id = membership.id)
        post.message = "Testing321"

        post.save()
    
        test_post = Post.objects.get(id = post.id)
        
        self.assertEquals(test_post, post)
        self.assertEquals(test_post.author, Membership.objects.get(id = membership.id))
        self.assertEquals(test_post.message, "Testing321")
   
        post.delete()
        membership.delete()
        group.delete()
        user.delete()