Beispiel #1
0
def putWeekReport(report, newsletter):

    # if nothing changed, nothing to report, moving on.
    if report['db_changes'] == None and report['discussion'] == None and report['characteristic'] == None:
        return

    now = timezone.now()

    mess = Message(title=newsletter.title+" - Recent Changes - "+now.strftime("%Y-%m-%d %H:%M"),slug=newsletter.slug+'_'+now.strftime("%Y%m%d%H%M%S"), newsletter=newsletter)
    mess.save()

    if report['db_changes'] != None:
        art = Article(title="Changes on Database:", text=report['db_changes'], post=mess)
        art.save()

    if report['discussion'] != None:
        art2 = Article(title="New Discussion:", text=report['discussion'], post=mess)
        art2.save()

    if report['characteristic'] != None:
        art3 = Article(title="New Population Characteristic Data:", text=report['characteristic'], post=mess)
        art3.save()

    subm = Submission.from_message(mess)

    subm.prepared = True

    subm.save()
Beispiel #2
0
def send_newsletter(post_id):
    post = Post.objects.get(pk=post_id)
    if not post.notified:
        print("send_newsletter activated")
        site = Site.objects.all()[0]

        newsletter = Newsletter.objects.all()[0]
        submission = Submission()
        message = Message()
        article = Article()
        article.url = "http://{}{}".format(site.domain, post.get_absolute_url())
        article.title = post.title
        article.sortorder = 0

        message.title = post.title
        message.newsletter = newsletter
        message.slug = post.slug
        message.save()
        message.articles.add(article, bulk=False)
        message.save()
        article.save()

        submission.newsletter = newsletter
        submission.message = message
        submission.save()
        for s in newsletter.get_subscriptions():
            submission.subscriptions.add(s)
        submission.save()

        submission.submit()
        Submission.submit_queue()
        post.notified = True
        post.save()
        print("send_newsletter submitted")
Beispiel #3
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)
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)
def putWeekReport(report, newsletter):

    # if nothing changed, nothing to report, moving on.
    if report['db_changes'] == None and report[
            'discussion'] == None and report['characteristic'] == None:
        return

    now = timezone.now()

    mess = Message(title=newsletter.title + " - Recent Changes - " +
                   now.strftime("%Y-%m-%d %H:%M"),
                   slug=newsletter.slug + '_' + now.strftime("%Y%m%d%H%M%S"),
                   newsletter=newsletter)
    mess.save()

    if report['db_changes'] != None:
        art = Article(title="Changes on Database:",
                      text=report['db_changes'],
                      post=mess)
        art.save()

    if report['discussion'] != None:
        art2 = Article(title="New Discussion:",
                       text=report['discussion'],
                       post=mess)
        art2.save()

    if report['characteristic'] != None:
        art3 = Article(title="New Population Characteristic Data:",
                       text=report['characteristic'],
                       post=mess)
        art3.save()

    subm = Submission.from_message(mess)

    subm.prepared = True

    subm.save()