Exemplo n.º 1
0
def sendmail(request):
    authenticate_backend_group(request, 'Membership administrators')

    if request.method == 'POST':
        idlist = list(map(int, request.POST['idlist'].split(',')))
    else:
        idlist = list(map(int, request.GET['idlist'].split(',')))

    cfg = get_config()

    recipients = Member.objects.filter(pk__in=idlist)

    initial = {
        '_from':
        '{0} <{1}>'.format(settings.ORG_NAME, cfg.sender_email),
        'recipients':
        escape(", ".join([
            '{0} <{1}>'.format(x.fullname, x.user.email) for x in recipients
        ])),
        'idlist':
        ",".join(map(str, idlist)),
    }

    if request.method == 'POST':
        p = request.POST.copy()
        p['recipients'] = initial['recipients']
        form = BackendMemberSendEmailForm(data=p, initial=initial)
        if form.is_valid():
            with transaction.atomic():
                for r in recipients:
                    msgtxt = "{0}\n\n-- \nThis message was sent to members of {1}\n".format(
                        form.cleaned_data['message'], settings.ORG_NAME)
                    send_simple_mail(
                        cfg.sender_email,
                        r.user.email,
                        form.cleaned_data['subject'],
                        msgtxt,
                        sendername=settings.ORG_NAME,
                        receivername=r.fullname,
                    )
                messages.info(request,
                              "Email sent to %s attendees" % len(recipients))

            return HttpResponseRedirect("../")
    else:
        form = BackendMemberSendEmailForm(initial=initial)

    return render(
        request, 'confreg/admin_backend_form.html', {
            'basetemplate': 'adm/admin_base.html',
            'form': form,
            'what': 'new email',
            'savebutton': 'Send email',
            'cancelurl': '../',
            'breadcrumbs': [
                ('../', 'Members'),
            ],
        })
Exemplo n.º 2
0
    def handle(self, *args, **options):
        cfg = get_config()

        # Expire members (and let them know it happened)
        expired = Member.objects.filter(paiduntil__lt=datetime.now())
        for m in expired:
            MemberLog(member=m,
                      timestamp=datetime.now(),
                      message='Membership expired').save()
            # Generate an email to the user
            send_template_mail(
                cfg.sender_email,
                m.user.email,
                "Your {0} membership has expired".format(settings.ORG_NAME),
                'membership/mail/expired.txt',
                {
                    'member': m,
                },
            )
            self.stdout.write("Expired member {0} (paid until {1})".format(
                m, m.paiduntil))
            # An expired member has no membersince and no paiduntil.
            m.membersince = None
            m.paiduntil = None
            m.save()

        # Send warnings to members about to expire. We explicitly avoid sending
        # a warning in the last 24 hours before expire, so we don't end up sending
        # both a warning and an expiry within minutes in case the cronjob runs on
        # slightly different times.

        warning = Member.objects.filter(
            Q(paiduntil__gt=datetime.now() - timedelta(days=1))
            & Q(paiduntil__lt=datetime.now() + timedelta(days=30))
            & (Q(expiry_warning_sent__lt=datetime.now() - timedelta(days=10))
               | Q(expiry_warning_sent__isnull=True)))
        for m in warning:
            MemberLog(member=m,
                      timestamp=datetime.now(),
                      message='Membership expiry warning sent to %s' %
                      m.user.email).save()
            # Generate an email to the user
            send_template_mail(
                cfg.sender_email,
                m.user.email,
                "Your {0} membership will expire soon".format(
                    settings.ORG_NAME),
                'membership/mail/warning.txt',
                {
                    'member': m,
                },
            )
            self.stdout.write(
                "Sent warning to member {0} (paid until {1}, last warned {2})".
                format(m, m.paiduntil, m.expiry_warning_sent))
            m.expiry_warning_sent = datetime.now()
            m.save()
Exemplo n.º 3
0
    def handle(self, *args, **options):
        cfg = get_config()

        for r in MeetingReminder.objects.select_related('meeting').filter(
                sentat__isnull=True, sendat__lte=timezone.now()):
            for a in r.meeting.get_all_attendees().select_related('user'):
                send_template_mail(
                    cfg.sender_email,
                    a.user.email,
                    "Upcoming meeting: {}".format(r.meeting.name),
                    'membership/mail/meeting_reminder.txt',
                    {
                        'meeting': r.meeting,
                        'member': a,
                    },
                    sendername=cfg.sender_name,
                    receivername=a.fullname,
                )
            r.sentat = timezone.now()
            r.save()
Exemplo n.º 4
0
def sendmail(request):
    authenticate_backend_group(request, 'Membership administrators')

    cfg = get_config()

    if request.method == 'POST':
        idl = request.POST['idlist']
    else:
        idl = request.GET['idlist']

    if idl == 'allactive':
        recipients = list(Member.objects.filter(paiduntil__gte=today_global()))
        idlist = [m.user_id for m in recipients]
    else:
        idlist = list(map(int, idl.split(',')))
        recipients = Member.objects.filter(pk__in=idlist)

    initial = {
        '_from':
        '{0} <{1}>'.format(cfg.sender_name, cfg.sender_email),
        'recipients':
        escape(", ".join([
            '{0} <{1}>'.format(x.fullname, x.user.email) for x in recipients
        ])),
        'idlist':
        idl,
    }

    if request.method == 'POST':
        p = request.POST.copy()
        p['recipients'] = initial['recipients']
        form = BackendMemberSendEmailForm(data=p, initial=initial)
        if form.is_valid():
            with transaction.atomic():
                msgtxt = "{0}\n\n-- \nThis message was sent to members of {1}\n".format(
                    form.cleaned_data['message'], settings.ORG_NAME)
                mail = MemberMail(
                    sentat=timezone.now(),
                    sentfrom="{} <{}>".format(cfg.sender_name,
                                              cfg.sender_email),
                    subject=form.cleaned_data['subject'],
                    message=msgtxt,
                )
                mail.save()
                mail.sentto.set(recipients)

                for r in recipients:
                    send_simple_mail(
                        cfg.sender_email,
                        r.user.email,
                        form.cleaned_data['subject'],
                        msgtxt,
                        sendername=cfg.sender_name,
                        receivername=r.fullname,
                    )
                messages.info(request,
                              "Email sent to %s members" % len(recipients))

            return HttpResponseRedirect('/admin/membership/emails/')
    else:
        form = BackendMemberSendEmailForm(initial=initial)

    return render(
        request, 'confreg/admin_backend_form.html', {
            'basetemplate': 'adm/admin_base.html',
            'form': form,
            'what': 'new email',
            'savebutton': 'Send email',
            'cancelurl':
            '/admin/membership/emails/' if idl == 'allactive' else '../',
            'breadcrumbs': [
                ('../', 'Members'),
            ],
        })