Beispiel #1
0
    def get(self):
        """Retrieve all the latest blog-entries and render them to user."""
        page_to_show = self.request.get("page")
        if page_to_show.isdigit() and int(page_to_show) > 1:
            page_to_show = int(page_to_show)
        else:
            page_to_show = 1

        limit = 5
        offset = (page_to_show - 1) * limit
        totalArticles = BlogEntity.all().count(1000)
        totalPages = int(ceil(float(totalArticles) / limit))
        articles = BlogEntity.all().order('-created').fetch(limit=limit,
                                                            offset=offset)

        self.render("blogs.html",
                    articles=articles,
                    parser=self.render_blog_article,
                    pages=totalPages,
                    currentPage=page_to_show)
Beispiel #2
0
    def test_delete_post(self):
        """delete_post should delete the post and its comments and votes."""
        james = UserEntity.register(username='******', password='******')
        kimmy = UserEntity.register(username='******', password='******')
        dane = UserEntity.register(username='******', password='******')
        joe = UserEntity.register(username='******', password='******')

        a = BlogEntity.create_blog_entry(parent=blog_key(),
                                         title='a',
                                         article='content',
                                         created_by=james)

        b = BlogEntity.create_blog_entry(parent=blog_key(),
                                         title='b',
                                         article='content',
                                         created_by=james)

        a.vote(voteBy=kimmy, voteType='up')
        a.vote(voteBy=dane, voteType='up')
        a.vote(voteBy=joe, voteType='down')
        b.vote(voteBy=kimmy, voteType='up')
        b.vote(voteBy=dane, voteType='up')
        b.vote(voteBy=joe, voteType='down')

        a.add_comment(commentBy=kimmy, comment='abc')
        a.add_comment(commentBy=dane, comment='abc')
        a.add_comment(commentBy=joe, comment='123')
        b.add_comment(commentBy=kimmy, comment='abc')
        b.add_comment(commentBy=dane, comment='abc')
        b.add_comment(commentBy=joe, comment='123')

        a.delete_post(james)
        votes = VotesEntity.all()
        for vote in votes:
            self.assertNotEqual(vote.voteOn.title,
                                'a',
                                msg="Votes of post 'a' should be deleted")
        comments = CommentsEntity.all()
        for comment in comments:
            self.assertNotEqual(comment.commentOn.title,
                                'a',
                                msg="Comments of post 'a' should be deleted")

        bloe_entries = BlogEntity.all()
        for blog_entity in bloe_entries:
            self.assertNotEqual(blog_entity.title,
                                'a',
                                msg="Post 'a' should be deleted")
Beispiel #3
0
            if j > 0:
                if randint(0, 5) == 1:
                    article += "<h4>{}</h4>".format(
                        pick_random_from_list(title_list))
            article += "<p>{}</p>".format(
                pick_random_from_list(article_paragraphgs))
        a = BlogEntity(
            parent=blog_key(),
            created_by=users[randint(0, users.count() - 1)],
            title='{} {}'.format(i, pick_random_from_list(title_list)),
            article=article)
        a.put()


def assign_random_votes(blog_entries, users):
    """Assign random votes to articles."""
    for blog_entry in blog_entries:
        for user in users:
            try:
                blog_entry.vote(voteBy=user,
                                voteType=pick_random_from_list(['up', 'down']))
            except myExceptions.VoteOnOwnPostNotAllowed:
                pass


user_list = UserEntity.all()
blog_entry_list = BlogEntity.all()

dev_create_some_blog_posts(user_list)
assign_random_votes(blog_entry_list, user_list)