def __init__(self, request, thread, page): try: thread_model = thread.unwrap() except AttributeError: thread_model = thread posts_queryset = self.get_posts_queryset(request, thread_model) posts_limit = settings.MISAGO_POSTS_PER_PAGE posts_orphans = settings.MISAGO_POSTS_TAIL list_page = paginate(posts_queryset, page, posts_limit, posts_orphans, paginator=PostsPaginator) paginator = pagination_dict(list_page) posts = list(list_page.object_list) posters = [] for post in posts: post.category = thread.category post.thread = thread_model if post.poster: posters.append(post.poster) make_users_status_aware(request.user, posters) if thread.category.acl['can_see_posts_likes']: add_likes_to_posts(request.user, posts) # add events to posts if thread_model.has_events: first_post = None if list_page.has_previous(): first_post = posts[0] last_post = None if list_page.has_next(): last_post = posts[-1] events_limit = settings.MISAGO_EVENTS_PER_PAGE posts += self.get_events_queryset(request, thread_model, events_limit, first_post, last_post) # sort both by pk posts.sort(key=lambda p: p.pk) # make posts and events ACL and reads aware add_acl(request.user, posts) make_read_aware(request.user, posts) self._user = request.user self.posts = posts self.paginator = paginator
def __init__(self, request, thread, page): try: thread_model = thread.unwrap() except AttributeError: thread_model = thread posts_queryset = self.get_posts_queryset(request, thread_model) posts_limit = settings.MISAGO_POSTS_PER_PAGE posts_orphans = settings.MISAGO_POSTS_TAIL list_page = paginate( posts_queryset, page, posts_limit, posts_orphans, paginator=PostsPaginator ) paginator = pagination_dict(list_page) posts = list(list_page.object_list) posters = [] for post in posts: post.category = thread.category post.thread = thread_model if post.poster: posters.append(post.poster) make_users_status_aware(request.user, posters) if thread.category.acl['can_see_posts_likes']: add_likes_to_posts(request.user, posts) # add events to posts if thread_model.has_events: first_post = None if list_page.has_previous(): first_post = posts[0] last_post = None if list_page.has_next(): last_post = posts[-1] events_limit = settings.MISAGO_EVENTS_PER_PAGE posts += self.get_events_queryset( request, thread_model, events_limit, first_post, last_post ) # sort both by pk posts.sort(key=lambda p: p.pk) # make posts and events ACL and reads aware add_acl(request.user, posts) make_posts_read_aware(request.user, thread_model, posts) self._user = request.user self.posts = posts self.paginator = paginator
def __init__(self, request, profile, page=0): root_category = ThreadsRootCategory(request) threads_categories = [root_category.unwrap() ] + root_category.subcategories threads_queryset = self.get_threads_queryset(request, threads_categories, profile) posts_queryset = self.get_posts_queryset( request.user, profile, threads_queryset).filter(is_hidden=False, is_unapproved=False).order_by('-pk') list_page = paginate(posts_queryset, page, settings.MISAGO_POSTS_PER_PAGE, settings.MISAGO_POSTS_TAIL) paginator = pagination_dict(list_page, include_page_range=False) posts = list(list_page.object_list) posters = [] threads = [] for post in posts: threads.append(post.thread) if post.poster: posters.append(post.poster) add_categories_to_items(root_category.unwrap(), threads_categories, posts + threads) add_acl(request.user, threads) add_acl(request.user, posts) threadstracker.make_threads_read_aware(request.user, threads) for post in posts: threadstracker.make_posts_read_aware(request.user, post.thread, [post]) add_likes_to_posts(request.user, posts) make_users_status_aware(request.user, posters) self._user = request.user self.posts = posts self.paginator = paginator
def __init__(self, request, profile, page=0): root_category = ThreadsRootCategory(request) threads_categories = [root_category.unwrap()] + root_category.subcategories threads_queryset = self.get_threads_queryset( request, threads_categories, profile) posts_queryset = self.get_posts_queryset( request.user, profile, threads_queryset ).filter( is_event=False, is_hidden=False, is_unapproved=False ).order_by('-pk') list_page = paginate( posts_queryset, page, settings.MISAGO_POSTS_PER_PAGE, settings.MISAGO_POSTS_TAIL) paginator = pagination_dict(list_page, include_page_range=False) posts = list(list_page.object_list) posters = [] threads = [] for post in posts: threads.append(post.thread) if post.poster: posters.append(post.poster) add_categories_to_items( root_category.unwrap(), threads_categories, posts + threads) add_acl(request.user, threads) add_acl(request.user, posts) threadstracker.make_threads_read_aware(request.user, threads) for post in posts: threadstracker.make_posts_read_aware(request.user, post.thread, [post]) add_likes_to_posts(request.user, posts) make_users_status_aware(request.user, posters) self._user = request.user self.posts = posts self.paginator = paginator