def get( self, thread ): data = '' pagination = '' not_found = '' post_requested = str( self.request.get( 'start' )) post_count = str( self.request.get( 'count' )) validation_result = EnkiModelThread.validate_thread_pagination( thread, post_requested, post_count ) if validation_result == enki.libutil.ENKILIB_OK: if not post_requested: post_requested = EnkiModelPost.POST_DEFAULT if not post_count: post_count = EnkiModelPost.POSTS_PER_PAGE data = EnkiModelPost.get_thread_data( thread, post_requested, post_count ) pagination = EnkiModelPost.get_thread_pagination_data( thread, post_requested, post_count ) else: not_found = MSG.POST_THREAD_NOT_EXIST( ) self.render_tmpl( 'thread.html', False, active_menu = 'forums', data = data, pagination = pagination, user_id = self.user_id, not_found = not_found, maxpostlength = EnkiModelPost.POST_LENGTH_MAX )
def post( self, thread ): if self.ensure_is_logged_in() and self.ensure_has_display_name(): if thread.isdigit() and EnkiModelThread.get_by_id( int( thread )): user = self.user_id post_body = self.request.get( 'post_body' ) submit_type = self.request.get( 'submittype' ) post_count = str( self.request.get( 'count' )) post_requested = str( self.request.get( 'start' )) if not post_count: post_count = EnkiModelPost.POSTS_PER_PAGE if not post_requested: post_requested = EnkiModelPost.get_first_post_on_page( EnkiModelPost.get_page( EnkiModelThread.get_by_id( int( thread )), EnkiModelPost.POST_LAST, int( post_count )), int( post_count )) error_message = '' preview = '' pmtoken = self.request.get( 'preventmultitoken' ) show_input = True if submit_type == 'input': post_body = '' pmtoken = EnkiModelTokenVerify.add_preventmultipost_token( 'preventmultipost' ) else: self.check_CSRF() if submit_type != 'cancel': if not post_body: error_message = MSG.POST_BODY_NEEDED() else: exceed = len( post_body ) - EnkiModelPost.POST_LENGTH_MAX if exceed > 0: error_message = MSG.POST_BODY_TOO_LONG( exceed ) if not error_message: post_sticky_order = xint( self.request.get( 'sticky_order' )) if submit_type == 'submit': if EnkiModelTokenVerify.check_and_delete_preventmultipost_token( pmtoken, 'preventmultipost' ): result = EnkiModelPost.add_post( user, thread, post_body, post_sticky_order ) if result == enki.libutil.ENKILIB_OK: self.add_infomessage( MSG.SUCCESS( ), MSG.POST_PUBLISHED()) post_requested = EnkiModelPost.get_first_post_on_page( EnkiModelPost.get_page( EnkiModelThread.get_by_id( int( thread )), EnkiModelPost.POST_LAST, int( post_count )), int( post_count )) url = enki.libutil.get_local_url( 'thread', { 'thread': thread, 'start': str( post_requested ), 'count': str( post_count )}) self.send_email_admin( 'FPA', url ) self.redirect( url ) return else: error_message = MSG.FAIL_POST_SUBMISSION() else: post_body = '' elif submit_type == 'preview': preview = post_body elif submit_type == 'cancel': post_body = '' data = EnkiModelPost.get_thread_data( thread, post_requested, post_count ) pagination = EnkiModelPost.get_thread_pagination_data( thread, post_requested, post_count ) self.render_tmpl( 'thread.html', CSRFneeded = show_input, active_menu = 'forums', data = data, pagination = pagination, user_id = self.user_id, has_permission_sticky = self.has_permissions( self.enki_user, [ 'PFPS' ]), show_input = show_input, preventmultitoken = pmtoken, error = error_message, maxpostlength = EnkiModelPost.POST_LENGTH_MAX, postbody = post_body, preview = preview )