Пример #1
0
    def threads_info(self):
        if not self._account.is_authenticated():
            return {}

        time_barrier = datetime.datetime.now() - datetime.timedelta(seconds=forum_settings.UNREAD_STATE_EXPIRE_TIME)

        return {thread.id: thread for thread in ThreadPrototype.from_query(ThreadPrototype._db_filter(updated_at__gt=time_barrier))}
Пример #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([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 } )
Пример #3
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
            })
Пример #4
0
    def threads_info(self):
        if not self._account.is_authenticated:
            return {}

        time_barrier = datetime.datetime.now() - datetime.timedelta(
            seconds=forum_settings.UNREAD_STATE_EXPIRE_TIME)

        return {
            thread.id: thread
            for thread in ThreadPrototype.from_query(
                ThreadPrototype._db_filter(updated_at__gt=time_barrier))
        }