コード例 #1
0
ファイル: mail.py プロジェクト: 4teamwork/seantis.reservation
def send_reservations_confirmed(reservations, language):
    sender = utils.get_site_email_sender()

    if not sender:
        log.warn('Cannot send email as no sender is configured')
        return

    # load resources
    resources = dict()
    for reservation in reservations:

        if not reservation.resource in resources:
            resources[reservation.resource] = utils.get_resource_by_uuid(
                reservation.resource
            ).getObject()

            if not resources[reservation.resource]:
                log.warn('Cannot send email as the resource does not exist')
                return

    # send reservations grouped by reservee email
    groupkey = lambda r: r.email
    by_recipient = groupby(sorted(reservations, key=groupkey), key=groupkey)

    for recipient, grouped_reservations in by_recipient:

        lines = []

        for reservation in grouped_reservations:

            resource = resources[reservation.resource]

            prefix = '' if reservation.autoapprovable else '* '
            lines.append(prefix + utils.get_resource_title(resource))

            for start, end in reservation.timespans():
                lines.append(utils.display_date(start, end))

            lines.append('')

        # differs between resources
        subject, body = get_email_content(
            resource, 'reservation_received', language
        )

        mail = ReservationMail(
            resource, reservation,
            sender=sender,
            recipient=recipient,
            subject=subject,
            body=body,
            reservations=lines[:-1]
        )

        send_mail(resource, mail)
コード例 #2
0
ファイル: mail.py プロジェクト: scott50301/DS-project
def send_reservation_mail(reservations,
                          email_type,
                          language,
                          to_managers=False,
                          reason=u'',
                          old_time=None,
                          new_time=None):

    if isinstance(reservations, CombinedReservations):
        reservation = reservations
    else:
        reservation = tuple(combine_reservations(reservations))[0]

    resource = utils.get_resource_by_uuid(reservation.resource)

    # the resource doesn't currently exist in testing so we quietly
    # exit. This should be changed => #TODO
    if not resource:
        log.warn('Cannot send email as the resource does not exist')
        return

    sender = utils.get_site_email_sender()

    if not sender:
        log.warn('Cannot send email as no sender is configured')
        return

    resource = resource.getObject()

    if to_managers:
        recipients = get_manager_emails(resource)
        if not recipients:
            log.warn("Couldn't find a manager to send an email to")
            return
    else:
        recipients = [reservation.email]

    subject, body = get_email_content(resource, email_type, language)

    for recipient in recipients:
        mail = ReservationMail(resource,
                               reservation,
                               sender=sender,
                               recipient=recipient,
                               subject=subject,
                               body=body,
                               reason=reason,
                               old_time=old_time,
                               new_time=new_time)

        if may_send_mail(resource, mail, intended_for_admin=to_managers):
            send_mail(resource, mail)
コード例 #3
0
ファイル: mail.py プロジェクト: seantis/seantis.reservation
def send_reservation_mail(
    reservations, email_type, language, to_managers=False,
        reason=u'', old_time=None, new_time=None
):

    if isinstance(reservations, CombinedReservations):
        reservation = reservations
    else:
        reservation = tuple(combine_reservations(reservations))[0]

    resource = utils.get_resource_by_uuid(reservation.resource)

    # the resource doesn't currently exist in testing so we quietly
    # exit. This should be changed => #TODO
    if not resource:
        log.warn('Cannot send email as the resource does not exist')
        return

    sender = utils.get_site_email_sender()

    if not sender:
        log.warn('Cannot send email as no sender is configured')
        return

    resource = resource.getObject()

    if to_managers:
        recipients = get_manager_emails(resource)
        if not recipients:
            log.warn("Couldn't find a manager to send an email to")
            return
    else:
        recipients = [reservation.email]

    subject, body = get_email_content(resource, email_type, language)

    for recipient in recipients:
        mail = ReservationMail(
            resource, reservation,
            sender=sender,
            recipient=recipient,
            subject=subject,
            body=body,
            reason=reason,
            old_time=old_time,
            new_time=new_time
        )

        if may_send_mail(resource, mail, intended_for_admin=to_managers):
            send_mail(resource, mail)
コード例 #4
0
ファイル: mail.py プロジェクト: seantis/seantis.reservation
def send_reservations_confirmed(reservations, language):

    sender = utils.get_site_email_sender()

    if not sender:
        log.warn('Cannot send email as no sender is configured')
        return

    # load resources
    resources = load_resources(reservations)

    # send reservations grouped by reservee email
    groupkey = lambda r: r.email
    by_recipient = groupby(sorted(reservations, key=groupkey), key=groupkey)

    for recipient, grouped_reservations in by_recipient:

        lines = []

        for reservation in combine_reservations(grouped_reservations):

            resource = resources[reservation.resource]

            prefix = '' if reservation.autoapprovable else '* '
            title_prefix = '{}x '.format(reservation.quota)
            lines.append(
                prefix + utils.get_resource_title(resource, title_prefix)
            )

            for start, end in reservation.timespans():
                lines.append(utils.display_date(start, end))

            lines.append('')

        # differs between resources
        subject, body = get_email_content(
            resource, 'reservation_received', language
        )

        mail = ReservationMail(
            resource, reservation,
            sender=sender,
            recipient=recipient,
            subject=subject,
            body=body,
            reservations=lines[:-1]
        )

        if may_send_mail(resource, mail, intended_for_admin=False):
            send_mail(resource, mail)
コード例 #5
0
ファイル: mail.py プロジェクト: scott50301/DS-project
def send_reservations_confirmed(reservations, language):

    sender = utils.get_site_email_sender()

    if not sender:
        log.warn('Cannot send email as no sender is configured')
        return

    # load resources
    resources = load_resources(reservations)

    # send reservations grouped by reservee email
    groupkey = lambda r: r.email
    by_recipient = groupby(sorted(reservations, key=groupkey), key=groupkey)

    for recipient, grouped_reservations in by_recipient:

        lines = []

        for reservation in combine_reservations(grouped_reservations):

            resource = resources[reservation.resource]

            prefix = '' if reservation.autoapprovable else '* '
            title_prefix = '{}x '.format(reservation.quota)
            lines.append(prefix +
                         utils.get_resource_title(resource, title_prefix))

            for start, end in reservation.timespans():
                lines.append(utils.display_date(start, end))

            lines.append('')

        # differs between resources
        subject, body = get_email_content(resource, 'reservation_received',
                                          language)

        mail = ReservationMail(resource,
                               reservation,
                               sender=sender,
                               recipient=recipient,
                               subject=subject,
                               body=body,
                               reservations=lines[:-1])

        if may_send_mail(resource, mail, intended_for_admin=False):
            send_mail(resource, mail)
コード例 #6
0
ファイル: mail.py プロジェクト: 4teamwork/seantis.reservation
def send_reservation_mail(reservation, email_type, language,
                          to_managers=False, revocation_reason=u'',
                          bcc=tuple(), mail_class=None):
    mail_class = mail_class or ReservationMail
    resource = utils.get_resource_by_uuid(reservation.resource)

    # the resource doesn't currently exist in testing so we quietly
    # exit. This should be changed => #TODO
    if not resource:
        log.warn('Cannot send email as the resource does not exist')
        return

    sender = utils.get_site_email_sender()

    if not sender:
        log.warn('Cannot send email as no sender is configured')
        return

    resource = resource.getObject()

    if to_managers:
        recipients = get_manager_emails_by_context(resource)
        if not recipients:
            log.warn("Couldn't find a manager to send an email to")
            return
    else:
        recipients = [reservation.email]

    subject, body = get_email_content(resource, email_type, language)

    for recipient in recipients:
        mail = mail_class(
            resource, reservation,
            sender=sender,
            recipient=recipient,
            bcc=bcc,
            subject=subject,
            body=body,
            revocation_reason=revocation_reason
        )

        send_mail(resource, mail)