def update_comment(self): """ Creates the shadow comment object to hold this document's place in a commment thread, if this document is a reply to comments. """ # Create comment objects only when the doc is public. That way, # subscription signals are fired at the right moment -- the comment is # public and viewable. parent = None if self.in_reply_to: try: parent = self.in_reply_to.document except Document.DoesNotExist: pass if parent and self.is_public(): # Only create a comment object if we are public. try: comment = self.comment except Comment.DoesNotExist: comment = Comment() comment.user = self.author comment.removed = False comment.document = parent comment.comment_doc = self comment.save() else: # If we've gone non-public, mark the comment removed rather # than deleting. That way, we don't re-fire subscriptions if # the doc is only temporarily un-published. try: self.comment.removed = True self.comment.save() except Comment.DoesNotExist: pass