示例#1
0
def _send_contact_emails(contact):
    """Send an email to a visitor who submitted a contact form; email brothers who want to be notified.

    Required parameters:
        - contact   =>  the contact record for which to email

    """
    date = contact.created.strftime('%B %d, %Y at %I:%M %p')
    # message to the person who submitted the information card
    message = EmailMessage(get_message('email.contact.subject'),
                           get_message('email.contact.body',
                                       args=(contact.name, date,
                                             contact.to_string())),
                           to=[contact.email])
    # message to the webmaster and everyone who has selected to be notified about new contact forms
    notification = EmailMessage(get_message('notify.contact.subject'),
                                get_message('notify.contact.body',
                                            args=(date, contact.to_string())),
                                to=['*****@*****.**'],
                                bcc=UserProfile.all_emails_with_bit(
                                    STATUS_BITS['EMAIL_NEW_CONTACT']))
    # open a connection to the SMTP backend so we can send two messages over the same connection
    conn = get_connection()
    conn.open()
    conn.send_messages([message, notification])
    conn.close()
示例#2
0
def _send_info_card_emails(card):
    """Send an email thanking a potential for submitting an information card; email brothers who want to be notified.

    Required parameters:
        - card  =>  the information card about which to email

    """
    date = card.created.strftime('%B %d, %Y at %I:%M %p')
    # message to the person who submitted the information card
    message = EmailMessage(get_message('email.infocard.subject'),
                           get_message('email.infocard.body',
                                       args=(card.name, date,
                                             card.to_string())),
                           to=[card.email])
    # message to the Membership Chair and everyone who has selected to be notified about new info cards
    notification = EmailMessage(
        get_message('notify.infocard.subject'),
        get_message('notify.infocard.body',
                    args=(date, card.to_string(), settings.URI_PREFIX)),
        to=['*****@*****.**'],
        bcc=UserProfile.all_emails_with_bit(STATUS_BITS['EMAIL_NEW_INFOCARD']))
    # open a connection to the SMTP backend so we can send two messages over the same connection
    conn = get_connection()
    conn.open()
    conn.send_messages([message, notification])
    conn.close()
示例#3
0
def _send_info_card_emails(card):
    """Send an email thanking a potential for submitting an information card; email brothers who want to be notified.

    Required parameters:
        - card  =>  the information card about which to email

    """
    date = card.created.strftime('%B %d, %Y at %I:%M %p')
    # message to the person who submitted the information card
    message = EmailMessage(get_message('email.infocard.subject'),
                           get_message('email.infocard.body', args=(card.name, date, card.to_string())), to=[card.email])
    # message to the Membership Chair and everyone who has selected to be notified about new info cards
    notification = EmailMessage(get_message('notify.infocard.subject'),
                                get_message('notify.infocard.body', args=(date, card.to_string(), settings.URI_PREFIX)),
                                to=['*****@*****.**'],
                                bcc=UserProfile.all_emails_with_bit(STATUS_BITS['EMAIL_NEW_INFOCARD']))
    # open a connection to the SMTP backend so we can send two messages over the same connection
    conn = get_connection()
    conn.open()
    conn.send_messages([message, notification])
    conn.close()
示例#4
0
def _send_contact_emails(contact):
    """Send an email to a visitor who submitted a contact form; email brothers who want to be notified.

    Required parameters:
        - contact   =>  the contact record for which to email

    """
    date = contact.created.strftime('%B %d, %Y at %I:%M %p')
    # message to the person who submitted the information card
    message = EmailMessage(get_message('email.contact.subject'),
                           get_message('email.contact.body', args=(contact.name, date, contact.to_string())),
                           to=[contact.email])
    # message to the webmaster and everyone who has selected to be notified about new contact forms
    notification = EmailMessage(get_message('notify.contact.subject'),
                                get_message('notify.contact.body', args=(date, contact.to_string())),
                                to=['*****@*****.**'],
                                bcc=UserProfile.all_emails_with_bit(STATUS_BITS['EMAIL_NEW_CONTACT']))
    # open a connection to the SMTP backend so we can send two messages over the same connection
    conn = get_connection()
    conn.open()
    conn.send_messages([message, notification])
    conn.close()
示例#5
0
def add_announcement(request):
    """Render and process a form to create a new announcement.

    This function will email all users who have elected to be notified of new announcements and also all potentials
    who have submitted information cards and elected to subscribe to chapter updates.

    """
    log_page_view(request, "Add Announcement")
    if request.method == "POST":
        form = AnnouncementForm(request.POST)
        if form.is_valid():
            announcement = form.save(commit=False)
            announcement.user = request.user
            announcement.save()
            recipients = UserProfile.all_emails_with_bit(STATUS_BITS["EMAIL_NEW_ANNOUNCEMENT"])
            if announcement.public:
                recipients += InformationCard.all_subscriber_emails()
            date = "" if announcement.date is None else "[%s] " % announcement.date.strftime("%B %d, %Y")
            message = EmailMessage(
                _("notify.announcement.subject"),
                _(
                    "notify.announcement.body",
                    args=(announcement.user.get_profile().common_name(), date, announcement.text, settings.URI_PREFIX),
                ),
                to=["*****@*****.**"],
                bcc=recipients,
            )
            message.send()
            log.info(
                "%s (%s) added a new announcement: '%s'",
                request.user.username,
                request.user.get_full_name(),
                announcement.text,
            )
            return HttpResponseRedirect(reverse("announcements"))
    else:
        form = AnnouncementForm()
    return render(request, "chapter/add_announcement.html", {"form": form}, context_instance=RequestContext(request))
示例#6
0
def add_announcement(request):
    """Render and process a form to create a new announcement.

    This function will email all users who have elected to be notified of new announcements and also all potentials
    who have submitted information cards and elected to subscribe to chapter updates.

    """
    log_page_view(request, 'Add Announcement')
    if request.method == 'POST':
        form = AnnouncementForm(request.POST)
        if form.is_valid():
            announcement = form.save(commit=False)
            announcement.user = request.user
            announcement.save()
            recipients = UserProfile.all_emails_with_bit(
                STATUS_BITS['EMAIL_NEW_ANNOUNCEMENT'])
            if announcement.public:
                recipients += InformationCard.all_subscriber_emails()
            date = ('' if announcement.date is None else '[%s] ' %
                    announcement.date.strftime('%B %d, %Y'))
            message = EmailMessage(
                _('notify.announcement.subject'),
                _('notify.announcement.body',
                  args=(announcement.user.get_profile().common_name(), date,
                        announcement.text, settings.URI_PREFIX)),
                to=['*****@*****.**'],
                bcc=recipients)
            message.send()
            log.info('%s (%s) added a new announcement: \'%s\'',
                     request.user.username, request.user.get_full_name(),
                     announcement.text)
            return HttpResponseRedirect(reverse('announcements'))
    else:
        form = AnnouncementForm()
    return render(request,
                  'chapter/add_announcement.html', {'form': form},
                  context_instance=RequestContext(request))