def get_date_parameters(self, reservation):
        lines = []
        dates = sorted(reservation.timespans(), key=lambda i: i[0])
        for start, end in dates:
            lines.append(utils.display_date(start, end))

        return u'\n'.join(lines)
    def reservation_data(self):
        """ Prepares data to be shown in the my reservation's table """
        reservations = []

        for reservation in self.reservations():
            resource = utils.get_resource_by_uuid(reservation.resource)

            if resource is None:
                log.warn('Invalid UUID %s' % str(reservation.resource))
                continue

            resource = resource.getObject()

            data = {}

            data['title'] = utils.get_resource_title(resource)

            timespans = []
            for start, end in reservation.timespans():
                timespans.append(u'◆ ' + utils.display_date(start, end))

            data['time'] = '<br />'.join(timespans)
            data['quota'] = utils.get_reservation_quota_statement(
                reservation.quota
            ) if reservation.quota > 1 else u''

            data['url'] = resource.absolute_url()
            data['remove-url'] = ''.join((
                resource.absolute_url(),
                '/your-reservations?remove=',
                reservation.token.hex
            ))
            reservations.append(data)

        return reservations
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)
Exemple #4
0
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)
Exemple #5
0
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)
    def build_your_reservations(
        self, reservations
    ):
        """ Prepares the given reservations to be shown in the
        your-reservations macro.

        """
        result = []

        for reservation in reservations:
            resource = utils.get_resource_by_uuid(reservation.resource)

            if resource is None:
                log.warn('Invalid UUID %s' % str(reservation.resource))
                continue

            resource = resource.getObject()

            data = {}

            data['token'] = reservation.token
            data['title'] = utils.get_resource_title(resource)

            timespans = []
            for start, end in reservation.timespans():
                timespans.append(utils.display_date(start, end))

            data['time'] = '<ul class="dense"><li>{}</li></ul>'.format(
                '</li><li>'.join(timespans)
            )
            data['quota'] = utils.get_reservation_quota_statement(
                reservation.quota
            ) if reservation.quota > 1 else u''

            data['url'] = resource.absolute_url()
            data['remove-url'] = ''.join((
                resource.absolute_url(),
                '/your-reservations?remove=',
                reservation.token.hex
            ))
            result.append(data)

        return result
Exemple #7
0
    def build_your_reservations(self, reservations):
        """ Prepares the given reservations to be shown in the
        your-reservations macro.

        """
        result = []

        for reservation in reservations:
            resource = utils.get_resource_by_uuid(reservation.resource)

            if resource is None:
                log.warn('Invalid UUID %s' % str(reservation.resource))
                continue

            resource = resource.getObject()

            data = {}

            data['token'] = reservation.token
            data['title'] = utils.get_resource_title(resource)

            timespans = []
            for start, end in reservation.timespans():
                timespans.append(utils.display_date(start, end))

            data['time'] = '<ul class="dense"><li>{}</li></ul>'.format(
                '</li><li>'.join(timespans))
            data['quota'] = utils.get_reservation_quota_statement(
                reservation.quota) if reservation.quota > 1 else u''

            data['url'] = resource.absolute_url()
            data['remove-url'] = ''.join(
                (resource.absolute_url(), '/your-reservations?remove=',
                 reservation.token.hex))
            result.append(data)

        return result
Exemple #8
0
    def __init__(self, resource, reservation, **kwargs):
        for k, v in kwargs.items():
            if hasattr(self, k):
                setattr(self, k, v)

        # get information for the body/subject string

        p = dict()
        is_needed = lambda key: key in self.subject or key in self.body

        # title of the resource
        if is_needed('resource'):
            p['resource'] = utils.get_resource_title(resource)

        # reservation email
        if is_needed('reservation_mail'):
            p['reservation_mail'] = reservation.email

        # a list of reservations
        if is_needed('reservations'):
            p['reservations'] = '\n'.join(self.reservations)

        # a list of dates
        if is_needed('dates'):
            lines = []
            dates = sorted(reservation.timespans(), key=lambda i: i[0])
            for start, end in dates:
                lines.append(utils.display_date(start, end))

            p['dates'] = '\n'.join(lines)

        # reservation quota
        if is_needed('quota'):
            p['quota'] = reservation.quota

        # tabbed reservation data
        if is_needed('data'):
            data = reservation.data
            lines = []
            for key in self.sort_reservation_data(data):
                interface = data[key]

                lines.append(interface['desc'])
                sorted_values = self.sort_reservation_data_values(
                    interface['values']
                )

                for value in sorted_values:
                    lines.append(
                        '\t' + value['desc'] + ': ' +
                        six.text_type(
                            self.display_reservation_data(value['value'])
                        )
                    )

            p['data'] = '\n'.join(lines)

        if is_needed('reservation_link'):
            p['reservation_link'] = self.show_all_url(
                reservation.token, resource
            )

        # approval link
        if is_needed('approval_link'):
            p['approval_link'] = self.approve_all_url(
                reservation.token, resource
            )

        # denial link
        if is_needed('denial_link'):
            p['denial_link'] = self.deny_all_url(reservation.token, resource)

        # cancel link
        if is_needed('cancel_link'):
            p['cancel_link'] = self.revoke_all_url(reservation.token, resource)

        # revocation reason
        if is_needed('reason'):
            p['reason'] = self.reason

        # old time
        if is_needed('old_time'):
            p['old_time'] = utils.display_date(*self.old_time)

        # new time
        if is_needed('new_time'):
            p['new_time'] = utils.display_date(*self.new_time)

        self.parameters = p
Exemple #9
0
    def __init__(self, resource, reservation, **kwargs):
        for k, v in kwargs.items():
            if hasattr(self, k):
                setattr(self, k, v)

        # get information for the body/subject string

        p = dict()
        is_needed = lambda key: key in self.subject or key in self.body

        # title of the resource
        if is_needed('resource'):
            p['resource'] = utils.get_resource_title(resource)

        # reservation email
        if is_needed('reservation_mail'):
            p['reservation_mail'] = reservation.email

        # a list of reservations
        if is_needed('reservations'):
            p['reservations'] = '\n'.join(self.reservations)

        # a list of dates
        if is_needed('dates'):
            lines = []
            dates = sorted(reservation.timespans(), key=lambda i: i[0])
            for start, end in dates:
                lines.append(utils.display_date(start, end))

            p['dates'] = '\n'.join(lines)

        # reservation quota
        if is_needed('quota'):
            p['quota'] = reservation.quota

        # tabbed reservation data
        if is_needed('data'):
            data = reservation.data
            lines = []
            for key in self.sort_reservation_data(data):
                interface = data[key]

                lines.append(interface['desc'])
                sorted_values = self.sort_reservation_data_values(
                    interface['values'])

                for value in sorted_values:
                    lines.append('\t' + value['desc'] + ': ' + six.text_type(
                        self.display_reservation_data(value['value'])))

            p['data'] = '\n'.join(lines)

        if is_needed('reservation_link'):
            p['reservation_link'] = self.show_all_url(reservation.token,
                                                      resource)

        # approval link
        if is_needed('approval_link'):
            p['approval_link'] = self.approve_all_url(reservation.token,
                                                      resource)

        # denial link
        if is_needed('denial_link'):
            p['denial_link'] = self.deny_all_url(reservation.token, resource)

        # cancel link
        if is_needed('cancel_link'):
            p['cancel_link'] = self.revoke_all_url(reservation.token, resource)

        # revocation reason
        if is_needed('reason'):
            p['reason'] = self.reason

        # old time
        if is_needed('old_time'):
            p['old_time'] = utils.display_date(*self.old_time)

        # new time
        if is_needed('new_time'):
            p['new_time'] = utils.display_date(*self.new_time)

        self.parameters = p