def roombooking_occurrences_digest(): if not Config.getInstance().getIsRoomBookingActive(): logger.info('Digest not sent because room booking is disabled') return if not rb_settings.get('notifications_enabled'): logger.info('Digest not sent because notifications are globally disabled') return digest_start = round_up_month(date.today(), from_day=2) digest_end = get_month_end(digest_start) occurrences = ReservationOccurrence.find( Room.notifications_enabled, Reservation.is_accepted, Reservation.repeat_frequency == RepeatFrequency.WEEK, ReservationOccurrence.is_valid, ReservationOccurrence.start_dt >= digest_start, ReservationOccurrence.start_dt <= digest_end, ~ReservationOccurrence.notification_sent, _build_digest_window_filter(), _join=[Reservation, Room] ) digests = defaultdict(list) for occurrence in occurrences: digests[occurrence.reservation].append(occurrence) try: for reservation, occurrences in digests.iteritems(): notify_reservation_digest(reservation, occurrences) for occurrence in occurrences: occurrence.notification_sent = True finally: db.session.commit()
def roombooking_occurrences(): if not Config.getInstance().getIsRoomBookingActive(): logger.info('Notifications not sent because room booking is disabled') return if not rb_settings.get('notifications_enabled'): logger.info('Notifications not sent because they are globally disabled') return occurrences = ReservationOccurrence.find( Room.notifications_enabled, Reservation.is_accepted, Reservation.repeat_frequency != RepeatFrequency.WEEK, ReservationOccurrence.is_valid, ReservationOccurrence.start_dt >= datetime.now(), ~ReservationOccurrence.notification_sent, _build_notification_window_filter(), _join=[Reservation, Room] ) try: for occ in occurrences: notify_upcoming_occurrence(occ) occ.notification_sent = True if occ.reservation.repeat_frequency == RepeatFrequency.DAY: occ.reservation.occurrences.update({'notification_sent': True}) finally: db.session.commit()
def roombooking_occurrences(): if not Config.getInstance().getIsRoomBookingActive(): logger.info('Notifications not sent because room booking is disabled') return if not rb_settings.get('notifications_enabled'): logger.info( 'Notifications not sent because they are globally disabled') return occurrences = ReservationOccurrence.find( Room.is_active, Room.notifications_enabled, Reservation.is_accepted, Reservation.repeat_frequency != RepeatFrequency.WEEK, ReservationOccurrence.is_valid, ReservationOccurrence.start_dt >= datetime.now(), ~ReservationOccurrence.notification_sent, _build_notification_window_filter(), _join=[Reservation, Room]) try: for occ in occurrences: notify_upcoming_occurrence(occ) occ.notification_sent = True if occ.reservation.repeat_frequency == RepeatFrequency.DAY: occ.reservation.occurrences.update({'notification_sent': True}) finally: db.session.commit()
def roombooking_occurrences(debug=False): if not Config.getInstance().getIsRoomBookingActive(): logger.info('Notifications not sent because room booking is disabled') return if not rb_settings.get('notifications_enabled'): logger.info( 'Notifications not sent because they are globally disabled') return occurrences = (ReservationOccurrence.query.join( ReservationOccurrence.reservation).join(Reservation.room).filter( Room.is_active, Room.notifications_enabled, Reservation.is_accepted, Reservation.booked_for_id.isnot(None), ReservationOccurrence.is_valid, ReservationOccurrence.start_dt >= datetime.now(), ~ReservationOccurrence.notification_sent, _make_occurrence_date_filter()).order_by( Reservation.booked_for_id, ReservationOccurrence.start_dt, Room.id).options( contains_eager('reservation').contains_eager( 'room')).all()) try: for user, user_occurrences in groupby( occurrences, key=attrgetter('reservation.booked_for_user')): user_occurrences = list(user_occurrences) if debug: _print_occurrences(user, user_occurrences) else: _notify_occurrences(user, user_occurrences) finally: if not debug: db.session.commit()
def roombooking_occurrences_digest(): if not Config.getInstance().getIsRoomBookingActive(): logger.info('Digest not sent because room booking is disabled') return if not rb_settings.get('notifications_enabled'): logger.info( 'Digest not sent because notifications are globally disabled') return digest_start = round_up_month(date.today(), from_day=2) digest_end = get_month_end(digest_start) occurrences = ReservationOccurrence.find( Room.is_active, Room.notifications_enabled, Reservation.is_accepted, Reservation.repeat_frequency == RepeatFrequency.WEEK, ReservationOccurrence.is_valid, ReservationOccurrence.start_dt >= digest_start, ReservationOccurrence.start_dt <= digest_end, ~ReservationOccurrence.notification_sent, _build_digest_window_filter(), _join=[Reservation, Room]) digests = defaultdict(list) for occurrence in occurrences: digests[occurrence.reservation].append(occurrence) try: for reservation, occurrences in digests.iteritems(): notify_reservation_digest(reservation, occurrences) for occurrence in occurrences: occurrence.notification_sent = True finally: db.session.commit()
def roombooking_occurrences(debug=False): if not config.ENABLE_ROOMBOOKING: logger.info('Notifications not sent because room booking is disabled') return if not rb_settings.get('notifications_enabled'): logger.info('Notifications not sent because they are globally disabled') return occurrences = (ReservationOccurrence.query .join(ReservationOccurrence.reservation) .join(Reservation.room) .filter(Room.is_active, Room.notifications_enabled, Reservation.is_accepted, Reservation.booked_for_id.isnot(None), ReservationOccurrence.is_valid, ReservationOccurrence.start_dt >= datetime.now(), ~ReservationOccurrence.notification_sent, _make_occurrence_date_filter()) .order_by(Reservation.booked_for_id, ReservationOccurrence.start_dt, Room.id) .options(contains_eager('reservation').contains_eager('room')) .all()) for user, user_occurrences in groupby(occurrences, key=attrgetter('reservation.booked_for_user')): user_occurrences = list(user_occurrences) if debug: _print_occurrences(user, user_occurrences) else: _notify_occurrences(user, user_occurrences) if not debug: db.session.commit()
def roombooking_end_notifications(): if not config.ENABLE_ROOMBOOKING: logger.info('Notifications not sent because room booking is disabled') return if not rb_settings.get('end_notifications_enabled'): logger.info( 'Notifications not sent because they are globally disabled') return defaults = { 'default': rb_settings.get('end_notification_daily'), 'weekly': rb_settings.get('end_notification_weekly'), 'monthly': rb_settings.get('end_notification_monthly') } room_columns = { 'default': Room.end_notification_daily, 'weekly': Room.end_notification_weekly, 'monthly': Room.end_notification_monthly } cte = (db.session.query( Reservation.id, Reservation.repeat_frequency).add_columns( db.func.max(ReservationOccurrence.start_dt).label( 'last_valid_end_dt')).join(Reservation.room).join( Reservation.occurrences).filter( ReservationOccurrence.is_valid, ReservationOccurrence.end_dt >= datetime.now(), Reservation.is_accepted, Reservation.repeat_frequency != RepeatFrequency.NEVER, Room.end_notifications_enabled, ~Reservation.end_notification_sent, ~Room.is_deleted).group_by(Reservation.id).cte()) reservations = (Reservation.query.options(noload('created_by_user')).join( cte, cte.c.id == Reservation.id).join(Reservation.room).filter( _make_occurrence_date_filter(cte.c.last_valid_end_dt, defaults, room_columns, cte.c.repeat_frequency)).order_by( 'booked_for_id', 'start_dt', 'room_id').all()) for user, user_reservations in groupby(reservations, key=attrgetter('booked_for_user')): user_reservations = list(user_reservations) notify_about_finishing_bookings(user, list(user_reservations)) for user_reservation in user_reservations: user_reservation.end_notification_sent = True db.session.commit()
def _process_DELETE(self): # XXX: we could safely allow deleting any locations regardless of whether there # are rooms now that we soft-delete them. but it's probably safer to disallow # deletion of locations with rooms, simply to prevent accidental deletions. if self.location.rooms: raise ExpectedError(_('Cannot delete location with active rooms')) self.location.is_deleted = True logger.info('Location %r deleted by %r', self.location, session.user) # this code currently doesn't do anything since we don't allow deleting locations # that have non-deleted rooms, but if we change this in the future it's needed for room in self.location.rooms: logger.info('Deleting room %r', room) room.is_deleted = True db.session.flush() return '', 204
def roombooking_occurrences(debug=False): if not config.ENABLE_ROOMBOOKING: logger.info('Notifications not sent because room booking is disabled') return if not rb_settings.get('notifications_enabled'): logger.info( 'Notifications not sent because they are globally disabled') return defaults = { 'default': rb_settings.get('notification_before_days'), 'weekly': rb_settings.get('notification_before_days_weekly'), 'monthly': rb_settings.get('notification_before_days_monthly') } room_columns = { 'default': Room.notification_before_days, 'weekly': Room.notification_before_days_weekly, 'monthly': Room.notification_before_days_monthly } occurrences = (ReservationOccurrence.query.join( ReservationOccurrence.reservation).join(Reservation.room).filter( ~Room.is_deleted, Room.notifications_enabled, Reservation.is_accepted, Reservation.booked_for_id.isnot(None), ReservationOccurrence.is_valid, ReservationOccurrence.start_dt >= datetime.now(), ~ReservationOccurrence.notification_sent, _make_occurrence_date_filter( ReservationOccurrence.start_dt, defaults, room_columns)).order_by( Reservation.booked_for_id, ReservationOccurrence.start_dt, Room.id).options( contains_eager('reservation').contains_eager( 'room')).all()) for user, user_occurrences in groupby( occurrences, key=attrgetter('reservation.booked_for_user')): user_occurrences = list(user_occurrences) if debug: _print_occurrences(user, user_occurrences) else: _notify_occurrences(user, user_occurrences) if not debug: db.session.commit()
def roombooking_end_notifications(): if not config.ENABLE_ROOMBOOKING: logger.info('Notifications not sent because room booking is disabled') return if not rb_settings.get('end_notifications_enabled'): logger.info( 'Notifications not sent because they are globally disabled') return defaults = { 'default': rb_settings.get('end_notification_daily'), 'weekly': rb_settings.get('end_notification_weekly'), 'monthly': rb_settings.get('end_notification_monthly') } room_columns = { 'default': Room.end_notification_daily, 'weekly': Room.end_notification_weekly, 'monthly': Room.end_notification_monthly } reservations = (Reservation.query.join(Reservation.room).filter( ~Room.is_deleted, Room.end_notifications_enabled, Reservation.is_accepted, Reservation.end_dt >= datetime.now(), Reservation.repeat_frequency != RepeatFrequency.NEVER, ~Reservation.end_notification_sent, _make_occurrence_date_filter(Reservation.end_dt, defaults, room_columns)).order_by( Reservation.booked_for_id, Reservation.start_dt, Room.id).all()) for user, user_reservations in groupby(reservations, key=attrgetter('booked_for_user')): user_reservations = list(user_reservations) notify_about_finishing_bookings(user, list(user_reservations)) for user_reservation in user_reservations: user_reservation.end_notification_sent = True db.session.commit()
def _process_DELETE(self): logger.info('Room %r deleted by %r', self.room, session.user) self.room.is_deleted = True return '', 204
def _process_DELETE(self): if not rb_is_admin(session.user): raise Forbidden logger.info('Room %r deleted by %r', self.room, session.user) self.room.is_deleted = True return '', 204