def manageHotel(hotel_id): logger.info("Got a manage hotel page request: %s" % request) db = AndrewDB() g.role = 'receptionist' recForm = CReceptionistForm() roomForm = CRoomForm() form = UDRoomForm() form2 = URoomForm() form3 = DReceptionistForm() form.csrf_enabled = False form2.csrf_enabled = False form3.csrf_enabled = False if current_user.is_hotel_admin(): if form.delete.data: if db.delete_room_by_id(form.room_id.data): flash('Room was removed') logger.info("Room was removed: ID = %s" % form.room_id.data) logger.info("Redirecting to manage hotel page") return redirect(url_for('manageHotel', hotel_id=hotel_id)) if form2.edit.data: logger.info("Validating the Update room form") if form2.validate_on_submit(): option_id = None config_id = None res = db.get_option_by_params(form2.is_bathroom.data, form2.is_tv.data, form2.is_wifi.data, form2.is_bathhub.data, form2.is_aircond.data) if not res: option_id = db.insert_option(form2.is_bathroom.data, form2.is_tv.data, form2.is_wifi.data, form2.is_bathhub.data, form2.is_aircond.data) else: option_id = res['option_id'] res = db.select_config(form2.sing_bed.data, form2.doub_bed.data, form2.sofa_bed.data) if not res: config_id = db.insert_config(form2.sing_bed.data, form2.doub_bed.data, form2.sofa_bed.data) else: config_id = res['config_id'] db.set_up_room_by_id(config_id, option_id, form2.quantity.data, form2.title.data, form2.description.data, form2.cost.data, form2.room_id.data) if form3.del_rec.data: if db.delete_receptionist_by_id(form3.user_id.data): flash("Receptionist was removed") logger.info("Receptionist was removed: ID = %s" % form3.user_id.data) if recForm.save.data: logger.info("Validating the Create receptionist form") if recForm.validate_on_submit(): hash_password = bcrypt.generate_password_hash( recForm.password.data).decode('utf-8') user_id = db.insert_sys_user_get_id(recForm.email.data, hash_password, g.role) if user_id: flash('User with this email already registered') else: logger.info("Redirecting to manage hotel page") redirect(url_for('manageHotel', hotel_id=hotel_id)) if db.add_new_receptionist(user_id, hotel_id, recForm.first_name.data, recForm.last_name.data, recForm.telephone.data, recForm.salary.data): flash("Receptionist was added") logger.info("Receptionist was added: ID = %s" % recForm.user_id.data) logger.info("Redirecting to manage hotel page") return redirect(url_for('manageHotel', hotel_id=hotel_id)) if roomForm.save.data: logger.info("Validating the Create room form") if roomForm.validate_on_submit(): option_id = None config_id = None res = db.get_option_by_params(roomForm.is_bathroom.data, roomForm.is_tv.data, roomForm.is_wifi.data, roomForm.is_bathhub.data, roomForm.is_aircond.data) if not res: option_id = db.insert_option(roomForm.is_bathroom.data, roomForm.is_tv.data, roomForm.is_wifi.data, roomForm.is_bathhub.data, roomForm.is_aircond.data) else: option_id = res['option_id'] res = db.select_config(roomForm.sing_bed.data, roomForm.doub_bed.data, roomForm.sofa_bed.data) if not res: config_id = db.insert_config(roomForm.sing_bed.data, roomForm.doub_bed.data, roomForm.sofa_bed.data) else: config_id = res['config_id'] db.add_new_room(hotel_id, config_id, option_id, roomForm.quantity.data, roomForm.title.data, roomForm.description.data, roomForm.cost.data) flash('Room was added') logger.info( "Receptionist was added (ID = %s), Redirecting to manage hotel page" % roomForm.user_id.data) return redirect(url_for('manageHotel', hotel_id=hotel_id)) hotel = db.get_hotel_by_id(hotel_id) rooms = db.get_rooms_with_settings_by_id(hotel_id) recep = db.get_receptionists_by_hotel_id(hotel_id) logger.info("Rendering the Manage hotel page") return render_template('manage_hotel.html', recForm=recForm, roomForm=roomForm, form=form, form2=form2, form3=form3, hotel=hotel, rooms=rooms, recep=recep) else: flash("Access error") logger.info("Access error, Redirecting to login page") return redirect(url_for('login'))
def test_delete_receptionist_by_id(mock_connect): """Remove receptionist user from database by its id""" with allure.step('Delete receptionist by id'): with app.app_context(): db = AndrewDB() db.delete_receptionist_by_id(1)