def get( self ): thread_view_count = enki.modelcounter.get_count( 'views_forum' ) if not EnkiModelForum.exist(): # if no forum topic exists , populate the forums with user-defined groups and topics EnkiModelForum.create_forums() self.render_tmpl( 'forums.html', False, active_menu = 'forums', thread_view_count = thread_view_count, forums_data = EnkiModelForum.get_forums_data())
def get_author_posts(cls, author_selected): # get posts by author to display on their profile. If the author hasn't set a display name, return nothing author_display_name = EnkiModelDisplayName.get_by_user_id_current( int(author_selected)) if author_display_name: forums_url = enki.libutil.get_local_url('forums') author_data = EnkiModelDisplayName.get_user_id_display_name_url( author_display_name) list = cls.fetch_by_author(int(author_selected)) if list: for i, item in enumerate(list): thread = EnkiModelThread.get_by_id(item.thread) forum = EnkiModelForum.get_by_id(thread.forum) item.thread_title = thread.title item.thread_url = enki.libutil.get_local_url( 'thread', {'thread': str(item.thread)}) item.forum_title = forum.title item.forum_group = forum.group item.forum_url = enki.libutil.get_local_url( 'forum', {'forum': str(forum.key.id())}) item.post_page = enki.libutil.get_local_url( 'post', {'post': str(item.key.id())}) item.sticky = True if (item.sticky_order > 0) else False list[i] = item author_posts_data = authorpostsData( forums_url, author_data, list, enki.libutil.markdown_escaped_extras) return author_posts_data
def get_post_data(post_selected): # get a post forums_url = enki.libutil.get_local_url('forums') post = EnkiModelPost.get_by_id(int(post_selected)) post_page = enki.libutil.get_local_url('post', {'post': str(post.key.id())}) thread = EnkiModelThread.get_by_id(post.thread) thread_url = enki.libutil.get_local_url('thread', {'thread': str(thread.key.id())}) forum = EnkiModelForum.get_by_id(thread.forum) forum_url = enki.libutil.get_local_url('forum', {'forum': str(forum.key.id())}) author_data = enki.libdisplayname.get_user_id_display_name_url( enki.libdisplayname.get_EnkiUserDisplayName_by_user_id_current( post.author)) post_data = postData( forums_url, forum, forum_url, thread, thread_url, post, post_page, author_data, markdown2.markdown, ) return post_data
def get_author_posts(author_selected): # MOVED TO LIB # get posts by author to display on their profile. If the author hasn't set a display name, return nothing author_display_name = enki.libdisplayname.get_EnkiUserDisplayName_by_user_id_current( int(author_selected)) if author_display_name: forums_url = enki.libutil.get_local_url('forums') author_data = enki.libdisplayname.get_user_id_display_name_url( author_display_name) list = fetch_EnkiPost_by_author(int(author_selected)) if list: for i, item in enumerate(list): thread = EnkiModelThread.get_by_id(item.thread) forum = EnkiModelForum.get_by_id(thread.forum) item.thread_title = thread.title item.thread_url = enki.libutil.get_local_url( 'thread', {'thread': str(item.thread)}) item.forum_title = forum.title item.forum_group = forum.group item.forum_url = enki.libutil.get_local_url( 'forum', {'forum': str(forum.key.id())}) item.post_page = enki.libutil.get_local_url( 'post', {'post': str(item.key.id())}) list[i] = item author_posts_data = authorpostsData(forums_url, author_data, list, markdown2.markdown) return author_posts_data
def get_thread_data(thread_selected, post_requested=POST_DEFAULT, post_count=POSTS_PER_PAGE): # get posts by thread forums_url = enki.libutil.get_local_url('forums') thread = EnkiModelThread.get_by_id(int(thread_selected)) thread_url = enki.libutil.get_local_url('thread', {'thread': str(thread_selected)}) forum = EnkiModelForum.get_by_id(thread.forum) forum_url = enki.libutil.get_local_url('forum', {'forum': str(forum.key.id())}) if post_requested == POST_LAST: post_requested = thread.num_posts list = fetch_EnkiPost_by_thread(int(thread_selected), offset=(int(post_requested) - 1), limit=int(post_count)) if list: for i, item in enumerate(list): item.author_data = enki.libdisplayname.get_user_id_display_name_url( enki.libdisplayname.get_EnkiUserDisplayName_by_user_id_current( item.author)) item.post_page = enki.libutil.get_local_url( 'post', {'post': str(item.key.id())}) list[i] = item thread_data = threadData(forums_url, forum, forum_url, thread, thread_url, list, markdown2.markdown, thread_selected) return thread_data
def get_thread_data(cls, thread_selected, post_requested=POST_DEFAULT, post_count=POSTS_PER_PAGE): # get posts by thread forums_url = enki.libutil.get_local_url('forums') thread = EnkiModelThread.get_by_id(int(thread_selected)) thread_url = enki.libutil.get_local_url( 'thread', {'thread': str(thread_selected)}) forum = EnkiModelForum.get_by_id(thread.forum) forum_url = enki.libutil.get_local_url('forum', {'forum': str(forum.key.id())}) if post_requested == cls.POST_LAST: post_requested = thread.num_posts list = cls.fetch_by_thread(int(thread_selected), offset=(int(post_requested) - 1), limit=int(post_count)) if list: for i, item in enumerate(list): item.author_data = EnkiModelDisplayName.get_user_id_display_name_url( EnkiModelDisplayName.get_by_user_id_current(item.author)) item.post_page = enki.libutil.get_local_url( 'post', {'post': str(item.key.id())}) item.sticky = True if (item.sticky_order > 0) else False list[i] = item thread_data = threadData(forums_url, forum, forum_url, thread, thread_url, list, enki.libutil.markdown_escaped_extras, thread_selected) return thread_data
def get_post_data ( post_selected ): # get a post forums_url = enki.libutil.get_local_url( 'forums' ) post = EnkiModelPost.get_by_id( int( post_selected )) post_page = enki.libutil.get_local_url( 'post', { 'post': str( post.key.id( ) ) } ) thread = EnkiModelThread.get_by_id( post.thread ) thread_url = enki.libutil.get_local_url( 'thread', { 'thread': str( thread.key.id( ) ) } ) forum = EnkiModelForum.get_by_id( thread.forum ) forum_url = enki.libutil.get_local_url( 'forum', { 'forum': str( forum.key.id( ) ) } ) author_data = enki.libdisplayname.get_user_id_display_name_url( enki.libdisplayname.get_EnkiUserDisplayName_by_user_id_current( post.author ) ) post_data = postData( forums_url, forum, forum_url, thread, thread_url, post, post_page, author_data, markdown2.markdown, ) return post_data
def get( self, forum ): data = '' not_found = '' if forum.isdigit() and EnkiModelForum.get_by_id( int( forum ) ): EnkiModelCounter.increment() data = enki.libforum.get_forum_data( forum ) else: not_found = MSG.FORUM_NOT_EXIST( ) self.render_tmpl( 'forum.html', False, active_menu = 'forums', data = data, not_found = not_found, maxpostlength = enki.libforum.POST_LENGTH_MAX, maxthreadtitlelength = enki.libforum.THREAD_TITLE_LENGTH_MAX )
def get_forum_data( forum_selected ): forums_url = enki.libutil.get_local_url( 'forums' ) forum = EnkiModelForum.get_by_id( int( forum_selected )) num_posts = 0 list = fetch_EnkiThread_by_forum( int( forum_selected )) if list: for i, item in enumerate( list ): num_posts += item.num_posts url = enki.libutil.get_local_url( 'thread', { 'thread': str( item.key.id( ) ) } ) item.url = url item.author_data = enki.libdisplayname.get_user_id_display_name_url( enki.libdisplayname.get_EnkiUserDisplayName_by_user_id_current( item.author ) ) list[ i ] = item forum_data = forumData( forums_url, forum, num_posts, list, markdown2.markdown, forum_selected ) return forum_data
def get( self, forum ): data = '' not_found = '' if forum.isdigit() and EnkiModelForum.get_by_id( int( forum ) ): enki.modelcounter.increment( 'views_forum' ) data = EnkiModelThread.get_forum_data( forum ) else: not_found = MSG.FORUM_NOT_EXIST( ) self.render_tmpl( 'forum.html', False, active_menu = 'forums', data = data, not_found = not_found, maxpostlength = EnkiModelPost.POST_LENGTH_MAX, maxthreadtitlelength = EnkiModelThread.THREAD_TITLE_LENGTH_MAX )
def get_thread_data( thread_selected, post_requested = POST_DEFAULT, post_count = POSTS_PER_PAGE ): # get posts by thread forums_url = enki.libutil.get_local_url( 'forums' ) thread = EnkiModelThread.get_by_id( int( thread_selected )) thread_url = enki.libutil.get_local_url( 'thread', { 'thread': str( thread_selected ) } ) forum = EnkiModelForum.get_by_id( thread.forum ) forum_url = enki.libutil.get_local_url( 'forum', { 'forum': str( forum.key.id( ) ) } ) if post_requested == POST_LAST: post_requested = thread.num_posts list = fetch_EnkiPost_by_thread( int( thread_selected ), offset = (int( post_requested ) - 1), limit = int( post_count ) ) if list: for i, item in enumerate( list ): item.author_data = enki.libdisplayname.get_user_id_display_name_url( enki.libdisplayname.get_EnkiUserDisplayName_by_user_id_current( item.author ) ) item.post_page = enki.libutil.get_local_url( 'post', { 'post': str( item.key.id( ) ) } ) list[ i ] = item thread_data = threadData( forums_url, forum, forum_url, thread, thread_url, list, markdown2.markdown, thread_selected ) return thread_data
def get_forum_data(forum_selected): forums_url = enki.libutil.get_local_url('forums') forum = EnkiModelForum.get_by_id(int(forum_selected)) num_posts = 0 list = fetch_EnkiThread_by_forum(int(forum_selected)) if list: for i, item in enumerate(list): num_posts += item.num_posts url = enki.libutil.get_local_url('thread', {'thread': str(item.key.id())}) item.url = url item.author_data = enki.libdisplayname.get_user_id_display_name_url( enki.libdisplayname.get_EnkiUserDisplayName_by_user_id_current( item.author)) list[i] = item forum_data = forumData(forums_url, forum, num_posts, list, markdown2.markdown, forum_selected) return forum_data
def get_post_data(cls, post_selected): # get a post forums_url = enki.libutil.get_local_url('forums') post = cls.get_by_id(int(post_selected)) sticky = True if (post.sticky_order > 0) else False post_page = enki.libutil.get_local_url('post', {'post': str(post.key.id())}) thread = EnkiModelThread.get_by_id(post.thread) thread_url = enki.libutil.get_local_url( 'thread', {'thread': str(thread.key.id())}) forum = EnkiModelForum.get_by_id(thread.forum) forum_url = enki.libutil.get_local_url('forum', {'forum': str(forum.key.id())}) author_data = EnkiModelDisplayName.get_user_id_display_name_url( EnkiModelDisplayName.get_by_user_id_current(post.author)) post_data = postData(forums_url, forum, forum_url, thread, thread_url, post, sticky, post_page, author_data, enki.libutil.markdown_escaped_extras) return post_data
def get_forum_data(cls, forum_selected): forums_url = enki.libutil.get_local_url('forums') forum = EnkiModelForum.get_by_id(int(forum_selected)) num_posts = 0 threads = cls.fetch_by_forum(int(forum_selected)) if threads: for i, thread in enumerate(threads): num_posts += thread.num_posts url = enki.libutil.get_local_url( 'thread', {'thread': str(thread.key.id())}) thread.url = url thread.author_data = EnkiModelDisplayName.get_user_id_display_name_url( EnkiModelDisplayName.get_by_user_id_current(thread.author)) thread.sticky = True if (thread.sticky_order > 0) else False threads[i] = thread forum_data = forumData(forums_url, forum, num_posts, threads, enki.libutil.markdown_escaped_extras, forum_selected) return forum_data
def get_author_posts( author_selected ): # MOVED TO LIB # get posts by author to display on their profile. If the author hasn't set a display name, return nothing author_display_name = enki.libdisplayname.get_EnkiUserDisplayName_by_user_id_current( int( author_selected ) ) if author_display_name: forums_url = enki.libutil.get_local_url( 'forums' ) author_data = enki.libdisplayname.get_user_id_display_name_url( author_display_name ) list = fetch_EnkiPost_by_author( int( author_selected )) if list: for i, item in enumerate( list ): thread = EnkiModelThread.get_by_id( item.thread ) forum = EnkiModelForum.get_by_id( thread.forum ) item.thread_title = thread.title item.thread_url = enki.libutil.get_local_url( 'thread', { 'thread': str( item.thread ) } ) item.forum_title = forum.title item.forum_group = forum.group item.forum_url = enki.libutil.get_local_url( 'forum', { 'forum': str( forum.key.id( ) ) } ) item.post_page = enki.libutil.get_local_url( 'post', { 'post': str( item.key.id( ) ) } ) list[ i ] = item author_posts_data = authorpostsData( forums_url, author_data, list, markdown2.markdown ) return author_posts_data
def post( self, forum ): if self.ensure_is_logged_in() and enki.libdisplayname.ensure_has_display_name( self ): if forum.isdigit() and EnkiModelForum.get_by_id( int( forum ) ): self.check_CSRF( 'forum' ) user_id = self.user_id thread_title = self.request.get( 'thread_title' ) post_body = self.request.get( 'post_body' ) submit_type = self.request.get( 'submittype' ) error_message_threadtitle = '' error_message_postbody = '' preview_threadtitle = '' preview_post = '' pmtoken = self.request.get( 'preventmultitoken' ) show_input = True if submit_type == 'input': thread_title = '' post_body = '' pmtoken = enki.libforum.add_preventmultipost_token( ) else: if submit_type != 'cancel': if not thread_title: error_message_threadtitle = MSG.THREAD_TITLE_NEEDED( ) else: exceed = len( thread_title ) - enki.libforum.THREAD_TITLE_LENGTH_MAX if exceed > 0: error_message_threadtitle = MSG.THREAD_TITLE_TOO_LONG( exceed ) if not post_body: error_message_postbody = MSG.POST_BODY_NEEDED() else: exceed = len( post_body ) - enki.libforum.POST_LENGTH_MAX if exceed > 0: error_message_postbody = MSG.POST_BODY_TOO_LONG( exceed ) if not error_message_threadtitle and not error_message_postbody: if submit_type == 'submit': if enki.libforum.check_and_delete_preventmultipost_token( pmtoken ): result = enki.libforum.add_thread_and_post( user_id, forum, thread_title, post_body ) if result == enki.libutil.ENKILIB_OK: self.add_infomessage( 'success', MSG.SUCCESS( ), MSG.THREAD_PUBLISHED()) thread_title = '' post_body = '' self.redirect( enki.libutil.get_local_url( 'forum', { 'forum': forum })) return else: error_threadtitle = MSG.FAIL_THREAD_SUBMISSION() else: thread_title = '' post_body = '' elif submit_type == 'preview': preview_threadtitle = thread_title preview_post = post_body elif submit_type == 'cancel': thread_title = '' post_body = '' self.render_tmpl( 'forum.html', active_page = 'forums', CSRFtoken = self.create_CSRF( 'forum' ), data = enki.libforum.get_forum_data( forum ), show_input = show_input, preventmultitoken = pmtoken, error_threadtitle = error_message_threadtitle, error_postbody = error_message_postbody, maxpostlength = enki.libforum.POST_LENGTH_MAX, maxthreadtitlelength = enki.libforum.THREAD_TITLE_LENGTH_MAX, threadtitle = thread_title, postbody = post_body, previewthreadtitle = preview_threadtitle, previewpost = preview_post )
def post(self, forum): if self.ensure_is_logged_in() and self.ensure_has_display_name(): if forum.isdigit() and EnkiModelForum.get_by_id(int(forum)): user_id = self.user_id thread_title = self.request.get('thread_title') post_body = self.request.get('post_body') submit_type = self.request.get('submittype') error_message_threadtitle = '' error_message_postbody = '' preview_threadtitle = '' preview_post = '' pmtoken = self.request.get('preventmultitoken') show_input = True if submit_type == 'input': thread_title = '' post_body = '' pmtoken = enki.libforum.add_preventmultipost_token() else: self.check_CSRF() if submit_type != 'cancel': if not thread_title: error_message_threadtitle = MSG.THREAD_TITLE_NEEDED( ) else: exceed = len( thread_title ) - enki.libforum.THREAD_TITLE_LENGTH_MAX if exceed > 0: error_message_threadtitle = MSG.THREAD_TITLE_TOO_LONG( exceed) if not post_body: error_message_postbody = MSG.POST_BODY_NEEDED() else: exceed = len( post_body) - enki.libforum.POST_LENGTH_MAX if exceed > 0: error_message_postbody = MSG.POST_BODY_TOO_LONG( exceed) if not error_message_threadtitle and not error_message_postbody: if submit_type == 'submit': if enki.libforum.check_and_delete_preventmultipost_token( pmtoken): result = enki.libforum.add_thread_and_post( user_id, forum, thread_title, post_body) if result == enki.libutil.ENKILIB_OK: self.add_infomessage( 'success', MSG.SUCCESS(), MSG.THREAD_PUBLISHED()) thread_title = '' post_body = '' self.redirect( enki.libutil.get_local_url( 'forum', {'forum': forum})) return else: error_threadtitle = MSG.FAIL_THREAD_SUBMISSION( ) else: thread_title = '' post_body = '' elif submit_type == 'preview': preview_threadtitle = thread_title preview_post = post_body elif submit_type == 'cancel': thread_title = '' post_body = '' self.render_tmpl( 'forum.html', CSRFneeded=show_input, active_menu='forums', data=enki.libforum.get_forum_data(forum), show_input=show_input, preventmultitoken=pmtoken, error_threadtitle=error_message_threadtitle, error_postbody=error_message_postbody, maxpostlength=enki.libforum.POST_LENGTH_MAX, maxthreadtitlelength=enki.libforum.THREAD_TITLE_LENGTH_MAX, threadtitle=thread_title, postbody=post_body, previewthreadtitle=preview_threadtitle, previewpost=preview_post)
def post( self, forum ): if self.ensure_is_logged_in() and self.ensure_has_display_name(): if forum.isdigit() and EnkiModelForum.get_by_id( int( forum )): user_id = self.user_id thread_title = self.request.get( 'thread_title' ) post_body = self.request.get( 'post_body' ) thread_sticky_order = xint( self.request.get( 'sticky_order_thread' )) post_sticky_order = xint( self.request.get( 'sticky_order_post' )) submit_type = self.request.get( 'submittype' ) error_message_threadtitle = '' error_message_postbody = '' pmtoken = self.request.get( 'preventmultitoken' ) show_input = True if submit_type == 'cancel' or submit_type == 'input': thread_title = '' post_body = '' thread_sticky_order = 0 post_sticky_order = 0 if submit_type == 'input': pmtoken = EnkiModelTokenVerify.add_preventmultipost_token( 'preventmultipost' ) else: self.check_CSRF() if not thread_title: error_message_threadtitle = MSG.THREAD_TITLE_NEEDED( ) else: exceed = len( thread_title ) - EnkiModelThread.THREAD_TITLE_LENGTH_MAX if exceed > 0: error_message_threadtitle = MSG.THREAD_TITLE_TOO_LONG( exceed ) if not post_body: error_message_postbody = MSG.POST_BODY_NEEDED() else: exceed = len( post_body ) - EnkiModelPost.POST_LENGTH_MAX if exceed > 0: error_message_postbody = MSG.POST_BODY_TOO_LONG( exceed ) if not error_message_threadtitle and not error_message_postbody: if submit_type == 'submit': if EnkiModelTokenVerify.check_and_delete_preventmultipost_token( pmtoken, 'preventmultipost' ): result = EnkiModelPost.add_thread_and_post( user_id, forum, thread_title, thread_sticky_order, post_body, post_sticky_order ) if result == enki.libutil.ENKILIB_OK: self.add_infomessage( MSG.SUCCESS( ), MSG.THREAD_PUBLISHED()) url = enki.libutil.get_local_url( 'forum', { 'forum':forum }) self.send_email_admin( 'FTPA', url ) self.redirect( url ) return else: error_threadtitle = MSG.FAIL_THREAD_SUBMISSION() else: thread_title = '' post_body = '' self.render_tmpl( 'forum.html', CSRFneeded = show_input, active_menu = 'forums', data = EnkiModelThread.get_forum_data( forum ), has_permission_sticky = self.has_permissions( self.enki_user, [ 'PFPS', 'PFTS' ]), show_input = show_input, preventmultitoken = pmtoken, error_threadtitle = error_message_threadtitle, error_postbody = error_message_postbody, maxpostlength = EnkiModelPost.POST_LENGTH_MAX, maxthreadtitlelength = EnkiModelThread.THREAD_TITLE_LENGTH_MAX, threadtitle = thread_title, postbody = post_body, threadstickyorder = thread_sticky_order, poststickyorder = post_sticky_order, preview = True if ( submit_type == 'preview' and thread_title and post_body ) else False)
def exist_EnkiForums(): count = EnkiModelForum.query().count(1) return count > 0
def fetch_EnkiForum_by_group( group ): list = EnkiModelForum.query( EnkiModelForum.group == group ).order( EnkiModelForum.order ).fetch() return list
def exist_EnkiForums(): count = EnkiModelForum.query().count( 1 ) return count > 0
def fetch_EnkiForum_by_group(group): list = EnkiModelForum.query(EnkiModelForum.group == group).order( EnkiModelForum.order).fetch() return list
def exist_EnkiForums(): count = EnkiModelForum.query().count( 1 ) if count: return True else: return False