Example #1
0
    def handle(self, *args, **kwargs):
        days_diff = 1
        post_list = {}
        post_list['posts'] = list()

        for post in Post.objects.filter(date_created__gte=datetime.now() -
                                        timedelta(days=days_diff)):
            context = {}
            context['title'] = post.title
            context['url'] = "http://fun.mitaka-g.net/post/" + str(
                post.pk) + "/" + post.slug + "/"
            post_list['posts'].append(context)

        if len(post_list['posts']) == 0:
            return

        template = read_template(
            '/home/django/projects/fun/core/templates/core/post_digest_email.txt'
        )

        for author in Author.objects.filter(
                Q(receive_update=2) & Q(is_active=True)):
            send_gearman_mail('Daily digest for fun.mitaka-g.net',
                              template.render(Context(post_list)),
                              '*****@*****.**', [author.email],
                              fail_silently=False,
                              auth_user=settings.MANDRILL_USER,
                              auth_password=settings.MANDRILL_API_KEY,
                              host=settings.MANDRILL_HOST)
Example #2
0
File: models.py Project: mitaka/fun
    def save(self, *args, **kwargs):
        created = False
        if self.pk is None:
            created = True

        if self.slug == '':
            self.slug = slugify(unidecode(self.title[:255]))

        super(Post, self).save(*args, **kwargs)

        if not settings.DEBUG:
            try:
                ping_google(sitemap_url='/sitemap.xml')
            except Exception():
                pass

        if created:
            context = {
                "title": self.title,
                "url": "http://fun.mitaka-g.net/post/" + str(self.pk) + "/" + self.slug + "/",
                "content": self.content,
                "author": self.author
            }

            for author in Author.objects.filter(~Q(pk=self.author.pk) & Q(is_active=True)):
                if author.receive_update == 1:
                    logger.info("Sending notification via email to %s", author.email)
                    template = read_template('/home/django/projects/fun/core/templates/core/post_email.txt')
                    send_gearman_mail('New post on fun.mitaka-g.net', template.render(Context(context)), '*****@*****.**', [author.email], fail_silently=False, auth_user=settings.MANDRILL_USER, auth_password=settings.MANDRILL_API_KEY, host=settings.MANDRILL_HOST)
                elif author.receive_update == 3:
                    logger.info("Sending notification via jabber to %s", author.jabber_contact)
                    template = read_template('/home/django/projects/fun/core/templates/core/post_jabber.txt', replace_newlines=False)
                    send_gearman_jabber(template.render(Context(context)), author.jabber_contact)
Example #3
0
File: admin.py Project: mitaka/fun
def send_newsletters(modeladmin, request, queryset):
    for letter in queryset:
        context = {
            'subject': letter.subject,
            'content': letter.content,
        }
        template = read_template("/home/django/projects/fun/core/templates/core/post_newsletter_email.txt")
        for author in Author.objects.filter(newsletter=True):
            send_gearman_mail(letter.subject, template.render(Context(context)), '*****@*****.**', [author.email], fail_silently=False, auth_user=settings.MANDRILL_USER, auth_password=settings.MANDRILL_API_KEY, host=settings.MANDRILL_HOST)
            queryset.update(sent=True)
Example #4
0
File: models.py Project: mitaka/fun
    def save(self, *args, **kwargs):
        created = False
        if self.pk is None:
            created = True

        if self.slug == '':
            self.slug = slugify(unidecode(self.title[:255]))

        super(Post, self).save(*args, **kwargs)

        if not settings.DEBUG:
            try:
                ping_google(sitemap_url='/sitemap.xml')
            except Exception():
                pass

        if created:
            context = {
                "title":
                self.title,
                "url":
                "http://fun.mitaka-g.net/post/" + str(self.pk) + "/" +
                self.slug + "/",
                "content":
                self.content,
                "author":
                self.author
            }

            for author in Author.objects.filter(~Q(pk=self.author.pk)
                                                & Q(is_active=True)):
                if author.receive_update == 1:
                    logger.info("Sending notification via email to %s",
                                author.email)
                    template = read_template(
                        '/home/django/projects/fun/core/templates/core/post_email.txt'
                    )
                    send_gearman_mail('New post on fun.mitaka-g.net',
                                      template.render(Context(context)),
                                      '*****@*****.**',
                                      [author.email],
                                      fail_silently=False,
                                      auth_user=settings.MANDRILL_USER,
                                      auth_password=settings.MANDRILL_API_KEY,
                                      host=settings.MANDRILL_HOST)
                elif author.receive_update == 3:
                    logger.info("Sending notification via jabber to %s",
                                author.jabber_contact)
                    template = read_template(
                        '/home/django/projects/fun/core/templates/core/post_jabber.txt',
                        replace_newlines=False)
                    send_gearman_jabber(template.render(Context(context)),
                                        author.jabber_contact)
Example #5
0
def post_save_user(sender, instance, created, **kwargs):
    context = {"user": instance.username, "email": instance.email}

    if created:
        template = read_template(
            'core/templates/registration/registration_email.txt')
        send_gearman_mail('User registration',
                          template.render(Context(context)),
                          '*****@*****.**', [settings.ADMIN_EMAIL],
                          fail_silently=False,
                          auth_user=settings.MANDRILL_USER,
                          auth_password=settings.MANDRILL_API_KEY,
                          host=settings.MANDRILL_HOST)
Example #6
0
 def handle(self, *args, **kwargs):
     for nl in NewsLetter.objects.filter(sent=False):
         context = {"subject": nl.subject, "content": nl.content}
         template = read_template(
             '/home/django/projects/fun/core/templates/core/post_newsletter_email.txt'
         )
         for author in Author.objects.all():
             send_gearman_mail(nl.subject,
                               template.render(Context(context)),
                               '*****@*****.**', [author.email],
                               fail_silently=False,
                               auth_user=settings.MANDRILL_USER,
                               auth_password=settings.MANDRILL_API_KEY,
                               host=settings.MANDRILL_HOST)
             nl.date_sent = timezone.now()
             nl.sent = True
             nl.save()
Example #7
0
def send_newsletters(modeladmin, request, queryset):
    for letter in queryset:
        context = {
            'subject': letter.subject,
            'content': letter.content,
        }
        template = read_template(
            "/home/django/projects/fun/core/templates/core/post_newsletter_email.txt"
        )
        for author in Author.objects.filter(newsletter=True):
            send_gearman_mail(letter.subject,
                              template.render(Context(context)),
                              '*****@*****.**', [author.email],
                              fail_silently=False,
                              auth_user=settings.MANDRILL_USER,
                              auth_password=settings.MANDRILL_API_KEY,
                              host=settings.MANDRILL_HOST)
            queryset.update(sent=True)
Example #8
0
    def handle(self, *args, **kwargs):
        days_diff = 1
        post_list = {}
        post_list['posts'] = list()

        for post in Post.objects.filter(date_created__gte=datetime.now()-timedelta(days=days_diff)):
            context = {}
            context['title'] = post.title
            context['url'] = "http://fun.mitaka-g.net/post/" + str(post.pk) + "/" + post.slug + "/"
            post_list['posts'].append(context)

        if len(post_list['posts']) == 0:
            return

        template = read_template('/home/django/projects/fun/core/templates/core/post_digest_email.txt')

        for author in Author.objects.filter(Q(receive_update=2) & Q(is_active=True)):
            send_gearman_mail('Daily digest for fun.mitaka-g.net', template.render(Context(post_list)), '*****@*****.**', [author.email], fail_silently=False, auth_user=settings.MANDRILL_USER, auth_password=settings.MANDRILL_API_KEY, host=settings.MANDRILL_HOST)
Example #9
0
def post_save_user(sender, instance, created, **kwargs):
    context = {"user": instance.username, "email": instance.email}

    if created:
        template = read_template('core/templates/registration/registration_email.txt')
        send_gearman_mail('User registration', template.render(Context(context)), '*****@*****.**', [settings.ADMIN_EMAIL], fail_silently=False, auth_user=settings.MANDRILL_USER, auth_password=settings.MANDRILL_API_KEY, host=settings.MANDRILL_HOST)