示例#1
0
    def reserve(self, data):

        allocation = self.allocation(data['id'])
        approve_manually = allocation.approve_manually

        self.inject_missing_data(data, allocation)

        start, end = self.validate(data)
        quota = int(data.get('quota', 1))

        # whole day allocations don't show the start / end time which is to
        # say the data arrives with 00:00 - 00:00. we align that to the day
        if allocation.whole_day:
            assert start == end
            start, end = utils.align_range_to_day(start, end)

        def reserve():
            self.run_reserve(
                data=data, approve_manually=approve_manually,
                start=start, end=end, quota=quota
            )

        utils.handle_action(
            action=reserve, success=self.redirect_to_your_reservations
        )
示例#2
0
    def edit(self, data):

        scheduler = self.context.scheduler()

        start, end = utils.get_date_range(
            data['day'], data['start_time'], data['end_time']
        )

        args = (
            data['id'],
            start,
            end,
            six.text_type(data['group'] or u''),
            data['quota'],
            data['approve_manually'],
            data['reservation_quota_limit'],
            data['whole_day']
        )

        def edit():
            scheduler.move_allocation(*args)

            # ensure that the allocation is not accessed again by the defaults,
            # this prevents a DirtyReadOnlySession error
            self.allocation_stale = True

            self.flash(_(u'Allocation saved'))

        utils.handle_action(action=edit, success=self.redirect_to_context)
示例#3
0
    def approve(self, data):

        def approve():
            self.scheduler.approve_reservation(data['reservation'])
            self.flash(_(u'Reservation confirmed'))

        utils.handle_action(action=approve, success=self.redirect_to_context)
示例#4
0
    def deny(self, data):

        def deny():
            self.scheduler.deny_reservation(data['reservation'])
            self.flash(_(u'Reservation denied'))

        utils.handle_action(action=deny, success=self.redirect_to_context)
示例#5
0
    def save(self, data):

        # might happen if the user submits twice
        if not self.reservation:
            return

        def change():
            start = datetime.combine(self.reservation.start.date(),
                                     data['start_time'])
            end = datetime.combine(self.reservation.end.date(),
                                   data['end_time'])

            changed = self.scheduler.change_reservation_time(
                token=data['token'],
                id=data['id'],
                new_start=start,
                new_end=end,
                send_email=data['send_email'],
                reason=data['reason'])
            if changed:
                self.flash(_(u'Reservation changed.'))
            else:
                self.flash(_(u'There was nothing to change.'))

        utils.handle_action(action=change, success=self.redirect_to_context)
示例#6
0
    def reserve(self, data):

        allocation = self.allocation(data['id'])
        approve_manually = allocation.approve_manually

        self.inject_missing_data(data, allocation)

        start, end = self.validate(data)
        quota = int(data.get('quota', 1))

        # whole day allocations don't show the start / end time which is to
        # say the data arrives with 00:00 - 00:00. we align that to the day
        if allocation.whole_day:

            if not allocation.partly_available:
                assert start == end

            if start == end:
                start, end = utils.align_range_to_day(start, end)

        def reserve():
            self.run_reserve(data=data,
                             approve_manually=approve_manually,
                             start=start,
                             end=end,
                             quota=quota)

        utils.handle_action(action=reserve,
                            success=self.redirect_to_your_reservations)
示例#7
0
    def reserve(self, data):

        approve_manually = self.scheduler.allocations_by_group(data["group"]).first().approve_manually

        def reserve():
            self.run_reserve(data=data, approve_manually=approve_manually, group=data["group"], quota=data["quota"])

        utils.handle_action(action=reserve, success=self.redirect_to_your_reservations)
示例#8
0
    def reserve(self, data):
        approve_manually = self.scheduler.manual_approval_required(self.ids)

        def reserve():
            dates = list(self.scheduler.allocation_dates_by_ids(self.ids, data["start_time"], data["end_time"]))
            self.run_reserve(data=data, approve_manually=approve_manually, dates=dates, quota=data["quota"])

        utils.handle_action(action=reserve, success=self.redirect_to_your_reservations)
示例#9
0
    def remove(self, data):
        def remove():
            self.scheduler.remove_reservation_slots(
                data['reservation'], self.timespan_start, self.timespan_end
            )
            self.flash(_(u'Reservation removed'))

        utils.handle_action(action=remove, success=self.redirect_to_context)
示例#10
0
    def revoke(self, data):

        def revoke():
            self.scheduler.revoke_reservation(
                data['reservation'], data['reason'], data['send_email']
            )
            self.flash(_(u'Reservation revoked'))

        utils.handle_action(action=revoke, success=self.redirect_to_context)
示例#11
0
    def finish(self, data):

        resources = self.resources()

        def on_success():
            self.request.response.redirect(
                '{context}/thank-you-for-reserving?uuid={uuids}'.format(
                    context=self.context.absolute_url(),
                    uuids='&uuid='.join(resources)))

        utils.handle_action(self.confirm_reservations, success=on_success)
示例#12
0
    def finish(self, data):

        resources = self.resources()

        def on_success():
            self.request.response.redirect(
                "{context}/thank-you-for-reserving?uuid={uuids}".format(
                    context=self.context.absolute_url(), uuids="&uuid=".join(resources)
                )
            )

        utils.handle_action(self.confirm_reservations, success=on_success)
示例#13
0
    def delete(self, data):

        assert bool(data['id']) != bool(data['group']), \
            "Either id or group, not both"

        scheduler = self.scheduler

        def delete():
            scheduler.remove_allocation(id=data['id'], group=data['group'])
            self.flash(_(u'Allocation removed'))

        utils.handle_action(action=delete, success=self.redirect_to_context)
示例#14
0
    def reserve(self, data):

        approve_manually = self.scheduler.allocations_by_group(data['group']) \
            .first().approve_manually

        def reserve():
            self.run_reserve(data=data,
                             approve_manually=approve_manually,
                             group=data['group'],
                             quota=data['quota'])

        utils.handle_action(action=reserve,
                            success=self.redirect_to_your_reservations)
示例#15
0
    def save(self, data):

        self.additional_data = utils.additional_data_dictionary(data, self.fti)

        def save():
            self.scheduler.update_reservation_data(
                self.reservation, self.additional_data
            )
            self.flash(_(u'Formdata updated'))

        utils.handle_action(
            action=save, success=self.redirect_to_context
        )
示例#16
0
    def revoke(self, data):

        # might happen if the user submits twice
        if not self.has_reservations:
            return

        def revoke():
            self.scheduler.revoke_reservation(
                token=data["token"], reason=data["reason"], id=data.get("id"), send_email=data["send_email"]
            )
            self.flash(_(u"Reservation revoked"))

        utils.handle_action(action=revoke, success=self.redirect_to_context)
示例#17
0
    def revoke(self, data):

        # might happen if the user submits twice
        if not self.has_reservations:
            return

        def revoke():
            self.scheduler.revoke_reservation(token=data['token'],
                                              reason=data['reason'],
                                              id=data.get('id'),
                                              send_email=data['send_email'])
            self.flash(_(u'Reservation revoked'))

        utils.handle_action(action=revoke, success=self.redirect_to_context)
示例#18
0
    def reserve(self, data):
        approve_manually = self.scheduler.manual_approval_required(self.ids)

        def reserve():
            dates = list(
                self.scheduler.allocation_dates_by_ids(self.ids,
                                                       data['start_time'],
                                                       data['end_time']))
            self.run_reserve(data=data,
                             approve_manually=approve_manually,
                             dates=dates,
                             quota=data['quota'])

        utils.handle_action(action=reserve,
                            success=self.redirect_to_your_reservations)
示例#19
0
    def remove(self, data):

        assert bool(data['id']) != bool(data['group']), \
            "Either id or group, not both"

        scheduler = self.scheduler
        groups = self.allocation_groups

        def remove():
            scheduler.remove_allocation(id=data['id'], groups=groups)
            if data['id']:
                self.flash(_(u'Allocation deleted'))
            else:
                self.flash(_(u'Allocations deleted'))

        utils.handle_action(action=remove, success=self.redirect_to_context)
示例#20
0
    def delete(self, data):
        nof_params = len(list(itertools.ifilter(None, (
                                                data['id'],
                                                data['group'],
                                                data['recurrence_id'],)
                         )))
        assert nof_params == 1, "Exactly one of id, group or recurrence_id"

        scheduler = self.scheduler

        def delete():
            scheduler.remove_allocation(id=data['id'],
                                        group=data['group'],
                                        recurrence_id=data['recurrence_id'])
            self.flash(_(u'Allocation removed'))

        utils.handle_action(action=delete, success=self.redirect_to_context)
示例#21
0
    def allocate(self, data):
        dates = self.get_dates(data)

        def allocate():
            self.scheduler.allocate(
                dates,
                raster=data['raster'],
                quota=data['quota'],
                partly_available=data['partly_available'],
                grouped=data['recurring'] and not data['separately'],
                approve_manually=data['approve_manually'],
                quota_limit=data['reservation_quota_limit'],
                whole_day=data['whole_day']
            )
            self.flash(_(u'Allocation added'))

        utils.handle_action(action=allocate, success=self.redirect_to_context)
示例#22
0
    def save(self, data):

        broken = self.separate_broken_data()[1]
        working = utils.additional_data_dictionary(data, self.fti)

        if broken:
            self.additional_data = utils.merge_data_dictionaries(broken, working)
        else:
            self.additional_data = working

        def save():
            if self.reservation.email != data["email"]:
                self.scheduler.change_email(self.token, data["email"])

            self.scheduler.change_reservation_data(self.token, self.additional_data)
            self.flash(_(u"Formdata updated"))

        utils.handle_action(action=save, success=self.redirect_to_context)
示例#23
0
    def delete(self, data):
        nof_params = len(
            list(
                itertools.ifilter(None, (
                    data['id'],
                    data['group'],
                    data['recurrence_id'],
                ))))
        assert nof_params == 1, "Exactly one of id, group or recurrence_id"

        scheduler = self.scheduler

        def delete():
            scheduler.remove_allocation(id=data['id'],
                                        group=data['group'],
                                        recurrence_id=data['recurrence_id'])
            self.flash(_(u'Allocation removed'))

        utils.handle_action(action=delete, success=self.redirect_to_context)
示例#24
0
    def save(self, data):

        broken = self.separate_broken_data()[1]
        working = utils.additional_data_dictionary(data, self.fti)

        if broken:
            self.additional_data = utils.merge_data_dictionaries(
                broken, working)
        else:
            self.additional_data = working

        def save():
            if self.reservation.email != data['email']:
                self.scheduler.change_email(self.token, data['email'])

            self.scheduler.change_reservation_data(self.token,
                                                   self.additional_data)
            self.flash(_(u'Formdata updated'))

        utils.handle_action(action=save, success=self.redirect_to_context)
示例#25
0
    def reserve(self, data):
        allocation = self.allocation(data['id'])
        approve_manually = allocation.approve_manually

        self.inject_missing_data(data, allocation)

        dates = utils.get_dates(data, is_whole_day=allocation.whole_day)
        quota = int(data.get('quota', 1))
        description = data.get('description')

        def reserve():
            self.run_reserve(
                data=data, approve_manually=approve_manually,
                dates=dates, quota=quota,
                rrule=data['recurrence'],
                description=description,
            )

        utils.handle_action(
            action=reserve, success=self.redirect_to_your_reservations
        )
示例#26
0
    def save(self, data):
        query = self.scheduler.reservation_by_token(self.reservation)
        reservation = query.one()

        self.additional_data = self.get_additional_data(data)
        self.inject_missing_data(data, reservation)
        start, end = utils.get_date_range(reservation.start.date(),
                                          data.get('start_time'),
                                          data.get('end_time'))

        def save():
            self.scheduler.update_reservation(
                self.reservation,
                start,
                end,
                data.get('email'),
                data.get('description'),
                self.additional_data,
            )
            self.flash(_(u'Formdata updated'))

        utils.handle_action(
            action=save, success=self.redirect_to_context
        )
示例#27
0
    def save(self, data):

        # might happen if the user submits twice
        if not self.reservation:
            return

        def change():
            start = datetime.combine(self.reservation.start.date(), data["start_time"])
            end = datetime.combine(self.reservation.end.date(), data["end_time"])

            changed = self.scheduler.change_reservation_time(
                token=data["token"],
                id=data["id"],
                new_start=start,
                new_end=end,
                send_email=data["send_email"],
                reason=data["reason"],
            )
            if changed:
                self.flash(_(u"Reservation changed."))
            else:
                self.flash(_(u"There was nothing to change."))

        utils.handle_action(action=change, success=self.redirect_to_context)
示例#28
0
    def finish(self, data):
        def on_success():
            self.request.response.redirect(self.context.absolute_url())
            self.flash(_(u'Reservations Successfully Submitted'))

        utils.handle_action(self.confirm_reservations, success=on_success)
示例#29
0
    def approve(self, data):
        def approve():
            self.scheduler.approve_reservations(data["token"])
            self.flash(_(u"Reservation approved"))

        utils.handle_action(action=approve, success=self.redirect_to_context)