Exemplo n.º 1
0
    def get_subcategory(self, page=1):

        threads_query = Thread.objects.filter(subcategory=self.subcategory._model)

        url_builder = UrlBuilder(reverse('forum:subcategories:show', args=[self.subcategory.id]), arguments={'page': page})

        page -= 1

        paginator = Paginator(page, threads_query.count(), forum_settings.THREADS_ON_PAGE, url_builder)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        thread_from, thread_to = paginator.page_borders(page)

        threads = ThreadPrototype.from_query(threads_query.select_related().order_by('-important', '-updated_at')[thread_from:thread_to])

        important_threads = sorted([t for t in threads if t.important], key=lambda t: t.caption)
        threads = [t for t in threads if not t.important]

        read_state = ReadState(account=self.account)

        if self.account.is_authenticated:
            SubCategoryReadInfoPrototype.read_subcategory(subcategory=self.subcategory, account=self.account)

        return self.template('forum/subcategory.html',
                             {'category': self.category,
                              'subcategory': self.subcategory,
                              'can_create_thread': can_create_thread(self.account, self.subcategory),
                              'paginator': paginator,
                              'can_subscribe': self.account.is_authenticated and not self.account.is_fast,
                              'has_subscription': SubscriptionPrototype.has_subscription(self.account, subcategory=self.subcategory),
                              'threads': threads,
                              'important_threads': important_threads,
                              'read_state': read_state } )
Exemplo n.º 2
0
    def get_subcategory(self, page=1):

        threads_query = Thread.objects.filter(
            subcategory=self.subcategory._model)

        url_builder = UrlBuilder(reverse('forum:subcategories:show',
                                         args=[self.subcategory.id]),
                                 arguments={'page': page})

        page -= 1

        paginator = Paginator(page, threads_query.count(),
                              forum_settings.THREADS_ON_PAGE, url_builder)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        thread_from, thread_to = paginator.page_borders(page)

        threads = ThreadPrototype.from_query(
            threads_query.select_related().order_by(
                '-important', '-updated_at')[thread_from:thread_to])

        important_threads = sorted(filter(lambda t: t.important, threads),
                                   key=lambda t: t.caption)
        threads = filter(lambda t: not t.important, threads)

        read_state = ReadState(account=self.account)

        if self.account.is_authenticated():
            SubCategoryReadInfoPrototype.read_subcategory(
                subcategory=self.subcategory, account=self.account)

        return self.template(
            'forum/subcategory.html', {
                'category':
                self.category,
                'subcategory':
                self.subcategory,
                'can_create_thread':
                can_create_thread(self.account, self.subcategory),
                'paginator':
                paginator,
                'can_subscribe':
                self.account.is_authenticated() and not self.account.is_fast,
                'has_subscription':
                SubscriptionPrototype.has_subscription(
                    self.account, subcategory=self.subcategory),
                'threads':
                threads,
                'important_threads':
                important_threads,
                'read_state':
                read_state
            })
Exemplo n.º 3
0
    def initialize(self, account, thread, page, inline=False):

        from the_tale.game.heroes.prototypes import HeroPrototype

        self.account = account
        self.thread = thread

        url_builder = UrlBuilder(reverse('forum:threads:show', args=[self.thread.id]),
                                 arguments={'page': page})

        page -= 1

        self.paginator = Paginator(page, thread.posts_count+1, forum_settings.POSTS_ON_PAGE, url_builder)

        if self.paginator.wrong_page_number:
            return False

        post_from, post_to = self.paginator.page_borders(page)
        self.post_from = post_from

        self.posts = [PostPrototype(post_model) for post_model in Post.objects.filter(thread=self.thread._model).order_by('created_at')[post_from:post_to]]

        self.authors = {author.id:author for author in  AccountPrototype.get_list_by_id([post.author_id for post in self.posts])}

        self.game_objects = {game_object.account_id:game_object
                             for game_object in  HeroPrototype.get_list_by_id([post.author_id for post in self.posts])}

        pages_on_page_slice = self.posts
        if post_from == 0:
            pages_on_page_slice = pages_on_page_slice[1:]

        self.has_post_on_page = any([post.author.id == self.account.id for post in pages_on_page_slice])
        self.new_post_form = forms.NewPostForm()
        self.start_posts_from = page * forum_settings.POSTS_ON_PAGE

        self.inline = inline

        self.can_delete_posts = can_delete_posts(self.account, self.thread)
        self.can_change_posts = can_change_posts(self.account)
        self.can_delete_thread = not self.inline and can_delete_thread(self.account)
        self.can_change_thread = not self.inline and can_change_thread(self.account, self.thread)

        self.ignore_first_post = (self.inline and self.paginator.current_page_number==0)
        self.can_post = self.account.is_authenticated() and not self.account.is_fast

        self.no_posts = (len(self.posts) == 0) or (self.ignore_first_post and len(self.posts) == 1)
        self.can_subscribe = self.account.is_authenticated() and not self.account.is_fast

        self.has_subscription = SubscriptionPrototype.has_subscription(self.account, self.thread)

        return True
Exemplo n.º 4
0
    def initialize(self, account, thread, page, inline=False):

        self.account = account
        self.thread = thread

        url_builder = UrlBuilder(reverse('forum:threads:show',
                                         args=[self.thread.id]),
                                 arguments={'page': page})

        page -= 1

        self.paginator = Paginator(page, thread.posts_count + 1,
                                   forum_settings.POSTS_ON_PAGE, url_builder)

        if self.paginator.wrong_page_number:
            return False

        post_from, post_to = self.paginator.page_borders(page)
        self.post_from = post_from

        self.posts = [
            PostPrototype(post_model)
            for post_model in Post.objects.filter(thread=self.thread._model).
            order_by('created_at')[post_from:post_to]
        ]

        self.authors = {
            author.id: author
            for author in AccountPrototype.get_list_by_id(
                [post.author_id for post in self.posts])
        }

        self.game_objects = {
            game_object.account_id: game_object
            for game_object in heroes_logic.load_heroes_by_account_ids(
                [post.author_id for post in self.posts])
        }

        pages_on_page_slice = self.posts
        if post_from == 0:
            pages_on_page_slice = pages_on_page_slice[1:]

        self.has_post_on_page = any([
            post.author.id == self.account.id for post in pages_on_page_slice
        ])
        self.new_post_form = forms.NewPostForm()
        self.start_posts_from = page * forum_settings.POSTS_ON_PAGE

        self.inline = inline

        self.can_delete_posts = can_delete_posts(self.account, self.thread)
        self.can_change_posts = can_change_posts(self.account)
        self.can_delete_thread = not self.inline and can_delete_thread(
            self.account)
        self.can_change_thread = not self.inline and can_change_thread(
            self.account, self.thread)

        self.ignore_first_post = (self.inline
                                  and self.paginator.current_page_number == 0)
        self.can_post = self.account.is_authenticated(
        ) and not self.account.is_fast

        self.no_posts = (len(self.posts) == 0) or (self.ignore_first_post
                                                   and len(self.posts) == 1)
        self.can_subscribe = self.account.is_authenticated(
        ) and not self.account.is_fast

        self.has_subscription = SubscriptionPrototype.has_subscription(
            self.account, self.thread)

        return True