def add_thread_and_post(user_id, forum, thread_title, post_body): result = enki.libutil.ENKILIB_OK if user_id and forum and thread_title and post_body: if len(thread_title) <= THREAD_TITLE_LENGTH_MAX and len( post_body) <= POST_LENGTH_MAX: if enki.libdisplayname.get_EnkiUserDisplayName_by_user_id_current( user_id): thread = EnkiModelThread(author=user_id, forum=int(forum), title=thread_title, num_posts=1) thread.put() post = EnkiModelPost(author=user_id, body=post_body, thread=thread.key.id()) post.put() forum_selected = ndb.Key(EnkiModelForum, int(forum)).get() forum_selected.num_posts += 1 forum_selected.num_threads += 1 forum_selected.put() else: result = ERROR_POST_CREATION else: result = ERROR_POST_LENGTH else: result = ERROR_POST_CREATION return result
def add_post(user_id, thread, post_body): result = enki.libutil.ENKILIB_OK if user_id and thread and post_body: if len(post_body) <= POST_LENGTH_MAX: post = EnkiModelPost(author=user_id, thread=int(thread), body=post_body) post.put() thread_selected = ndb.Key(EnkiModelThread, int(thread)).get() thread_selected.num_posts += 1 thread_selected.put() forum_selected = ndb.Key(EnkiModelForum, thread_selected.forum).get() forum_selected.num_posts += 1 forum_selected.put() else: result = ERROR_POST_LENGTH else: result = ERROR_POST_CREATION return result