Ejemplo n.º 1
0
def add(request):
    if Newsletter.objects.filter(email=request.POST['email']) != None:
        newsletter = Newsletter(email=request.POST['email'])
        newsletter.save()
        request.session["message"] = u"Zostałeś zapisany do newsletter'a"
        request.session["message_context"] = "success"
    else:
        request.session["message"] = u"Podany adres już istnieje w bazie"
        request.session["message_context"] = "danger"
    return HttpResponseRedirect('/')
Ejemplo n.º 2
0
class MailingTestCase(MailTestCase):

    def get_newsletter_kwargs(self):
        """ Returns the keyword arguments for instanciating the newsletter. """

        return {
            'title': 'Test newsletter',
            'slug': 'test-newsletter',
            'sender': 'Test Sender',
            'email': '[email protected]'
        }

    def setUp(self):
        self.n = Newsletter(**self.get_newsletter_kwargs())
        self.n.save()
        try:
            self.n.site.set(get_default_sites())
        except AttributeError:  # Django < 1.10
            self.n.site = get_default_sites()

        self.m = Message(title='Test message',
                         newsletter=self.n,
                         slug='test-message')
        self.m.save()

        self.s = Subscription.objects.create(
            name='Test Name', email='[email protected]',
            newsletter=self.n, subscribed=True
        )
        self.s2 = Subscription.objects.create(
            name='René Luçon', email='[email protected]',
            newsletter=self.n, subscribed=True
        )

    def send_email(self, action):
        assert action in ACTIONS + ('message', ), 'Unknown action: %s' % action

        if action == 'message':
            # Create submission
            sub = Submission.from_message(self.m)
            sub.prepared = True
            sub.publish_date = now() - timedelta(seconds=1)
            sub.save()

            # Send message email
            Submission.submit_queue()
        else:
            for subscriber in self.n.get_subscriptions():
                subscriber.send_activation_email(action)
Ejemplo n.º 3
0
    def getNewsletter(self):
        newsl = None
        try:
            newsl = Newsletter.objects.get(slug=self.fingerprint.fingerprint_hash)

        except Newsletter.DoesNotExist:

            newsl = Newsletter( title=self.fingerprint.findName()+' Updates',
                            slug=self.fingerprint.fingerprint_hash,
                            email=settings.DEFAULT_FROM_EMAIL,
                            message_template=EmailTemplate.objects.get(subject='aggregate'),
                            sender="Emif Catalogue")
            newsl.save()

        return newsl
Ejemplo n.º 4
0
 def get_services_newsletter(self):
     try:
         newsletter = Newsletter.objects.get(title=u'Новая акция')
     except Newsletter.DoesNotExist:
         newsletter = Newsletter()
         newsletter.title = u'Новая акция'
         newsletter.email = settings.DEFAULT_NEWSLETTER_EMAIL
         newsletter.sender = settings.DEFAULT_NEWSLETTER_SENDER
         newsletter.send_html = True
         newsletter.visible = True
         newsletter.slug=u'novaya-akciya'
         newsletter.save()
         newsletter.site.add(*Site.objects.all())
     return newsletter
Ejemplo n.º 5
0
    def setUp(self):
        self.n = Newsletter(title='Test newsletter',
                            slug='test-newsletter',
                            sender='Test Sender',
                            email='[email protected]')
        self.n.save()
        try:
            self.n.site.set(get_default_sites())
        except AttributeError:  # Django < 1.10
            self.n.site = get_default_sites()

        self.subscribe_url = \
            reverse('newsletter_subscribe_request',
                    kwargs={'newsletter_slug': self.n.slug})
        self.subscribe_confirm_url = \
            reverse('newsletter_subscribe_confirm',
                    kwargs={'newsletter_slug': self.n.slug})
        self.subscribe_email_sent_url = \
            reverse('newsletter_activation_email_sent',
                    kwargs={'newsletter_slug': self.n.slug,
                            'action': 'subscribe'})
        self.subscribe_activated_url = \
            reverse('newsletter_action_activated',
                    kwargs={'newsletter_slug': self.n.slug,
                            'action': 'subscribe'})

        self.update_url = \
            reverse('newsletter_update_request',
                    kwargs={'newsletter_slug': self.n.slug})
        self.update_email_sent_url = \
            reverse('newsletter_activation_email_sent',
                    kwargs={'newsletter_slug': self.n.slug,
                            'action': 'update'})
        self.update_activated_url = \
            reverse('newsletter_action_activated',
                    kwargs={'newsletter_slug': self.n.slug,
                            'action': 'update'})

        self.unsubscribe_url = \
            reverse('newsletter_unsubscribe_request',
                    kwargs={'newsletter_slug': self.n.slug})
        self.unsubscribe_confirm_url = \
            reverse('newsletter_unsubscribe_confirm',
                    kwargs={'newsletter_slug': self.n.slug})
        self.unsubscribe_email_sent_url = \
            reverse('newsletter_activation_email_sent',
                    kwargs={'newsletter_slug': self.n.slug,
                            'action': 'unsubscribe'})
        self.unsubscribe_activated_url = \
            reverse('newsletter_action_activated',
                    kwargs={'newsletter_slug': self.n.slug,
                            'action': 'unsubscribe'})

        super(SubscribeTestCase, self).setUp()
Ejemplo n.º 6
0
    def setUp(self):
        self.n = Newsletter(**self.get_newsletter_kwargs())
        self.n.save()
        self.n.site = get_default_sites()

        self.m = Message(title='Test message',
                         newsletter=self.n,
                         slug='test-message')
        self.m.save()

        self.s = Subscription(
            name='Test Name', email='[email protected]',
            newsletter=self.n, subscribed=True
        )
        self.s.save()
Ejemplo n.º 7
0
    def handle(self, *args, **kwargs):
        self.site = SITE_DOMAIN
        newsletters_to_send = Newsletter.get_queue().iterator()

        for obj in newsletters_to_send:
            obj.status = Newsletter.SENT
            obj.save()

            user_list = iter(obj.get_subscribers())
            counter = itertools.count()
            for user in user_list:
                counter.next()
                try:
                    obj.send(user)
                except Exception, e:
                    print e

            send_report_to_admin(counter.next())
Ejemplo n.º 8
0
    def setUp(self):
        self.n = Newsletter(**self.get_newsletter_kwargs())
        self.n.save()
        try:
            self.n.site.set(get_default_sites())
        except AttributeError:  # Django < 1.10
            self.n.site = get_default_sites()

        self.m = Message(title='Test message',
                         newsletter=self.n,
                         slug='test-message')
        self.m.save()

        self.s = Subscription.objects.create(
            name='Test Name', email='[email protected]',
            newsletter=self.n, subscribed=True
        )
        self.s2 = Subscription.objects.create(
            name='René Luçon', email='[email protected]',
            newsletter=self.n, subscribed=True
        )
Ejemplo n.º 9
0
class SubscribeTestCase(WebTestCase, MailTestCase):

    def setUp(self):
        self.n = Newsletter(title='Test newsletter',
                            slug='test-newsletter',
                            sender='Test Sender',
                            email='[email protected]')
        self.n.save()
        try:
            self.n.site.set(get_default_sites())
        except AttributeError:  # Django < 1.10
            self.n.site = get_default_sites()

        self.subscribe_url = \
            reverse('newsletter_subscribe_request',
                    kwargs={'newsletter_slug': self.n.slug})
        self.subscribe_confirm_url = \
            reverse('newsletter_subscribe_confirm',
                    kwargs={'newsletter_slug': self.n.slug})
        self.subscribe_email_sent_url = \
            reverse('newsletter_activation_email_sent',
                    kwargs={'newsletter_slug': self.n.slug,
                            'action': 'subscribe'})
        self.subscribe_activated_url = \
            reverse('newsletter_action_activated',
                    kwargs={'newsletter_slug': self.n.slug,
                            'action': 'subscribe'})

        self.update_url = \
            reverse('newsletter_update_request',
                    kwargs={'newsletter_slug': self.n.slug})
        self.update_email_sent_url = \
            reverse('newsletter_activation_email_sent',
                    kwargs={'newsletter_slug': self.n.slug,
                            'action': 'update'})
        self.update_activated_url = \
            reverse('newsletter_action_activated',
                    kwargs={'newsletter_slug': self.n.slug,
                            'action': 'update'})

        self.unsubscribe_url = \
            reverse('newsletter_unsubscribe_request',
                    kwargs={'newsletter_slug': self.n.slug})
        self.unsubscribe_confirm_url = \
            reverse('newsletter_unsubscribe_confirm',
                    kwargs={'newsletter_slug': self.n.slug})
        self.unsubscribe_email_sent_url = \
            reverse('newsletter_activation_email_sent',
                    kwargs={'newsletter_slug': self.n.slug,
                            'action': 'unsubscribe'})
        self.unsubscribe_activated_url = \
            reverse('newsletter_action_activated',
                    kwargs={'newsletter_slug': self.n.slug,
                            'action': 'unsubscribe'})

        super(SubscribeTestCase, self).setUp()

    def test_urls(self):
        # TODO: is performing this test in each subclass
        #     of WebSubscribeTestCase really needed?
        self.assertTrue(self.subscribe_url)
        self.assertTrue(self.update_url)
        self.assertTrue(self.unsubscribe_url)
        self.assertTrue(self.subscribe_confirm_url)
        self.assertTrue(self.unsubscribe_confirm_url)
        self.assertTrue(self.subscribe_email_sent_url)
        self.assertTrue(self.update_email_sent_url)
        self.assertTrue(self.unsubscribe_email_sent_url)
        self.assertTrue(self.subscribe_activated_url)
        self.assertTrue(self.update_activated_url)
        self.assertTrue(self.unsubscribe_activated_url)
Ejemplo n.º 10
0
 def test_slug_based_on_name(self):
     newsletter = Newsletter(name="MaxFax 2015-1")
     newsletter.save()
     self.assertEqual(newsletter.slug, slugify("MaxFax 2015-1"))