示例#1
0
def send_emails_for_subscribers():
    emails = Subscriber.objects.filter(send_email=True).values_list('email', flat=True)

    today = timezone.now()

    published_from = (today - timedelta(days=7)).replace(hour=0, minute=0, second=0)
    published_to = (today - timedelta(days=1)).replace(hour=23, minute=59, second=59)

    articles = Article.objects.filter(status=Article.STATUS_PUBLISHED,
                                      published_at__gte=published_from,
                                      published_at__lte=published_to)[:6]

    if not articles:
        return

    common_data = {
        'articles': articles,
        'domain': Site.objects.get_current(),
        'scheme': settings.META_SITE_PROTOCOL,
        'watermark_article': watermark_article,
    }

    for email in emails:
        data = {'email': email}
        data.update(common_data)
        render_send_email([email, ], 'blog/email/newsletter', data)
示例#2
0
def notify_user(user_id, task_ids):
    user = ApplicationUser.objects.get(id=user_id)
    tasks = Task.objects.filter(id__in=task_ids)

    if user.email:
        context = {'user': user, 'tasks': tasks}
        render_send_email([user.email], 'email/notification/deadline_notification', context)
示例#3
0
 def save(self, commit=True):
     password = self.cleaned_data["password1"]
     user = super(CustomAdminPasswordChangeForm, self).save(commit)
     context = {'password': password}
     template_name = 'email/reset_pass/transfer_notification'
     render_send_email([user.email],
                       template_name,
                       context,
                       use_base_template=False)
     return user
示例#4
0
    def send_email(self, template_name=None, instance_name=None, email=None,
                   extra_context=None, **kwargs):
        template_name = template_name or self.default_template_name
        email = email or self.default_email_address or getattr(self, 'email', None)
        if not (template_name and email):
            return

        class_name = instance_name or self.__class__.__name__.lower()
        context = dict([(class_name, self)])
        context.update(extra_context or {})

        render_send_email([email], template_name, context, use_base_template=False, **kwargs)
示例#5
0
def queue_render_send_email(recipients,
                            template,
                            data,
                            from_email=settings.DEFAULT_FROM_EMAIL,
                            subject=None,
                            use_base_template=True,
                            category=None,
                            fail_silently=False,
                            language=None,
                            cc=None,
                            bcc=None,
                            attachments=None,
                            headers=None,
                            bypass_hijacking=False,
                            attach_files=None):

    logger = queue_render_send_email.get_logger()

    logger.debug('Rendering and sending %s to %s' % (
        template,
        ','.join(recipients),
    ))

    render_send_email(recipients=recipients,
                      template=template,
                      data=data,
                      from_email=from_email,
                      subject=subject,
                      use_base_template=use_base_template,
                      category=category,
                      fail_silently=fail_silently,
                      language=language,
                      cc=cc,
                      bcc=bcc,
                      attachments=attachments,
                      headers=headers,
                      bypass_queue=True,
                      bypass_hijacking=bypass_hijacking,
                      attach_files=attach_files)

    return True
示例#6
0
    def create(self, validated_data):
        sender_account = validated_data['sender'].bank_account
        value = validated_data['value']

        sender_account.balance -= value
        sender_account.save()

        for_send_notification = [
            sender_account.holder.email,
        ]

        try:
            recipient_account = validated_data['recipient'].bank_account
            transfer_type = 'Internal'
            for_send_notification += [
                recipient_account.holder.email,
            ]
        except AttributeError:
            transfer_type = 'External'

        for destination in for_send_notification:
            context = {
                'transfer_type': transfer_type,
                'sender': sender_account,
                'is_sender': destination == sender_account.holder.email,
                'amount': value,
                'code': sender_account.currency.code,
                'recipient': validated_data['recipient']
            }
            render_send_email(
                recipients=[
                    destination,
                ],
                template='email/transfer_notification/transfer_notification',
                data=context,
                use_base_template=False)

        return super(TransferBaseSerializer, self).create(validated_data)
示例#7
0
 def send(self):
     context = {'url': self._get_invite_url()}
     render_send_email([self.email, ], 'email/invite/invite', context)