Ejemplo n.º 1
0
    def feed(self):
        feed = Atom1Feed(u'Сказка: Форум',
                         self.request.build_absolute_uri('/'),
                         u'Новые темы на форуме мморпг «Сказка»',
                         language=u'ru',
                         feed_url=self.request.build_absolute_uri(
                             reverse('forum:feed')))

        threads = [
            ThreadPrototype(model=thread)
            for thread in Thread.objects.filter(subcategory__restricted=False).
            order_by('-created_at')[:forum_settings.FEED_ITEMS_NUMBER]
        ]

        for thread in threads:

            if datetime.datetime.now(
            ) - thread.created_at < datetime.timedelta(
                    seconds=forum_settings.FEED_ITEMS_DELAY):
                continue

            post = PostPrototype(model=Post.objects.filter(
                thread_id=thread.id).order_by('created_at')[0])

            url = self.request.build_absolute_uri(
                reverse('forum:threads:show', args=[thread.id]))

            feed.add_item(title=thread.caption,
                          link=url,
                          description=post.safe_html,
                          pubdate=thread.created_at,
                          unique_id=url)

        return self.atom(feed.writeString('utf-8'))
Ejemplo n.º 2
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