def create_post(thread, tiki_post): """Create a post in `thread` from a Tiki post.""" author = get_django_user(tiki_post) created = datetime.fromtimestamp(tiki_post.commentDate) post_content = converter.convert(tiki_post.data) return Post.objects.create( thread=thread, author=author, content=post_content, created=created, updated=created, updated_by=author)
def create_answer(question, tiki_post, tiki_thread): """Create an answer to a question from a Tiki post.""" creator = get_django_user(tiki_post) created = datetime.fromtimestamp(tiki_post.commentDate) content = converter.convert(tiki_post.data) ans = Answer(question=question, creator=creator, content=content, created=created, updated=created) ans.save(no_update=True, no_notify=True) # don't send a reply notification # Set answer as solution if tiki_post.type == "o" and tiki_thread.type == "o": question.solution = ans return ans
def create_thread(forum, tiki_thread): """ Create a thread in `forum` from a Tiki thread. Keeps the same thread id. Also creates the first post in that thread. """ creator = get_django_user(tiki_thread) created = datetime.fromtimestamp(tiki_thread.commentDate) is_locked = (tiki_thread.type == 'l' or tiki_thread.type == 'a') is_sticky = (tiki_thread.type == 's' or tiki_thread.type == 'a') thread = Thread.objects.create( id=tiki_thread.threadId, title=tiki_thread.title, creator=creator, is_locked=is_locked, is_sticky=is_sticky, forum=forum, created=created) # now create the thread's first post thread.last_post = create_post(thread, tiki_thread) return thread
def create_question(tiki_thread): """ Create a question from a Tiki thread. Keeps the same question id. """ creator = get_django_user(tiki_thread) created = datetime.fromtimestamp(tiki_thread.commentDate) content = converter.convert(tiki_thread.data) is_locked = tiki_thread.type == "l" or tiki_thread.type == "a" question = Question( title=tiki_thread.title, creator=creator, is_locked=is_locked, status=CONFIRMED, confirmation_id="", created=created, updated=created, content=content, ) return question