Esempio n. 1
0
    def post(self, request, *args, **kwargs):
        ids = request.POST.getlist('selected')
        no_reimb = request.POST.get('no_reimb', False)
        reimbs = models.Reimbursement.objects.filter(pk__in=ids).all()
        mails = []
        errors = 0
        for reimb in reimbs:
            try:

                if not no_reimb:
                    assigned_money = request.POST.get('am_' + str(reimb.pk))
                    reimb.assigned_money = assigned_money
                    reimb.send(request.user)
                    m = emails.create_reimbursement_email(reimb, request)
                else:
                    reimb.no_reimb(request.user)
                    m = emails.create_no_reimbursement_email(reimb, request)
                mails.append(m)
            except ValidationError:
                errors += 1

        if mails:
            send_batch_emails(mails)
            if no_reimb:
                msg = "%s no reimbursements message sent"
            else:
                msg = "%s reimbursements sent"
            messages.success(request, msg % len(mails))
        else:
            messages.error(request, "%s reimbursements not sent" % errors)

        return HttpResponseRedirect(reverse('send_reimbursement'))
    def post(self, request, *args, **kwargs):
        ids = request.POST.getlist('selected')
        no_reimb = request.POST.get('no_reimb', False)
        reimbs = models.Reimbursement.objects.filter(pk__in=ids).all()
        mails = []
        errors = 0
        for reimb in reimbs:
            try:

                if not no_reimb:
                    assigned_money = request.POST.get('am_' + str(reimb.pk))
                    reimb.assigned_money = assigned_money
                    reimb.send(request.user)
                    m = emails.create_reimbursement_email(reimb, request)
                else:
                    reimb.no_reimb(request.user)
                    m = emails.create_no_reimbursement_email(reimb, request)
                mails.append(m)
            except ValidationError:
                errors += 1

        if mails:
            send_batch_emails(mails)
            if no_reimb:
                msg = "%s no reimbursements message sent"
            else:
                msg = "%s reimbursements sent"
            messages.success(request, msg % len(mails))
        else:
            messages.error(request, "%s reimbursements not sent" % errors)

        return HttpResponseRedirect(reverse('send_reimbursement'))
Esempio n. 3
0
    def send(self, request, queryset):
        msgs = []
        sent = 0
        errors = 0
        for reimb in queryset:
            try:
                reimb.send(request.user)
                msgs.append(emails.create_reimbursement_email(reimb, request))
                sent += 1
            except ValidationError as e:
                errors += 1
                logging.error(e.message)

        if msgs:
            connection = mail.get_connection()
            connection.send_messages(msgs)
        if sent > 0 and errors > 0:
            self.message_user(
                request,
                ("%s reimbursements sent, %s reimbursements not sent. Did you "
                 "check that they were invited before and with money assigned?"
                 % (sent, errors)),
                level=messages.WARNING)
        elif sent > 0:
            self.message_user(request,
                              '%s reimbursement sent' % sent,
                              level=messages.SUCCESS)
        else:
            self.message_user(request,
                              'Reimbursement couldn\'t be sent! Did you check '
                              'that app was invited before and with money '
                              'assigned?',
                              level=messages.ERROR)
    def send(self, request, queryset):
        msgs = []
        sent = 0
        errors = 0
        for reimb in queryset:
            try:
                reimb.send(request.user)
                msgs.append(emails.create_reimbursement_email(reimb, request))
                sent += 1
            except ValidationError as e:
                errors += 1
                logging.error(e.message)

        if msgs:
            connection = mail.get_connection()
            connection.send_messages(msgs)
        if sent > 0 and errors > 0:
            self.message_user(request, (
                "%s reimbursements sent, %s reimbursements not sent. Did you "
                "check that they were invited before and with money assigned?"
                % (sent, errors)), level=messages.WARNING)
        elif sent > 0:
            self.message_user(request, '%s reimbursement sent' % sent,
                              level=messages.SUCCESS)
        else:
            self.message_user(request,
                              'Reimbursement couldn\'t be sent! Did you check '
                              'that app was invited before and with money '
                              'assigned?',
                              level=messages.ERROR)