Exemplo n.º 1
0
def send_recent_posts(recipient):

    # Top 5 posts on Codango
    popular_posts = Resource.objects.annotate(
        num_comments=Count('comments')).annotate(
        num_votes=Count('votes')).order_by(
        '-num_comments', '-num_votes')[:5]

    # URL to Codango
    codango_url = "http://localhost:8000{}".format(reverse('index'))

    # Compose the email
    message = SendGrid.compose(
        sender='Codango <{}>'.format(CODANGO_EMAIL),
        recipient=recipient,
        subject="Top Posts on Codango",
        text=None,
        html=loader.get_template(
            'resources/popular-post-updates.html'
        ).render(Context({
            'popular_posts': popular_posts,
            'codango_url': codango_url
        }))
    )

    # send email
    response = SendGrid.send(message)
    logger.info("Sent Codango's top posts")
    return response
Exemplo n.º 2
0
 def setUp(self):
     self.email = SendGrid.compose(
         sender='Codango <*****@*****.**>',
         recipient='*****@*****.**',
         subject='Codango: Password Recovery',
         text="This is a test",
         html=None,
     )