Esempio n. 1
0
    def process(self):
        from the_tale.accounts.personal_messages import tt_api as pm_tt_api

        message = pm_tt_api.get_message(self.account_id, message_id=self.message_id)

        if message is None:
            return True # message can be removed by admins or with removed thread

        account = AccountPrototype.get_by_id(self.account_id)

        if not account.personal_messages_subscription:
            return True

        if account.id == get_system_user().id or account.is_bot:
            return True

        if not account.email:
            return True

        subject = '«Сказка»: личное сообщение'

        context = {'message': message,
                   'sender': AccountPrototype.get_by_id(message.sender_id)}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail([account], subject, text_content, html_content)
Esempio n. 2
0
    def process(self):
        from the_tale.accounts.personal_messages.prototypes import MessagePrototype as PersonalMessagePrototype

        message = PersonalMessagePrototype.get_by_id(self.message_id)

        if message is None:
            return True  # message can be removed by admins or with removed thread

        account = message.recipient

        if not account.personal_messages_subscription:
            return True

        if account.id == get_system_user().id or account.is_bot:
            return True

        if not account.email:
            return True

        subject = u'«Сказка»: личное сообщение'

        context = {'message': message}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail([account], subject, text_content, html_content)
Esempio n. 3
0
    def process(self):
        from the_tale.accounts.personal_messages.prototypes import MessagePrototype as PersonalMessagePrototype

        message = PersonalMessagePrototype.get_by_id(self.message_id)

        if message is None:
            return True # message can be removed by admins or with removed thread

        account = message.recipient

        if not account.personal_messages_subscription:
            return True

        if account.id == get_system_user().id or account.is_bot:
            return True

        if not account.email:
            return True

        subject = '«Сказка»: личное сообщение'

        context = {'message': message}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail([account], subject, text_content, html_content)
Esempio n. 4
0
    def check_send_mail(self, accounts, result, call_count, send=None):
        if send is None:
            send = mock.Mock()

        with mock.patch('django.core.mail.EmailMultiAlternatives.send', send) as send_mock:
            self.assertEqual(logic.send_mail(accounts, **self.SEND_ARGS), result)

        self.assertEqual(send_mock.call_count, call_count)
Esempio n. 5
0
    def check_send_mail(self, accounts, result, call_count, send=None):
        if send is None:
            send = mock.Mock()

        with mock.patch('django.core.mail.EmailMultiAlternatives.send',
                        send) as send_mock:
            self.assertEqual(logic.send_mail(accounts, **self.SEND_ARGS),
                             result)

        self.assertEqual(send_mock.call_count, call_count)
Esempio n. 6
0
    def process(self):
        account = AccountPrototype.get_by_id(self.account_id)

        if account.id == get_system_user().id or account.is_bot:
            return True

        subject = '«Сказка»: сброс пароля'

        context = {'account': account, 'task_uuid': self.task_uuid}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail([account], subject, text_content, html_content)
Esempio n. 7
0
    def process(self):

        subject = '«Сказка»: подтвердите email'

        task = ChangeCredentialsTaskPrototype.get_by_id(self.task_id)

        if task.account.id == get_system_user().id or task.account.is_bot:
            return True

        context = {'task': task}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail([(task.account, task.new_email)], subject, text_content, html_content)
Esempio n. 8
0
    def process(self):

        subject = '«Сказка»: подтвердите email'

        task = ChangeCredentialsTaskPrototype.get_by_id(self.task_id)

        if task.account.id == get_system_user().id or task.account.is_bot:
            return True

        context = {'task': task}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail([(task.account, task.new_email)], subject, text_content, html_content)
Esempio n. 9
0
    def process(self):
        account = AccountPrototype.get_by_id(self.account_id)

        if account.id == get_system_user().id or account.is_bot:
            return True

        subject = '«Сказка»: сброс пароля'

        context = {'account': account,
                   'task_uuid': self.task_uuid}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail([account], subject, text_content, html_content)
Esempio n. 10
0
    def process(self):
        from the_tale.news import logic as news_logic

        news = news_logic.load_news(self.news_id)

        if news is None:
            return True

        accounts = (AccountPrototype(model=account_model) for account_model in AccountPrototype._db_filter(news_subscription=True).iterator())

        subject = '«Сказка»::Новости: %s' % news.caption

        context = {'news': news}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail(accounts, subject, text_content, html_content)
Esempio n. 11
0
    def process(self):
        from the_tale.forum.prototypes import PostPrototype, SubscriptionPrototype

        post = PostPrototype.get_by_id(self.post_id)

        if post is None:
            return True # post can be removed by admins or with removed thread

        accounts = SubscriptionPrototype.get_accounts_for_thread(post.thread)

        subject = '«Сказка»: %s' % post.thread.caption

        context = {'post': post}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail(accounts, subject, text_content, html_content)
Esempio n. 12
0
    def process(self):
        from the_tale.cms.news import logic as news_logic

        news = news_logic.load_news(self.news_id)

        if news is None:
            return True

        accounts = (AccountPrototype(model=account_model) for account_model in AccountPrototype._db_filter(news_subscription=True).iterator())

        subject = '«Сказка»::Новости: %s' % news.caption

        context = {'news': news}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail(accounts, subject, text_content, html_content)
Esempio n. 13
0
    def process(self):
        from the_tale.forum.prototypes import PostPrototype, SubscriptionPrototype

        post = PostPrototype.get_by_id(self.post_id)

        if post is None:
            return True # post can be removed by admins or with removed thread

        accounts = SubscriptionPrototype.get_accounts_for_thread(post.thread)

        subject = '«Сказка»: %s' % post.thread.caption

        context = {'post': post}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail(accounts, subject, text_content, html_content)
Esempio n. 14
0
    def process(self):
        from the_tale.forum.prototypes import ThreadPrototype, SubscriptionPrototype

        thread = ThreadPrototype.get_by_id(self.thread_id)

        if thread is None:
            return True # thread can be removed by admins or with removed thread

        post = thread.get_first_post()

        accounts = SubscriptionPrototype.get_accounts_for_subcategory(thread.subcategory)

        subject = '«Сказка»: новая тема на форуме'

        context = {'thread': thread,
                   'post': post}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail(accounts, subject, text_content, html_content)
Esempio n. 15
0
    def process(self):
        from the_tale.forum.prototypes import ThreadPrototype, SubscriptionPrototype

        thread = ThreadPrototype.get_by_id(self.thread_id)

        if thread is None:
            return True # thread can be removed by admins or with removed thread

        post = thread.get_first_post()

        accounts = SubscriptionPrototype.get_accounts_for_subcategory(thread.subcategory)

        subject = '«Сказка»: новая тема на форуме'

        context = {'thread': thread,
                   'post': post}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail(accounts, subject, text_content, html_content)