def create_post(self, user, post_type, days=3):
     # Create a post.
     title = "Post 1, title needs to be sufficiently long"
     content = ('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod'
                'tempor incididunt ut labore et dolore magna aliqua.')
     tag_val = 'tag_val'
     post = Post(title=title, content=content, tag_val=tag_val, author=user, type=post_type, )
     post.save()
     post.creation_date = datetime.today() - timedelta(days=days)
     post.save()
     return post
Beispiel #2
0
 def create_post(self, post_type, parent=None, days=3):
     # Create a post.
     title = "Post 1, title needs to be sufficiently long"
     content = (
         'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod'
         'tempor incididunt ut labore et dolore magna aliqua.')
     tag_val = 'tag_val'
     post = Post(title=title,
                 content=content,
                 tag_val=tag_val,
                 author=self.user,
                 type=post_type,
                 parent=parent)
     #post.save()
     post.creation_date = datetime.today() - timedelta(days=days)
     post.save()
     return post
def get_post(row, users):
    uid = get(row, 'id', func=int)
    root_id = get(row, 'root_id', func=int)
    parent_id = get(row, 'parent_id', func=int)

    title = get(row, 'title').title()
    tag_val = get(row, 'tag_val').strip()

    author_id = get(row, 'author_id', func=int)
    author = users.get(author_id)

    if not author:
        print("*** author %s not found for post %s" % (author_id, uid))
        return None

    post_type = get(row, 'post_type')
    post_type = POST_TYPE_MAP.get(post_type, Post.FORUM)
    post_status = Post.OPEN if get(row,
                                   'post_status') == "Open" else Post.CLOSED

    post = Post(id=uid,
                title=title,
                author=author,
                lastedit_user=author,
                parent_id=parent_id,
                root_id=root_id)

    post.status = post_status
    post.type = post_type
    post.tag_val = ",".join(tag_val.split())
    post.creation_date = localize_time(get(row, 'creation_date'))
    post.lastedit_date = localize_time(get(row, 'lastedit_date'))
    post.view_count = get(row, "views", func=int)
    post.reply_count = get(row, "answer_count", func=int)
    post.book_count = get(row, "book_count", func=int)
    post.thread_score = get(row, "full_score", func=int)
    post.vote_count = get(row, "score", func=int)

    post_file = path_join(MIGRATE_DIR, 'posts', str(uid))
    post.content = file(post_file, 'rt').read()

    return post
def get_post(row, users):
    uid = get(row, 'id', func=int)
    root_id = get(row, 'root_id', func=int)
    parent_id = get(row, 'parent_id', func=int)

    title = get(row, 'title').title()
    tag_val = get(row, 'tag_val').strip()

    author_id = get(row, 'author_id', func=int)
    author = users.get(author_id)

    if not author:
        print("*** author %s not found for post %s" % (author_id, uid))
        return None

    post_type = get(row, 'post_type')
    post_type = POST_TYPE_MAP.get(post_type, Post.FORUM)
    post_status = Post.OPEN if get(row, 'post_status') == "Open" else Post.CLOSED

    post = Post(id=uid, title=title, author=author, lastedit_user=author,
                parent_id=parent_id, root_id=root_id)

    post.status = post_status
    post.type = post_type
    post.tag_val = ",".join(tag_val.split())
    post.creation_date = localize_time(get(row, 'creation_date'))
    post.lastedit_date = localize_time(get(row, 'lastedit_date'))
    post.view_count = get(row, "views", func=int)
    post.reply_count = get(row, "answer_count", func=int)
    post.book_count = get(row, "book_count", func=int)
    post.thread_score = get(row, "full_score", func=int)
    post.vote_count = get(row, "score", func=int)

    post_file = path_join(MIGRATE_DIR, 'posts', str(uid))
    post.content = file(post_file, 'rt').read()

    return post