Exemple #1
0
    def save(self, *args, **kwargs):
        notify = not self.id

        super(TypedComment, self).save(*args, **kwargs)

        if notify:
            post = self.content_object
            ctx = {
                'comment': self,
                'post': post,
            }

            # Internal comments go to publishers and editors
            if self.comment_type == 'internal':
                subject = _('New internal comment')
                email_helpers.send_publishers_authors_email(subject, 'send_notification_new_int_comment.txt', ctx)
            else:
                subject = _('New comment')

                ## Improbable generic foreign key filters would work
                users = set([post.author])

                if post.co_author:
                    users.add(post.co_author)

                commentators = auth_models.User.objects.filter(id__in=set([p.user.id for p in post.comments.all()]))
                for commentator in commentators:
                    users.add(commentator)

                for user in users:
                    email_helpers.send_user_email(user, subject, 'send_notification_new_ext_comment.txt', ctx)
Exemple #2
0
    def save(self, *args, **kwargs):
        from pyquery import PyQuery as pq

        ## Based on the assumption ckeditor always uses paragraphs
        # Also skip if someone accidentally started with an empty p
        # Also find image
        img_html = None
        first = True
        self.preview = None
        self.preview_img = None
        for p in pq(self.content)('p') + pq(self.content)('div'):
            preview = pq(p).html()

            # Policy dictates reprints are noted with <em> tags at the start
            em = pq(preview)('em')
            if em:
                em_html = pq(em).html()
                if preview.replace(em_html, '').strip() == '<em></em>':
                    continue

            # At least once we have an unclosed <em> at the end
            preview = pq(preview).text().strip()
            if preview and not self.preview:
                self.preview = preview
                if self.preview_img:
                    break

            # Returns None if not found
            img = pq(p)('img')
            img_src = img.attr('src')
            if img_src:
                self.preview_img = img_src
                if first:
                    self.preview = self.preview.strip(img.outerHtml())
                break

            first = False

        ## Send only on new posts
        notify = not self.id

        super(Post, self).save(*args, **kwargs)

        if notify:
            subject = _('New post')
            ctx = {
                'post': self,
            }
            email_helpers.send_publishers_authors_email(subject, 'send_notification_new_post.txt', ctx)