Exemplo n.º 1
0
 def add_thread_and_post(cls, user_id, forum, thread_title,
                         thread_sticky_order, post_body, post_sticky_order):
     result = enki.libutil.ENKILIB_OK
     if user_id and forum and thread_title and post_body:
         if len(thread_title
                ) <= EnkiModelThread.THREAD_TITLE_LENGTH_MAX and len(
                    post_body) <= cls.POST_LENGTH_MAX:
             if EnkiModelDisplayName.get_by_user_id_current(user_id):
                 thread = EnkiModelThread(
                     author=user_id,
                     forum=int(forum),
                     title=thread_title,
                     num_posts=1,
                     sticky_order=int(thread_sticky_order))
                 thread.put()
                 post = cls(author=user_id,
                            body=post_body,
                            thread=thread.key.id(),
                            sticky_order=int(post_sticky_order))
                 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 = cls.ERROR_POST_CREATION
         else:
             result = cls.ERROR_POST_LENGTH
     else:
         result = cls.ERROR_POST_CREATION
     return result
Exemplo n.º 2
0
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