Example #1
0
def email_commitments(fm_em, to_em, nb_wl, ds_wl):
    msg = EmailMultiAlternatives(
        subject=subject,
        from_email=fm_em,
        to=to_em,
    )
    msg.global_merge_vars = {
        'nb_wl': nb_wl,
        'ds_wl': ds_wl,
    }
    msg.template_name = "simple_notifications"
    msg.send()

    response_f = {}
    response_m = msg.mandrill_response[0]
    response_f = response_m
    if response_f['status'] == 'sent':
        print 'mensaje enviado con exito'
    else:
        print 'error enviando el mensaje'
Example #2
0
def email_commitments(fm_em, to_em, nb_wl, ds_wl):
    msg = EmailMultiAlternatives(
        subject=subject,
        from_email=fm_em,
        to=to_em,
    )
    msg.global_merge_vars = {
        'nb_wl': nb_wl,
        'ds_wl': ds_wl,
    }
    msg.template_name = "simple_notifications"
    msg.send()

    response_f = {}
    response_m = msg.mandrill_response[0]
    response_f = response_m
    if response_f['status'] == 'sent':
        print 'mensaje enviado con exito'
    else:
        print 'error enviando el mensaje'
Example #3
0
    def handle(self, *args, **options):
        #context = self.get_context_data(**kwargs)

        members = Member.objects.exclude(status='inactive').exclude(status='pending')
        check = []
        notify = []
        today = date.today()


        self.stdout.write('DEBUG: %s' % settings.DEBUG)

        for m in members:
            d = today - m.last_activity
            self.stdout.write('%s = %i' % (m.user.username, d.days))
            #import ipdb; ipdb.set_trace()
            if (d.days > 60) & (m.status != 'unknown') & (d.days < 181):
                m.status = 'unknown'
                m.save()
                check.append(m)
                self.stdout.write('Pedir validacion (%i dias): "%s"' % (d.days, m.user.username))

            elif d.days > 180:
                notify.append(m)
                self.stdout.write('Notificar a gerencia (180 dias): "%s"' % m.user.username)

        # Send emails to user that need to validate their data
        for c in check:

            mail_to = settings.ADMIN_EMAIL if settings.DEBUG else c.user.email

            msg = EmailMultiAlternatives(
                to = [mail_to],
                from_email = settings.FROM_EMAIL
            )
            groups = []
            for g in c.groups.all():
                groups.append(g.name)
            groups = ', '.join(g for g in groups)

            emails = [c.user.email]
            for e in c.secondary_emails.all():
                emails.append(e.email)
            emails = ', '.join(e for e in emails)


            msg.tags = ["iniciador", "check", today]
            msg.template_name = "checkeo-iniciador"
            msg.global_merge_vars = {
                'NAME': c.user.first_name,
                'GROUPS': groups,
                'EMAIL': emails,
                'PHONE': c.phone,
                'WEBSITE': settings.SERVER,
                'LINK': 'http://' + settings.SERVER + '/members/revision/' + c.user.username,
                'HASH': hashlib.sha224(str(c.last_activity) + str(c.user.id)).hexdigest()
            }

            msg.send()
            response = msg.mandrill_response[0]
            mandrill_id = response['_id']

        #TODO: Terminar la notificacion a la organizacion
        for n in notify:
            mail_to = settings.ADMIN_EMAIL if settings.DEBUG else n.user.email

            msg = EmailMultiAlternatives(
                to = [mail_to],
                from_email = settings.FROM_EMAIL
            )
            groups = []
            for g in n.groups.all():
                groups.append(g.name)
            groups = ', '.join(g for g in groups)

            emails = [n.user.email]
            for e in n.secondary_emails.all():
                emails.append(e.email)
            emails = ', '.join(e for e in emails)
            msg.tags = ["iniciador", "notify", today]
            msg.template_name = "notificar-organizador-no-responde"           # A Mandrill template name
            msg.global_merge_vars = {                        # Content blocks to fill in
                'NAME': n.user.first_name,
                'LASTNAME': n.user.last_name,
                'GROUPS': groups,
                'EMAIL': emails,
                'PHONE': n.phone,
                'WEBSITE': settings.SERVER,
                'LINK': 'http://' + settings.SERVER + '/members/revision/' + n.user.username,
                'HASH': hashlib.sha224(str(n.last_activity) + str(n.user.id)).hexdigest()
            }

            msg.send()
            response = msg.mandrill_response[0]
            mandrill_id = response['_id']

        #context['notified'] = notify
        #context['checked'] = check

        #self.stdout.write('Notificado los miembros "%s"' % poll_id)
        self.stdout.write('Notificados los miembros')
Example #4
0
    def save(self):

        data = self.cleaned_data
        
        u = User.objects.create(
            email = data.get("primary_email"),
            first_name = data.get("first_name"),
            last_name = data.get("last_name"),
            username = data.get("primary_email").split("@")[0][:30],
        )
        password = User.objects.make_random_password()
        u.set_password(password)
        u.save()

        m = Member.objects.create(
            user = u,
            bio = data.get('bio'),
            phone = data.get('phone'),
            role = data.get('role'),
            status = 'pending',
            photo = data.get('photo')
        )

        #import ipdb; ipdb.set_trace()
        groups = data.get("groups")

        for g in groups:
            g = Group.objects.get(name = g)
            m.groups.add(g)

        emails = data.get('secondary_emails');
        if emails:
            for e in emails.split(','):
                e, created = Email.objects.get_or_create(email = e.strip())
                m.secondary_emails.add(e)

        linkedin = data.get('linkedin')
        l, created = Profile.objects.get_or_create(url = linkedin, network = 'linkedin')
        m.profiles.add(l)

        twitter = data.get('twitter')
        t, created = Profile.objects.get_or_create(url = twitter, network = 'twitter')
        m.profiles.add(t)

        # Send mail to user
        #import ipdb; ipdb.set_trace()
        mail_to = settings.ADMIN_EMAIL if settings.DEBUG else data.get("primary_email")

        msg = EmailMultiAlternatives(
            subject = "Solicitud de alta",
            from_email = settings.FROM_EMAIL,
            to = [mail_to]
        )
        msg.tags = ["iniciador", "alta"]
        msg.metadata = {'user_id': m.id}
        msg.template_name = "alta-iniciador"
        msg.global_merge_vars = {
            'NAME': data.get("first_name"),
            'PASSWORD': password,
            'USERNAME': data.get("primary_email").split("@")[0][:30],
            #'WEBSITE': "<a href='" + data.get('linkedin') + "/*|TRACKINGNO|*'>Linkedin</a>"
        }
        print "Mail sent to:" + mail_to
        msg.send()

        # Send mail to iniciador
        mail_to = settings.ADMIN_EMAIL if settings.DEBUG else settings.FROM_EMAIL

        msg = EmailMultiAlternatives(
            subject = "Nueva solicitud de alta",
            from_email = settings.FROM_EMAIL,
            to = [mail_to]
        )
        msg.tags = ["iniciador", "alta", "gerencia", "user-" + str(m.id)]
        msg.metadata = {'user_id': m.id}
        msg.template_name = "aviso-a-gerencia-alta"
        msg.global_merge_vars = {
            'NAME': data.get("first_name"),
            'LASTNAME': data.get("last_name"),
            'UID': m.id,
            'SERVER': settings.SERVER,
            #'WEBSITE': "<a href='" + data.get('linkedin') + "/*|TRACKINGNO|*'>Linkedin</a>"
        }
        print "Mail sent to:" + mail_to
        msg.send()