コード例 #1
0
ファイル: allocate.py プロジェクト: scott50301/DS-project
    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)
コード例 #2
0
    def target_dates(self):
        """ Returns the dates this reservation targets. Those should not be
        confused with the dates this reservation actually reserved.

        The reason for this difference is the fact that after the reservation
        is created, certain dates might be removed through removing reserved
        slots.

        This function only returns dates the reservation was originally
        targeted at.

        """
        if self.target_type == u'allocation':
            return ((self.start, self.end),)

        if self.target_type == u'group':
            return self._target_allocations().with_entities(
                self.models.Allocation._start,
                self.models.Allocation._end
            ).all()

        if self.target_type == u'recurrence':
            time_start = self.start.time()
            time_end = self.end.time()

            date_start = self.start.date()
            from dateutil.rrule import rrulestr

            rule = rrulestr(self.rrule, dtstart=date_start)
            return [get_date_range(date, time_start, time_end)
                    for date in rule]

        raise NotImplementedError
コード例 #3
0
    def isValidRange(Allocation):
        start, end = utils.get_date_range(Allocation.day,
                                          Allocation.start_time,
                                          Allocation.end_time)

        if not Allocation.whole_day and abs((end - start).seconds // 60) < 5:
            raise Invalid(_(u'The allocation must be at least 5 minutes long'))
コード例 #4
0
    def isValidRange(Allocation):
        start, end = utils.get_date_range(
            Allocation.day,
            Allocation.start_time, Allocation.end_time
        )

        if not Allocation.whole_day and abs((end - start).seconds // 60) < 5:
            raise Invalid(_(u'The allocation must be at least 5 minutes long'))
コード例 #5
0
    def validate(self, data):
        try:
            start, end = utils.get_date_range(data["day"], data["start_time"], data["end_time"])
            if not self.allocation(data["id"]).contains(start, end):
                utils.form_error(_(u"Reservation out of bounds"))

            return start, end
        except (NoResultFound, TypeError):
            utils.form_error(_(u"Invalid reservation request"))
コード例 #6
0
    def validate(self, data):
        try:
            start, end = utils.get_date_range(data['day'], data['start_time'],
                                              data['end_time'])
            if not self.allocation(data['id']).contains(start, end):
                utils.form_error(_(u'Reservation out of bounds'))

            return start, end
        except (NoResultFound, TypeError):
            utils.form_error(_(u'Invalid reservation request'))
コード例 #7
0
    def validate(self, data):
        try:
            start, end = utils.get_date_range(
                data['day'], data['start_time'], data['end_time']
            )
            if not self.allocation(data['id']).contains(start, end):
                utils.form_error(_(u'Reservation out of bounds'))

            return start, end
        except (NoResultFound, TypeError):
            utils.form_error(_(u'Invalid reservation request'))
コード例 #8
0
ファイル: allocate.py プロジェクト: scott50301/DS-project
    def get_dates(self, data):
        """ Return a list with date tuples depending on the data entered by the
        user, using rrule if requested.

        """

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

        if not data['recurring']:
            return ((start, end))

        rule = rrule.rrule(
            rrule.DAILY,
            byweekday=data['days'],
            dtstart=data['recurrence_start'],
            until=data['recurrence_end'],
        )

        event = lambda d: \
            utils.get_date_range(d, data['start_time'], data['end_time'])

        return [event(d) for d in rule]
コード例 #9
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
        )