Пример #1
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.a = Attachment.objects.create(
            file=os.path.join('tests', 'files', 'sample.pdf'),
            message=self.m
        )

        self.s = Subscription.objects.create(
            name='Test Name', email='*****@*****.**',
            newsletter=self.n, subscribed=True
        )
        self.s2 = Subscription.objects.create(
            name='René Luçon', email='*****@*****.**',
            newsletter=self.n, subscribed=True
        )
Пример #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': '*****@*****.**'
        }

    def get_newsletter_sites(self):
        return get_default_sites()

    def get_site(self) -> Site:
        return Site.objects.get_current()

    def setUp(self):
        self.n = Newsletter(**self.get_newsletter_kwargs())
        self.n.save()
        self.n.site.set(self.get_newsletter_sites())

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

        self.a = Attachment.objects.create(file=os.path.join(
            'tests', 'files', 'sample.pdf'),
                                           message=self.m)

        self.s = Subscription.objects.create(name='Test Name',
                                             email='*****@*****.**',
                                             newsletter=self.n,
                                             subscribed=True)
        self.s2 = Subscription.objects.create(name='René Luçon',
                                              email='*****@*****.**',
                                              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, Site.objects.get_current())
            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(Site.objects.get_current(),
                                                 action)
Пример #3
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('/')
Пример #4
0
    def setUp(self):
        self.n = Newsletter(title='Test newsletter',
                            slug='test-newsletter',
                            sender='Test Sender',
                            email='*****@*****.**')
        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()
Пример #5
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
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': '*****@*****.**'
        }

    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='*****@*****.**',
            newsletter=self.n, subscribed=True
        )
        self.s2 = Subscription.objects.create(
            name='René Luçon', email='*****@*****.**',
            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)
Пример #7
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='*****@*****.**',
                              newsletter=self.n,
                              subscribed=True)
        self.s.save()
Пример #8
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
Пример #9
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
Пример #10
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
Пример #11
0
    def setUp(self):
        self.n = Newsletter(title='Test newsletter',
                            slug='test-newsletter',
                            sender='Test Sender',
                            email='*****@*****.**')
        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()
Пример #12
0
    def test_newsletter_label_name(self):
        """ Test that _meta returns correct app_label and model_name. """
        self.assertEqual(Newsletter._meta.app_label, 'newsletter')
        self.assertEqual(Newsletter._meta.model_name, 'newsletter')

        obj = Newsletter()
        self.assertEqual(obj._meta.app_label, 'newsletter')
        self.assertEqual(obj._meta.model_name, 'newsletter')

        custom_obj = CustomNewsletter()
        self.assertEqual(custom_obj._meta.app_label, 'name_of_my_app')
        self.assertEqual(custom_obj._meta.model_name, 'customnewsletter')
Пример #13
0
def create_event(request):
    ''' A view where staff and superuser can create new events '''
    if not (request.user.is_staff or request.user.is_superuser):
        return redirect('/')
    form = EventForm(request.POST or None, request.FILES or None)
    if form.is_valid():
        event = form.save(commit=False)
        event.organizer = request.user
        event.save()
        messages.success(request, f"New event created: {form.cleaned_data.get('name')}")
        event_name = form.cleaned_data.get('name')
        event = get_object_or_404(Event, name=event_name)
        new_slug = event_name.lower()
        new_slug = re.sub(r'[\s]', '-', new_slug)  # Replace all spaces with dash.
        new_slug = re.sub(r'[^\w|-]', '', new_slug)  # Remove all non alphabetic characters except dash.
        newsletter = Newsletter(title=event_name, slug=new_slug, email="*****@*****.**", sender="Eventify")
        newsletter.save()
        return redirect(event)

    form = EventForm()
    context = {
        'form': form
    }
    return render(request, "main/create_event.html", context)
Пример #14
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='*****@*****.**',
            newsletter=self.n, subscribed=True
        )
        self.s.save()
Пример #15
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())
Пример #16
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='*****@*****.**',
            newsletter=self.n, subscribed=True
        )
        self.s2 = Subscription.objects.create(
            name='René Luçon', email='*****@*****.**',
            newsletter=self.n, subscribed=True
        )
Пример #17
0
    def addSubscriber(self):

        return Newsletter.addSubscriber(self.cleaned_data)
Пример #18
0
class SubscribeTestCase(WebTestCase, MailTestCase):

    def setUp(self):
        self.n = Newsletter(title='Test newsletter',
                            slug='test-newsletter',
                            sender='Test Sender',
                            email='*****@*****.**')
        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)
Пример #19
0
 def test_slug_based_on_name(self):
     newsletter = Newsletter(name="MaxFax 2015-1")
     newsletter.save()
     self.assertEqual(newsletter.slug, slugify("MaxFax 2015-1"))
Пример #20
0
class SubscribeTestCase(WebTestCase, MailTestCase):
    def setUp(self):
        self.n = Newsletter(title='Test newsletter',
                            slug='test-newsletter',
                            sender='Test Sender',
                            email='*****@*****.**')
        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)
Пример #21
0
 def test_slug_based_on_name(self):
     newsletter = Newsletter(name="MaxFax 2015-1")
     newsletter.save()
     self.assertEqual(newsletter.slug, slugify("MaxFax 2015-1"))