本文整理汇总了Python中indico.modules.rb.models.reservations.Reservation类的典型用法代码示例。如果您正苦于以下问题:Python Reservation类的具体用法?Python Reservation怎么用?Python Reservation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Reservation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_overlapping_with_is_not_valid
def test_find_overlapping_with_is_not_valid(overlapping_reservation, dummy_user):
reservation, occurrence = overlapping_reservation
assert reservation in Reservation.find_overlapping_with(room=reservation.room,
occurrences=[occurrence]).all()
reservation.cancel(dummy_user, silent=True)
assert reservation not in Reservation.find_overlapping_with(room=reservation.room,
occurrences=[occurrence]).all()
示例2: rb_merge_users
def rb_merge_users(new_id, old_id):
"""Updates RB data after an Avatar merge
:param new_id: Target user
:param old_id: Source user (being deleted in the merge)
"""
from indico.modules.rb import settings as rb_settings
from indico.modules.rb.models.blocking_principals import BlockingPrincipal
from indico.modules.rb.models.blockings import Blocking
from indico.modules.rb.models.reservations import Reservation
from indico.modules.rb.models.rooms import Room
old_user = User.get(int(old_id))
new_user = User.get(int(new_id))
for bp in BlockingPrincipal.find():
if bp.principal == old_user:
bp.principal = new_user
Blocking.find(created_by_id=old_id).update({'created_by_id': new_id})
Reservation.find(created_by_id=old_id).update({'created_by_id': new_id})
Reservation.find(booked_for_id=old_id).update({'booked_for_id': new_id})
Room.find(owner_id=old_id).update({'owner_id': new_id})
for key in ('authorized_principals', 'admin_principals'):
principals = rb_settings.get(key)
principals = principals_merge_users(principals, new_id, old_id)
rb_settings.set(key, principals)
示例3: _merge_users
def _merge_users(target, source, **kwargs):
BlockingPrincipal.merge_users(target, source, 'blocking')
Blocking.find(created_by_id=source.id).update({Blocking.created_by_id: target.id})
Reservation.find(created_by_id=source.id).update({Reservation.created_by_id: target.id})
Reservation.find(booked_for_id=source.id).update({Reservation.booked_for_id: target.id})
Room.find(owner_id=source.id).update({Room.owner_id: target.id})
rb_settings.acls.merge_users(target, source)
示例4: test_find_overlapping_with_is_not_valid
def test_find_overlapping_with_is_not_valid(overlapping_reservation, dummy_user, freeze_time):
freeze_time(datetime.combine(date.today(), time(1)))
reservation, occurrence = overlapping_reservation
assert reservation in Reservation.find_overlapping_with(room=reservation.room,
occurrences=[occurrence]).all()
reservation.cancel(dummy_user, silent=True)
assert reservation not in Reservation.find_overlapping_with(room=reservation.room,
occurrences=[occurrence]).all()
示例5: test_find_overlapping_with_skip_reservation
def test_find_overlapping_with_skip_reservation(overlapping_reservation):
reservation, occurrence = overlapping_reservation
assert reservation in Reservation.find_overlapping_with(room=reservation.room, occurrences=[occurrence]).all()
assert (
reservation
not in Reservation.find_overlapping_with(
room=reservation.room, occurrences=[occurrence], skip_reservation_id=reservation.id
).all()
)
示例6: _merge_users
def _merge_users(target, source, **kwargs):
source_principals = set(source.in_blocking_acls.options(joinedload(BlockingPrincipal.blocking)))
target_blockings = {x.blocking for x in target.in_blocking_acls.options(joinedload(BlockingPrincipal.blocking))}
for principal in source_principals:
if principal.blocking not in target_blockings:
principal.user_id = target.id
else:
db.session.delete(principal)
Blocking.find(created_by_id=source.id).update({Blocking.created_by_id: target.id})
Reservation.find(created_by_id=source.id).update({Reservation.created_by_id: target.id})
Reservation.find(booked_for_id=source.id).update({Reservation.booked_for_id: target.id})
Room.find(owner_id=source.id).update({Room.owner_id: target.id})
settings.acls.merge_users(target, source)
示例7: _create_reservation
def _create_reservation(**params):
params.setdefault('start_dt', date.today() + relativedelta(hour=8, minute=30))
params.setdefault('end_dt', date.today() + relativedelta(hour=17, minute=30))
params.setdefault('repeat_frequency', RepeatFrequency.NEVER)
params.setdefault('repeat_interval', int(params['repeat_frequency'] != RepeatFrequency.NEVER))
params.setdefault('booking_reason', u'Testing')
params.setdefault('room', dummy_room)
params.setdefault('booked_for_user', dummy_user)
params.setdefault('created_by_user', dummy_user)
reservation = Reservation(**params)
reservation.create_occurrences(skip_conflicts=False)
db.session.add(reservation)
db.session.flush()
return reservation
示例8: _process
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)
示例9: split_booking
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
示例10: calculate_rooms_booked_time
def calculate_rooms_booked_time(rooms, start_date=None, end_date=None):
if end_date is None:
end_date = date.today() - relativedelta(days=1)
if start_date is None:
start_date = end_date - relativedelta(days=29)
# Reservations on working days
reservations = Reservation.find(Reservation.room_id.in_(r.id for r in rooms),
db.extract('dow', ReservationOccurrence.start_dt).between(1, 5),
db.cast(ReservationOccurrence.start_dt, db.Date) >= start_date,
db.cast(ReservationOccurrence.end_dt, db.Date) <= end_date,
ReservationOccurrence.is_valid,
_join=ReservationOccurrence)
rsv_start = db.cast(ReservationOccurrence.start_dt, db.TIME)
rsv_end = db.cast(ReservationOccurrence.end_dt, db.TIME)
slots = ((db.cast(start, db.TIME), db.cast(end, db.TIME)) for start, end in WORKING_TIME_PERIODS)
# this basically handles all possible ways an occurrence overlaps with each one of the working time slots
overlaps = sum(db.case([
((rsv_start < start) & (rsv_end > end), db.extract('epoch', end - start)),
((rsv_start < start) & (rsv_end > start) & (rsv_end <= end), db.extract('epoch', rsv_end - start)),
((rsv_start >= start) & (rsv_start < end) & (rsv_end > end), db.extract('epoch', end - rsv_start)),
((rsv_start >= start) & (rsv_end <= end), db.extract('epoch', rsv_end - rsv_start))
], else_=0) for start, end in slots)
return reservations.with_entities(db.func.sum(overlaps)).scalar() or 0
示例11: _process
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)
示例12: _export_reservations
def _export_reservations(hook, limit_per_room, include_rooms, extra_filters=None):
"""Exports reservations.
:param hook: The HTTPAPIHook instance
:param limit_per_room: Should the limit/offset be applied per room
:param include_rooms: Should reservations include room information
"""
filters = list(extra_filters) if extra_filters else []
if hook._fromDT and hook._toDT:
filters.append(cast(Reservation.start_dt, Date) <= hook._toDT.date())
filters.append(cast(Reservation.end_dt, Date) >= hook._fromDT.date())
filters.append(cast(Reservation.start_dt, Time) <= hook._toDT.time())
filters.append(cast(Reservation.end_dt, Time) >= hook._fromDT.time())
elif hook._toDT:
filters.append(cast(Reservation.end_dt, Date) <= hook._toDT.date())
filters.append(cast(Reservation.end_dt, Time) <= hook._toDT.time())
elif hook._fromDT:
filters.append(cast(Reservation.start_dt, Date) >= hook._fromDT.date())
filters.append(cast(Reservation.start_dt, Time) >= hook._fromDT.time())
filters += _get_reservation_state_filter(hook._queryParams)
data = ['vc_equipment']
if hook._occurrences:
data.append('occurrences')
order = {
'start': Reservation.start_dt,
'end': Reservation.end_dt
}.get(hook._orderBy, Reservation.start_dt)
if hook._descending:
order = order.desc()
reservations_data = Reservation.get_with_data(*data, filters=filters, limit=hook._limit, offset=hook._offset,
order=order, limit_per_room=limit_per_room)
for result in reservations_data:
yield result['reservation'].room_id, _serializable_reservation(result, include_rooms)
示例13: _createTabCtrl
def _createTabCtrl(self):
self._tabCtrl = TabControl()
self._tabExistBookings = self._tabCtrl.newTab('existing', 'Existing Bookings',
url_for('event_mgmt.rooms_booking_list', self._conf))
self._tabNewBooking = self._tabCtrl.newTab('new', 'New Booking',
url_for('event_mgmt.rooms_choose_event', self._conf))
if not Reservation.find(event_id=self._conf.getId()).count():
self._tabExistBookings.setEnabled(False)
self._setActiveTab()
示例14: _create_booking
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
示例15: rb_merge_users
def rb_merge_users(new_id, old_id):
"""Updates RB data after an Avatar merge
:param new_id: Target user
:param old_id: Source user (being deleted in the merge)
"""
from indico.modules.rb import settings
from indico.modules.rb.models.blocking_principals import BlockingPrincipal
from indico.modules.rb.models.blockings import Blocking
from indico.modules.rb.models.reservations import Reservation
from indico.modules.rb.models.rooms import Room
BlockingPrincipal.find(entity_type='Avatar', entity_id=old_id).update({'entity_id': new_id})
Blocking.find(created_by_id=old_id).update({'created_by_id': new_id})
Reservation.find(created_by_id=old_id).update({'created_by_id': new_id})
Reservation.find(booked_for_id=old_id).update({'booked_for_id': new_id})
Room.find(owner_id=old_id).update({'owner_id': new_id})
for key in ('authorized_principals', 'admin_principals'):
principals = settings.get(key, [])
principals = principals_merge_users(principals, new_id, old_id)
settings.set(key, principals)