本文整理汇总了Python中indico.modules.rb.models.reservations.Reservation.create_from_data方法的典型用法代码示例。如果您正苦于以下问题:Python Reservation.create_from_data方法的具体用法?Python Reservation.create_from_data怎么用?Python Reservation.create_from_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类indico.modules.rb.models.reservations.Reservation
的用法示例。
在下文中一共展示了Reservation.create_from_data方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: split_booking
# 需要导入模块: from indico.modules.rb.models.reservations import Reservation [as 别名]
# 或者: from indico.modules.rb.models.reservations.Reservation import create_from_data [as 别名]
def split_booking(booking, new_booking_data):
is_ongoing_booking = booking.start_dt.date() < date.today() < booking.end_dt.date()
if not is_ongoing_booking:
return
room = booking.room
occurrences = sorted(booking.occurrences, key=attrgetter('start_dt'))
cancelled_dates = [occ.start_dt.date() for occ in occurrences if occ.is_cancelled]
rejected_occs = {occ.start_dt.date(): occ.rejection_reason for occ in occurrences if occ.is_rejected}
occurrences_to_cancel = [occ for occ in occurrences if occ.start_dt >= datetime.now()]
new_start_dt = datetime.combine(occurrences_to_cancel[0].start_dt.date(), new_booking_data['start_dt'].time())
for occurrence_to_cancel in occurrences_to_cancel:
occurrence_to_cancel.cancel(session.user, silent=True)
new_end_dt = [occ for occ in occurrences if occ.start_dt < datetime.now()][-1].end_dt
old_booking_data = {
'booking_reason': booking.booking_reason,
'booked_for_user': booking.booked_for_user,
'start_dt': booking.start_dt,
'end_dt': new_end_dt,
'repeat_frequency': booking.repeat_frequency,
'repeat_interval': booking.repeat_interval,
}
booking.modify(old_booking_data, session.user)
prebook = not room.can_book(session.user, allow_admin=False) and room.can_prebook(session.user, allow_admin=False)
resv = Reservation.create_from_data(room, dict(new_booking_data, start_dt=new_start_dt), session.user,
prebook=prebook)
for new_occ in resv.occurrences:
new_occ_start = new_occ.start_dt.date()
if new_occ_start in cancelled_dates:
new_occ.cancel(None, silent=True)
if new_occ_start in rejected_occs:
new_occ.reject(None, rejected_occs[new_occ_start], silent=True)
return resv
示例2: _process
# 需要导入模块: from indico.modules.rb.models.reservations import Reservation [as 别名]
# 或者: from indico.modules.rb.models.reservations.Reservation import create_from_data [as 别名]
def _process(self, args):
room = Room.get_one(args.pop('room_id'))
user_id = args.pop('user_id', None)
booked_for = User.get_one(user_id) if user_id else session.user
is_prebooking = args.pop('is_prebooking')
# Check that the booking is not longer than allowed
booking_limit_days = room.booking_limit_days or rb_settings.get('booking_limit')
if not self._validate_room_booking_limit(args['start_dt'], args['end_dt'], booking_limit_days):
msg = (_('Bookings for the room "{}" may not be longer than {} days')
.format(room.name, booking_limit_days))
raise ExpectedError(msg)
try:
resv = Reservation.create_from_data(room, dict(args, booked_for_user=booked_for), session.user,
prebook=is_prebooking)
db.session.flush()
except NoReportError as e:
db.session.rollback()
raise ExpectedError(unicode(e))
serialized_occurrences = serialize_occurrences(group_by_occurrence_date(resv.occurrences.all()))
if is_prebooking:
data = {'pre_bookings': serialized_occurrences}
else:
data = {'bookings': serialized_occurrences}
return jsonify(room_id=room.id, booking=reservation_details_schema.dump(resv).data, calendar_data=data)
示例3: _process
# 需要导入模块: from indico.modules.rb.models.reservations import Reservation [as 别名]
# 或者: from indico.modules.rb.models.reservations.Reservation import create_from_data [as 别名]
def _process(self):
args = self.args
args.setdefault('booked_for_user', session.user)
if not is_booking_start_within_grace_period(args['start_dt'], session.user, args['admin_override_enabled']):
raise ExpectedError(_('You cannot create a booking which starts in the past'))
# Check that the booking is not longer than allowed
booking_limit_days = self.room.booking_limit_days or rb_settings.get('booking_limit')
if not self._validate_room_booking_limit(args['start_dt'], args['end_dt'], booking_limit_days):
msg = (_('Bookings for the room "{}" may not be longer than {} days')
.format(self.room.name, booking_limit_days))
raise ExpectedError(msg)
try:
resv = Reservation.create_from_data(self.room, args, session.user, prebook=self.prebook)
if args.get('link_type') is not None and args.get('link_id') is not None:
self._link_booking(resv, args['link_type'], args['link_id'], args['link_back'])
db.session.flush()
except NoReportError as e:
db.session.rollback()
raise ExpectedError(unicode(e))
serialized_occurrences = serialize_occurrences(group_by_occurrence_date(resv.occurrences.all()))
if self.prebook:
data = {'pre_bookings': serialized_occurrences}
else:
data = {'bookings': serialized_occurrences}
return jsonify(room_id=self.room.id, booking=reservation_details_schema.dump(resv), calendar_data=data)
示例4: _create_booking
# 需要导入模块: from indico.modules.rb.models.reservations import Reservation [as 别名]
# 或者: from indico.modules.rb.models.reservations.Reservation import create_from_data [as 别名]
def _create_booking(self, form, room):
if 'submit_book' in form and 'submit_prebook' in form:
# Admins have the choice
prebook = form.submit_prebook.data
else:
# Otherwise the existence of the book submit button means the user can book
prebook = 'submit_book' not in form
reservation = Reservation.create_from_data(room, form.data, session.user, prebook)
db.session.add(reservation)
db.session.flush()
return reservation
示例5: create_booking_for_event
# 需要导入模块: from indico.modules.rb.models.reservations import Reservation [as 别名]
# 或者: from indico.modules.rb.models.reservations.Reservation import create_from_data [as 别名]
def create_booking_for_event(room_id, event):
try:
room = Room.get_one(room_id)
default_timezone = timezone(config.DEFAULT_TIMEZONE)
start_dt = event.start_dt.astimezone(default_timezone).replace(tzinfo=None)
end_dt = event.end_dt.astimezone(default_timezone).replace(tzinfo=None)
booking_reason = "Event '%s'" % (event.title)
data = dict(start_dt=start_dt, end_dt=end_dt, booked_for_user=event.creator, booking_reason=booking_reason,
repeat_frequency=RepeatFrequency.NEVER, event_id=event.id)
resv = Reservation.create_from_data(room, data, session.user, ignore_admin=True)
return resv
except NoReportError:
flash(_("Booking could not be created. Probably somebody else booked the room in the meantime."), 'error')
示例6: api_roomBooking
# 需要导入模块: from indico.modules.rb.models.reservations import Reservation [as 别名]
# 或者: from indico.modules.rb.models.reservations.Reservation import create_from_data [as 别名]
def api_roomBooking(self, user):
data = MultiDict({
'start_dt': self._params['from'],
'end_dt': self._params['to'],
'repeat_frequency': RepeatFrequency.NEVER,
'repeat_interval': 0,
'room_id': self._room.id,
'booked_for_user': self._params['booked_for'],
'booking_reason': self._params['reason']
})
try:
reservation = Reservation.create_from_data(self._room, data, user)
except ConflictingOccurrences:
raise HTTPAPIError('Failed to create the booking due to conflicts with other bookings')
except IndicoError as e:
raise HTTPAPIError('Failed to create the booking: {}'.format(e))
db.session.add(reservation)
db.session.flush()
return {'reservationID': reservation.id}