Esempio n. 1
0
def unsubscribe(request, hashed, data):
    try:
        username, email = decode_data(hashed, data)
    except Exception:
        raise Http404
    try:
        subscription = SubscriptionSettings.objects.get(
            user__username=username, user__email=email)
    except SubscriptionSettings.DoesNotExist as e:
        raise Http404
    if not request.POST:
        context = {'user': subscription.user, 'cancel_url': '/'}
        return render(request, 'mass_post_office/unsubscribe.html', context)
    if not 'is_unsubscribed' in request.POST:
        return redirect('/')
    subscription.subscribed = False
    subscription.save()
    try:
        mail.from_template(settings.DEFAULT_FROM_EMAIL,
                           subscription.user.email,
                           template=u'post_office/canceled_subscription',
                           context={'user': subscription.user})
    except EmailTemplate.DoesNotExist as e:
        # we should process undefined EmailTemplate here
        # try to check 'post_migrate'
        pass
    return redirect(reverse('mass_post_office:unsubscribed'))
Esempio n. 2
0
def unsubscribe(request, hashed, data):
    try:
        username, email = decode_data(hashed, data)
    except Exception:
        raise Http404
    try:
        subscription = SubscriptionSettings.objects.get(
            user__username=username,
            user__email=email)
    except SubscriptionSettings.DoesNotExist as e:
        raise Http404
    if not request.POST:
        context = {
            'user': subscription.user,
            'cancel_url': '/'
        }
        return render(request, 'mass_post_office/unsubscribe.html', context)
    if not 'is_unsubscribed' in request.POST:
        return redirect('/')
    subscription.subscribed = False
    subscription.save()
    try:
        mail.from_template(
            settings.DEFAULT_FROM_EMAIL,
            subscription.user.email,
            template=u'post_office/canceled_subscription',
            context={
                'user': subscription.user
            })
    except EmailTemplate.DoesNotExist as e:
        # we should process undefined EmailTemplate here
        # try to check 'post_migrate'
        pass
    return redirect(reverse('mass_post_office:unsubscribed'))
Esempio n. 3
0
 def save(self, *args, **kwargs):
     super(MassEmail, self).save(*args, **kwargs)
     for user in self.mailing_list.get_users_queryset():
         email = from_template(settings.DEFAULT_FROM_EMAIL,
                               recipient=user.email,
                               template=self.template,
                               context={'user': user},
                               scheduled_time=self.scheduled_time,
                               priority=self.priority)
         email.save()
         self.emails.add(email)
Esempio n. 4
0
 def save(self, *args, **kwargs):
     super(MassEmail, self).save(*args, **kwargs)
     for user in self.mailing_list.get_users_queryset():
         email = from_template(
             settings.DEFAULT_FROM_EMAIL,
             recipient=user.email,
             template=self.template,
             context={'user': user},
             scheduled_time=self.scheduled_time,
             priority=self.priority)
         email.save()
         self.emails.add(email)
Esempio n. 5
0
 def __check_send_email(tpl_name, content=None):
     email = mail.from_template(
         "*****@*****.**",
         user.email,
         template=tpl_name,
         context=dict(user=user))
     self.assertEqual(Email.objects.get(id=email.id).status, STATUS.queued)
     mail.send_queued()
     self.assertEqual(Email.objects.get(id=email.id).status, STATUS.sent)
     if content:
         for field in content.iterkeys():
             self.assertIn(content[field], getattr(email, field))
Esempio n. 6
0
 def __check_send_email(tpl_name, content=None):
     email = mail.from_template("*****@*****.**",
                                user.email,
                                template=tpl_name,
                                context=dict(user=user))
     self.assertEqual(
         Email.objects.get(id=email.id).status, STATUS.queued)
     mail.send_queued()
     self.assertEqual(
         Email.objects.get(id=email.id).status, STATUS.sent)
     if content:
         for field in content.iterkeys():
             self.assertIn(content[field], getattr(email, field))