Exemple #1
0
 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
Exemple #2
0
 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
Exemple #3
0
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
Exemple #4
0
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
Exemple #5
0
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
Exemple #6
0
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
Exemple #7
0
def get_thread_pagination_data( thread_selected, post_requested = POST_DEFAULT, post_count = POSTS_PER_PAGE ):
	thread = EnkiModelThread.get_by_id( int( thread_selected ))
	post_requested = thread.num_posts if post_requested == POST_LAST else int( post_requested )
	post_count = int( post_count )
	page_first = ''
	page_previous = ''
	page_current = []
	page_next = ''
	page_last = ''
	page_list = []


	# first page
	first_post_first_page = 1
	if post_requested <> 1:
		page_first = enki.libutil.get_local_url( 'thread', { 'thread': thread_selected, 'start': str( first_post_first_page ), 'count': str( post_count ) } )

	# last page
	first_post_last_page = get_first_post_on_page( get_page( thread, thread.num_posts, post_count ), post_count)
	if post_requested + post_count <= thread.num_posts:
		page_last = enki.libutil.get_local_url( 'thread', { 'thread': thread_selected, 'start': str( first_post_last_page ), 'count': str( post_count ) } )

	# current, previous and next pages
	first_post_previous_page = get_first_post_on_page( get_page( thread, post_requested, post_count ), post_count )
	first_post_next_page = get_first_post_on_page( get_page( thread, ( post_requested + post_count ), post_count ), post_count )
	if get_first_post_on_page( get_page( thread, post_requested, post_count ), post_count ) == post_requested:
		page = enki.libutil.get_local_url( 'thread', { 'thread': thread_selected, 'start': str( post_requested ), 'count': str( post_count ) } )
		page_current = [ page, get_page( thread, post_requested, post_count )]
		if page_current[ 1 ] > first_post_first_page:
			first_post_previous_page = get_first_post_on_page( page_current[ 1 ] - 1, post_count )
		if page_current[ 1 ] < get_page( thread, thread.num_posts, post_count ):
			first_post_next_page = get_first_post_on_page( page_current[ 1 ] + 1, post_count )
	if page_first:
		page_previous = enki.libutil.get_local_url( 'thread', { 'thread': thread_selected, 'start': str( first_post_previous_page ), 'count': str( post_count ) } )
	if page_last:
		page_next = enki.libutil.get_local_url( 'thread', { 'thread': thread_selected, 'start': str( first_post_next_page ), 'count': str( post_count ) } )

	# list of posts
	start = get_page( thread, post_requested, post_count ) - PAGES_BEFORE
	while start < 1:
		start += 1
	stop = get_page( thread, post_requested, post_count ) + PAGES_AFTER
	while stop > get_page( thread, thread.num_posts, post_count ):
		stop -= 1
	index = start
	while index <= stop :
		first_post = get_first_post_on_page( index, post_count )
		page = enki.libutil.get_local_url( 'thread', { 'thread': thread_selected, 'start': str( first_post ), 'count': str( post_count ) } )
		page_list.append([ page, index ])
		index += 1

	result = pagination( page_first, page_previous, page_current, page_list, page_next, page_last )
	return result
Exemple #8
0
def validate_thread_pagination( thread, post_requested, post_count ):
	result = enki.libutil.ENKILIB_ERROR
	if thread:
		if thread.isdigit():
			thread_entity = EnkiModelThread.get_by_id( int( thread ))
			if thread_entity:
				if post_requested and post_count:
					if post_requested.isdigit( ) and post_count.isdigit( ) :
						if int( post_requested ) > 0 and int( post_requested ) <= thread_entity.num_posts and int( post_count ) > 0:
							result = enki.libutil.ENKILIB_OK
					elif post_requested == 'last' and post_count.isdigit( ):
						result = enki.libutil.ENKILIB_OK
				elif post_requested == '' and post_count == '':
					result = enki.libutil.ENKILIB_OK
	return result
Exemple #9
0
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
Exemple #10
0
def validate_thread_pagination(thread, post_requested, post_count):
    result = enki.libutil.ENKILIB_ERROR
    if thread:
        if thread.isdigit():
            thread_entity = EnkiModelThread.get_by_id(int(thread))
            if thread_entity:
                if post_requested and post_count:
                    if post_requested.isdigit() and post_count.isdigit():
                        if int(post_requested) > 0 and int(
                                post_requested
                        ) <= thread_entity.num_posts and int(post_count) > 0:
                            result = enki.libutil.ENKILIB_OK
                    elif post_requested == 'last' and post_count.isdigit():
                        result = enki.libutil.ENKILIB_OK
                elif post_requested == '' and post_count == '':
                    result = enki.libutil.ENKILIB_OK
    return result
Exemple #11
0
 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
Exemple #12
0
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
Exemple #13
0
	def post( self, thread ):
		if self.ensure_is_logged_in() and enki.libdisplayname.ensure_has_display_name( self ):
			if thread.isdigit() and EnkiModelThread.get_by_id( int( thread ) ):
				self.check_CSRF( '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 = enki.libforum.POSTS_PER_PAGE
				if not post_requested:
					post_requested = enki.libforum.get_first_post_on_page( enki.libforum.get_page( EnkiModelThread.get_by_id( int( thread )), enki.libforum.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 = enki.libforum.add_preventmultipost_token( )
				else:
					if submit_type != 'cancel':
						if not post_body:
							error_message = MSG.POST_BODY_NEEDED()
						else:
							exceed = len( post_body ) - enki.libforum.POST_LENGTH_MAX
							if exceed > 0:
								error_message = MSG.POST_BODY_TOO_LONG( exceed )
					if not error_message:
						if submit_type == 'submit':
							if enki.libforum.check_and_delete_preventmultipost_token( pmtoken ):
								result = enki.libforum.add_post( user, thread, post_body )
								if result == enki.libutil.ENKILIB_OK:
									self.add_infomessage( 'success', MSG.SUCCESS( ), MSG.POST_PUBLISHED())
									post_body = ''
									post_requested = enki.libforum.get_first_post_on_page( enki.libforum.get_page( EnkiModelThread.get_by_id( int( thread )), enki.libforum.POST_LAST, int( post_count )), int( post_count ))
									self.redirect( enki.libutil.get_local_url( 'thread', { 'thread': thread, 'start': str( post_requested ), 'count': str( post_count )}))
									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 = enki.libforum.get_thread_data( thread, post_requested, post_count )
				pagination = enki.libforum.get_thread_pagination_data( thread, post_requested, post_count )
				self.render_tmpl( 'thread.html',
				                  active_page = 'forums',
				                  CSRFtoken = self.create_CSRF( 'thread' ),
				                  data = data,
				                  pagination = pagination,
				                  user_id = self.user_id,
				                  show_input = show_input,
				                  preventmultitoken = pmtoken,
				                  error = error_message,
				                  maxpostlength = enki.libforum.POST_LENGTH_MAX,
				                  postbody = post_body,
				                  preview = preview )
Exemple #14
0
    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 = enki.libforum.POSTS_PER_PAGE
                if not post_requested:
                    post_requested = enki.libforum.get_first_post_on_page(
                        enki.libforum.get_page(
                            EnkiModelThread.get_by_id(int(thread)),
                            enki.libforum.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 = enki.libforum.add_preventmultipost_token()
                else:
                    self.check_CSRF()
                    if submit_type != 'cancel':
                        if not post_body:
                            error_message = MSG.POST_BODY_NEEDED()
                        else:
                            exceed = len(
                                post_body) - enki.libforum.POST_LENGTH_MAX
                            if exceed > 0:
                                error_message = MSG.POST_BODY_TOO_LONG(exceed)
                    if not error_message:
                        if submit_type == 'submit':
                            if enki.libforum.check_and_delete_preventmultipost_token(
                                    pmtoken):
                                result = enki.libforum.add_post(
                                    user, thread, post_body)
                                if result == enki.libutil.ENKILIB_OK:
                                    self.add_infomessage(
                                        'success', MSG.SUCCESS(),
                                        MSG.POST_PUBLISHED())
                                    post_body = ''
                                    post_requested = enki.libforum.get_first_post_on_page(
                                        enki.libforum.get_page(
                                            EnkiModelThread.get_by_id(
                                                int(thread)),
                                            enki.libforum.POST_LAST,
                                            int(post_count)), int(post_count))
                                    self.redirect(
                                        enki.libutil.get_local_url(
                                            'thread', {
                                                'thread': thread,
                                                'start': str(post_requested),
                                                'count': str(post_count)
                                            }))
                                    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 = enki.libforum.get_thread_data(thread, post_requested,
                                                     post_count)
                pagination = enki.libforum.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,
                                 show_input=show_input,
                                 preventmultitoken=pmtoken,
                                 error=error_message,
                                 maxpostlength=enki.libforum.POST_LENGTH_MAX,
                                 postbody=post_body,
                                 preview=preview)
Exemple #15
0
    def get_thread_pagination_data(cls,
                                   thread_selected,
                                   post_requested=POST_DEFAULT,
                                   post_count=POSTS_PER_PAGE):
        thread = EnkiModelThread.get_by_id(int(thread_selected))
        post_requested = thread.num_posts if post_requested == cls.POST_LAST else int(
            post_requested)
        post_count = int(post_count)
        page_first = ''
        page_previous = ''
        page_current = []
        page_next = ''
        page_last = ''
        page_list = []

        # first page
        first_post_first_page = 1
        if post_requested <> 1:
            page_first = enki.libutil.get_local_url(
                'thread', {
                    'thread': thread_selected,
                    'start': str(first_post_first_page),
                    'count': str(post_count)
                })

        # last page
        first_post_last_page = cls.get_first_post_on_page(
            cls.get_page(thread, thread.num_posts, post_count), post_count)
        if post_requested + post_count <= thread.num_posts:
            page_last = enki.libutil.get_local_url(
                'thread', {
                    'thread': thread_selected,
                    'start': str(first_post_last_page),
                    'count': str(post_count)
                })

        # current, previous and next pages
        first_post_previous_page = cls.get_first_post_on_page(
            cls.get_page(thread, post_requested, post_count), post_count)
        first_post_next_page = cls.get_first_post_on_page(
            cls.get_page(thread, (post_requested + post_count), post_count),
            post_count)
        if cls.get_first_post_on_page(
                cls.get_page(thread, post_requested, post_count),
                post_count) == post_requested:
            page = enki.libutil.get_local_url(
                'thread', {
                    'thread': thread_selected,
                    'start': str(post_requested),
                    'count': str(post_count)
                })
            page_current = [
                page, cls.get_page(thread, post_requested, post_count)
            ]
            if page_current[1] > first_post_first_page:
                first_post_previous_page = cls.get_first_post_on_page(
                    page_current[1] - 1, post_count)
            if page_current[1] < cls.get_page(thread, thread.num_posts,
                                              post_count):
                first_post_next_page = cls.get_first_post_on_page(
                    page_current[1] + 1, post_count)
        if page_first:
            page_previous = enki.libutil.get_local_url(
                'thread', {
                    'thread': thread_selected,
                    'start': str(first_post_previous_page),
                    'count': str(post_count)
                })
        if page_last:
            page_next = enki.libutil.get_local_url(
                'thread', {
                    'thread': thread_selected,
                    'start': str(first_post_next_page),
                    'count': str(post_count)
                })

        # list of posts
        start = cls.get_page(thread, post_requested,
                             post_count) - cls.PAGES_BEFORE
        while start < 1:
            start += 1
        stop = cls.get_page(thread, post_requested,
                            post_count) + cls.PAGES_AFTER
        while stop > cls.get_page(thread, thread.num_posts, post_count):
            stop -= 1
        index = start
        while index <= stop:
            first_post = cls.get_first_post_on_page(index, post_count)
            page = enki.libutil.get_local_url(
                'thread', {
                    'thread': thread_selected,
                    'start': str(first_post),
                    'count': str(post_count)
                })
            page_list.append([page, index])
            index += 1

        result = pagination(page_first, page_previous, page_current, page_list,
                            page_next, page_last)
        return result