def get_broken_reservations(service_user, service_identity): service_identity_user = create_service_identity_user_wo_default( service_user, service_identity) filter_ = RestaurantReservation.all().filter("service_user =", service_identity_user) return generator( filter_.filter('status >=', RestaurantReservation.STATUS_SHIFT_REMOVED))
def get_planned_reservations_by_user(service_user, service_identity, user, from_): service_identity_user = create_service_identity_user_wo_default( service_user, service_identity) return generator(RestaurantReservation.all().filter( "service_user =", service_identity_user).filter('user', user).filter( 'status', RestaurantReservation.STATUS_PLANNED).filter( 'shift_start >=', from_))
def get_reservations(service_user, service_identity, from_=None, until=None): service_identity_user = create_service_identity_user_wo_default( service_user, service_identity) filter_ = RestaurantReservation.all().filter("service_user =", service_identity_user) if from_: filter_ = filter_.filter('shift_start >=', from_) if until: filter_ = filter_.filter('shift_start <', until) return generator(filter_)
def clear_table_id_in_reservations(service_user, service_identity, table_id): service_identity_user = create_service_identity_user_wo_default( service_user, service_identity) qry = RestaurantReservation.all().filter("service_user =", service_identity_user) qry.filter('tables =', table_id) reservations = qry.fetch(None) for r in reservations: r.tables.remove(table_id) put_and_invalidate_cache(*reservations)
def get_upcoming_planned_reservations_by_table(service_user, service_identity, table_id, from_): service_identity_user = create_service_identity_user_wo_default( service_user, service_identity) qry = RestaurantReservation.all().filter("service_user =", service_identity_user) qry.filter('tables =', table_id) qry.filter('status', RestaurantReservation.STATUS_PLANNED) qry.filter('shift_start >=', from_) return generator(qry)
def get_reservations_keys_qry(service_user, service_identity, from_=None, until=None): service_identity_user = create_service_identity_user_wo_default( service_user, service_identity) filter_ = RestaurantReservation.all(keys_only=True).filter( "service_user =", service_identity_user) if from_: filter_ = filter_.filter('shift_start >=', from_) if until: filter_ = filter_.filter('shift_start <', until) return filter_
def get_restaurant_reservation(service_user, service_identity, shift_start): service_identity_user = create_service_identity_user_wo_default( service_user, service_identity) return generator(RestaurantReservation.all().filter( "service_user =", service_identity_user).filter('shift_start =', shift_start))
def _7000_migrate_solution(job_key): phase = MigrateServiceJob.PHASE_7000_MIGRATE_SOLUTION next_phase = MigrateServiceJob.PHASE_8000_FINISH_MODELS # Validate that the job still exists job = _get_job(job_key, phase) # Do the work _log_progress(job) if job.solution: logging.info('0/ Migrate the solution models without ancestor, but with service_user as key name.') def trans0(): new_models = list() old_models = list() for model_class in (SolutionMainBranding, SolutionLogo, SolutionAvatar): old_model = db.get(model_class.create_key(job.from_service_user)) if old_model: kwargs = copy_model_properties(old_model) new_model = model_class(key=model_class.create_key(job.to_service_user), **kwargs) new_models.append(new_model) old_models.append(old_model) if new_models: put_and_invalidate_cache(*new_models) if old_models: db.delete(old_models) xg_on = db.create_transaction_options(xg=True) db.run_in_transaction_options(xg_on, trans0) old_sln_settings = get_solution_settings(job.from_service_user) identities = [None] if old_sln_settings.identities: identities.extend(old_sln_settings.identities) logging.info('1/ Migrate RestaurantReservations') for service_identity in identities: from_si_user = create_service_identity_user_wo_default(job.from_service_user, service_identity) to_si_user = create_service_identity_user_wo_default(job.to_service_user, service_identity) while True: reservations = RestaurantReservation.all().filter('service_user', from_si_user).fetch(300) if not reservations: break for r in reservations: r.service_user = to_si_user _put_and_invalidate_cache_and_allocate_ids(*reservations) logging.info('2/ Migrate EventReminders') for service_identity in identities: from_si_user = create_service_identity_user(job.from_service_user) to_si_user = create_service_identity_user(job.to_service_user) while True: reminders = EventReminder.all().filter('service_identity_user', from_si_user).fetch(300) if not reminders: break for r in reminders: r.service_identity_user = to_si_user _put_and_invalidate_cache_and_allocate_ids(*reminders) logging.info('3/ Migrate RestaurantProfile.reserve_flow_part2') restaurant_profile = db.get(RestaurantProfile.create_key(job.from_service_user)) if restaurant_profile and restaurant_profile.reserve_flow_part2: old_part2_key = db.Key(restaurant_profile.reserve_flow_part2) new_part2_key = db.Key.from_path(old_part2_key.kind(), old_part2_key.id_or_name(), parent=parent_key(job.to_service_user)) logging.debug('New key: %r', new_part2_key) restaurant_profile.reserve_flow_part2 = str(new_part2_key) _put_and_invalidate_cache_and_allocate_ids(restaurant_profile) logging.info('4/ Delete all SolutionQRs. They will be recreated when provisioning.') for service_identity in identities: service_identity_user = create_service_identity_user_wo_default(job.from_service_user, service_identity) db.delete(SolutionQR.all(keys_only=True).ancestor(parent_key_unsafe(service_identity_user, job.solution))) logging.info('5/ Delete Loyalty QR. It will be recreated when provisioning.') if SolutionModule.LOYALTY in old_sln_settings.modules: for service_identity in identities: if is_default_service_identity(service_identity): loyalty_i_settings = db.get(SolutionLoyaltySettings.create_key(job.from_service_user)) else: loyalty_i_settings = db.get( SolutionLoyaltyIdentitySettings.create_key(job.from_service_user, service_identity)) if loyalty_i_settings: loyalty_i_settings.image_uri = None loyalty_i_settings.content_uri = None _put_and_invalidate_cache_and_allocate_ids(loyalty_i_settings) logging.info('6/ Change ancestor keys of solution models.') for solution in ['common', job.solution]: for service_identity in identities: if is_default_service_identity(service_identity): _migrate_ancestor_models(job, parent_key(job.from_service_user, solution)) else: service_identity_user = create_service_identity_user_wo_default( job.from_service_user, service_identity) _migrate_ancestor_models(job, parent_key_unsafe(service_identity_user, solution)) sln_settings = get_solution_settings(job.to_service_user) sln_main_branding = get_solution_main_branding(job.to_service_user) users.set_user(job.to_service_user) try: populate_identity(sln_settings, sln_main_branding.branding_key) finally: users.clear_user() # Set the next phase _set_job_in_next_phase(job_key, phase, next_phase)