Example #1
0
    def set_last_post(self, post=None):
        """
        Updates denormalised details about this Forum's last Post.

        It is assumed that any Post given is not a metapost and is not in
        a hidden Topic.

        If the last Post is not given, the last non-meta, non-hidden Post
        will be looked up. This method should never set the details of a
        Post in a hidden Topic as the last Post, as this would result in
        the display of latest Post links which do not work for regular and
        anonymous users.
        """
        try:
            if post is None:
                post = Post.objects.filter(meta=False,
                                           topic__forum=self,
                                           topic__hidden=False) \
                                    .order_by('-posted_at', '-id')[0]
            self.last_post_at = post.posted_at
            self.last_topic_id = post.topic.pk
            self.last_topic_title = post.topic.title
            self.last_user_id = post.user.pk
            self.last_username = post.user.username
        except IndexError:
            # No Post was given and there was no latest, non-hidden
            # Post, so there must not be any eligible Topics in the
            # Forum at the moment.
            self.last_post_at, self.last_topic_id, self.last_user_id = (None,
                                                                        None,
                                                                        None)
            self.last_topic_title, self.last_username = ('', '')
        model_utils.update(self, 'last_post_at', 'last_topic_id',
                           'last_topic_title', 'last_user_id', 'last_username')
Example #2
0
 def update_post_count(self):
     """
     Updates this ForumProfile's ``post_count`` with the number of
     Posts currently associated with its User.
     """
     self.post_count = self.user.posts.count()
     model_utils.update(self, 'post_count')
Example #3
0
    def set_last_post(self, post=None):
        """
        Updates denormalised details about this Forum's last Post.

        It is assumed that any Post given is not a metapost and is not in
        a hidden Topic.

        If the last Post is not given, the last non-meta, non-hidden Post
        will be looked up. This method should never set the details of a
        Post in a hidden Topic as the last Post, as this would result in
        the display of latest Post links which do not work for regular and
        anonymous users.
        """
        try:
            if post is None:
                post = Post.objects.filter(meta=False,
                                           topic__forum=self,
                                           topic__hidden=False) \
                                    .order_by('-posted_at', '-id')[0]
            self.last_post_at = post.posted_at
            self.last_topic_id = post.topic.pk
            self.last_topic_title = post.topic.title
            self.last_user_id = post.user.pk
            self.last_username = post.user.username
        except IndexError:
            # No Post was given and there was no latest, non-hidden
            # Post, so there must not be any eligible Topics in the
            # Forum at the moment.
            self.last_post_at, self.last_topic_id, self.last_user_id = (None, None, None)
            self.last_topic_title, self.last_username = ('', '')
        model_utils.update(self, 'last_post_at', 'last_topic_id',
                           'last_topic_title', 'last_user_id', 'last_username')
Example #4
0
 def update_post_count(self):
     """
     Updates this ForumProfile's ``post_count`` with the number of
     Posts currently associated with its User.
     """
     self.post_count = self.user.posts.count()
     model_utils.update(self, 'post_count')
Example #5
0
 def update_post_count(self, meta=False):
     """
     Updates one of this Topic's denormalised Post counts, based on
     ``meta``.
     """
     field_name = '%spost_count' % (meta and 'meta' or '', )
     setattr(self, field_name, self.posts.filter(meta=meta).count())
     model_utils.update(self, field_name)
Example #6
0
 def update_post_count(self, meta=False):
     """
     Updates one of this Topic's denormalised Post counts, based on
     ``meta``.
     """
     field_name = '%spost_count' % (meta and 'meta' or '',)
     setattr(self, field_name, self.posts.filter(meta=meta).count())
     model_utils.update(self, field_name)
Example #7
0
    def set_last_post(self, post=None):
        """
        Updates details about this Topic's last Post and its
        denormalised ``post_count``.

        It is assumed that any Post given is not a metapost.

        If the last Post is not given, it will be looked up.
        """
        if post is None:
            post = self.posts.filter(meta=False).order_by('-posted_at', '-id')[0]
        self.post_count = self.posts.filter(meta=False).count()
        self.last_post_at = post.posted_at
        self.last_user_id = post.user.pk
        self.last_username = post.user.username
        model_utils.update(self, 'post_count', 'last_post_at', 'last_user_id',
                           'last_username')
Example #8
0
    def set_last_post(self, post=None):
        """
        Updates details about this Topic's last Post and its
        denormalised ``post_count``.

        It is assumed that any Post given is not a metapost.

        If the last Post is not given, it will be looked up.
        """
        if post is None:
            post = self.posts.filter(meta=False).order_by('-posted_at',
                                                          '-id')[0]
        self.post_count = self.posts.filter(meta=False).count()
        self.last_post_at = post.posted_at
        self.last_user_id = post.user.pk
        self.last_username = post.user.username
        model_utils.update(self, 'post_count', 'last_post_at', 'last_user_id',
                           'last_username')
Example #9
0
 def update_topic_count(self):
     """
     Updates this Forum's ``topic_count``.
     """
     self.topic_count = self.topics.count()
     model_utils.update(self, 'topic_count')
Example #10
0
 def update_topic_count(self):
     """
     Updates this Forum's ``topic_count``.
     """
     self.topic_count = self.topics.count()
     model_utils.update(self, 'topic_count')