def admin_user_area(): """ Show the user area of the admin user :return: the private area of the user if credentials are valid, otherwise it returns the home page """ session_id = request.args.get('session-id', None) user_id = request.args.get('user-id', None) edit = request.args.get('edit', None) today = datetime.date.today() reservations_list = get_user_reservations_list(user_id) cars_reservations_list = get_cars_user_reservations_list(reservations_list) reservations_status_list = get_reservations_status_list(reservations_list) if edit == "true": edit_mode = True else: edit_mode = False user = get_user_by_id(user_id) if check_authentication(session_id, user_id) and is_admin_user(user_id): return render_template('user_area.html', user=user_id, session_id=session_id, edit_mode=edit_mode, surname=user.surname, name=user.name, birthdate=user.birthdate, today=today, reservations_list=reservations_list, cars_reservations_list=cars_reservations_list, reservations_status_list=reservations_status_list, admin=True) else: return render_template('home.html', cars_list=get_cars_preview(), news_list=get_news_list(), authjs=False, preview_length=get_cars_preview().__len__(), del_session_cookie=True)
def admin_add_car(): """ Show the web page for adding a new car :return: the form for adding a new car if admin credentials are valid, otherwise it returns the home page """ session_id = request.args.get('session-id', None) user_id = request.args.get('user-id', None) if check_authentication(session_id, user_id) and is_admin_user(user_id): return render_template('new_car.html', user=user_id, session_id=session_id, current_year=get_current_year()) else: return render_template('home.html', cars_list=get_cars_preview(), news_list=get_news_list(), authjs=False, preview_length=get_cars_preview().__len__(), del_session_cookie=True)
def list_all_users(): """ Show the list of all users :return: the list of all users if admin credentials are valid, otherwise it returns the home page """ session_id = request.args.get('session-id', None) user_id = request.args.get('user-id', None) users_list = get_users_list() if check_authentication(session_id, user_id) and is_admin_user(user_id): return render_template('admin_area.html', user=user_id, session_id=session_id, users_list=users_list) else: return render_template('home.html', cars_list=get_cars_preview(), news_list=get_news_list(), authjs=False, preview_length=get_cars_preview().__len__(), del_session_cookie=True)
def admin_update_account_type(): """ Change the user's privileges :return: the list of all users if admin credentials are valid, otherwise it returns the home page """ session_id = request.args.get('session-id', None) user_id = request.args.get('user-id', None) user_id_to_update = request.args.get('user-id-to-update', None) account_type = request.args.get('account-type', None) if check_authentication(session_id, user_id) and is_admin_user(user_id): update_account_type(user_id_to_update, account_type) users_list = get_users_list() return render_template('admin_area.html', user=user_id, session_id=session_id, users_list=users_list) else: return render_template('home.html', cars_list=get_cars_preview(), news_list=get_news_list(), authjs=False, preview_length=get_cars_preview().__len__(), del_session_cookie=True)
def admin_delete_news(): """ Delete a news :return: the list of news if admin credentials are valid, otherwise it returns the home page """ session_id = request.args.get('session-id', None) user_id = request.args.get('user-id', None) news_id = request.args.get('news-id', None) if check_authentication(session_id, user_id) and is_admin_user(user_id): delete_news(news_id) news_list = get_news_list() return render_template('news_manager.html', user=user_id, session_id=session_id, edit_mode=False, news_list=news_list) else: return render_template('home.html', cars_list=get_cars_preview(), news_list=get_news_list(), authjs=False, preview_length=get_cars_preview().__len__(), del_session_cookie=True)
def admin_delete_car(): """ Delete a car :return: delete the car and return admin area if admin credentials are valid, otherwise it returns the home page """ session_id = request.args.get('session-id', None) user_id = request.args.get('user-id', None) car_id = request.args.get('car-id', None) if check_authentication(session_id, user_id) and is_admin_user(user_id): delete_car(car_id) cars_list = get_cars_list() return render_template('admin_area.html', user=user_id, session_id=session_id, cars_list=cars_list, cars_list_mode=True) else: return render_template('home.html', cars_list=get_cars_preview(), news_list=get_news_list(), authjs=False, preview_length=get_cars_preview().__len__(), del_session_cookie=True)
def save_new_car(): """ Save the new car into the database :return: the new car's details if admin credentials are valid, otherwise it returns the home page """ session_id = request.args.get('session-id', None) user_id = request.args.get('user-id', None) if request.method == 'POST': brand = request.form['brand-text'] model = request.form['model-text'] car_year = request.form['car-year-text'] n_seats = request.form['n-seats-text'] car_type = request.form['type-text'] engine = request.form['engine-text'] fuel = request.form['fuel-text'] power = request.form['power-text'] transmission = request.form['transmission-text'] min_age = request.form['min-age-text'] price = request.form['price-day-text'] str_preview = request.form['preview'] if str_preview == "Yes": preview = True else: preview = False if check_authentication(session_id, user_id) and is_admin_user(user_id): if 'file' in request.files: file = request.files['file'] if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) car_id = add_car(brand, model, car_year, n_seats, car_type, engine, fuel, power, transmission, min_age, price, filename, preview) print(car_id) car = get_car_identified_by_id(car_id) return render_template('cars_manager.html', user=user_id, session_id=session_id, car=car, edit_mode=False) else: return render_template('new_car.html', user=user_id, session_id=session_id, current_year=get_current_year(), img_error=True) else: return render_template('new_car.html', user=user_id, session_id=session_id, current_year=get_current_year(), img_error=True) else: return render_template('home.html', cars_list=get_cars_preview(), news_list=get_news_list(), authjs=False, preview_length=get_cars_preview().__len__(), del_session_cookie=True)
def admin_add_news(): """ Save a new news into the database :return: the list of all news if admin credentials are valid, otherwise it returns the home page """ session_id = request.args.get('session-id', None) user_id = request.args.get('user-id', None) if request.method == 'POST': news_content = request.form['news-content'] if check_authentication(session_id, user_id) and is_admin_user(user_id): save_news(news_content) news_list = get_news_list() return render_template('news_manager.html', user=user_id, session_id=session_id, edit_mode=False, news_list=news_list) else: return render_template('home.html', cars_list=get_cars_preview(), news_list=get_news_list(), authjs=False, preview_length=get_cars_preview().__len__(), del_session_cookie=True)
def edit_car_view(): """ Show the web page for editing cars' information :return: the the web page for editing car's information if admin credentials are valid, otherwise it returns the home page """ session_id = request.args.get('session-id', None) user_id = request.args.get('user-id', None) car_id = request.args.get('car-id', None) edit_mode_string = request.args.get('edit', None) if edit_mode_string == 'true': edit_mode = True else: edit_mode = False car = get_car_identified_by_id(car_id) if check_authentication(session_id, user_id) and is_admin_user(user_id): return render_template('cars_manager.html', user=user_id, session_id=session_id, car=car, edit_mode=edit_mode, current_year=get_current_year()) else: return render_template('home.html', cars_list=get_cars_preview(), news_list=get_news_list(), authjs=False, preview_length=get_cars_preview().__len__(), del_session_cookie=True)
def list_all_reservations(): """ Show the list of reservations :return: the list of reservations if admin credentials are valid, otherwise it returns the home page """ session_id = request.args.get('session-id', None) user_id = request.args.get('user-id', None) reservation_filter = request.args.get('reservation-filter', None) reservations_list = get_all_reservations_list(reservation_filter) cars_reservations_list = get_cars_user_reservations_list(reservations_list) reservations_status_list = get_reservations_status_list(reservations_list) users_list_for_reservations = get_users_list_for_reservations_list(reservations_list) if check_authentication(session_id, user_id) and is_admin_user(user_id): return render_template('admin_area.html', user=user_id, session_id=session_id, reservations_list=reservations_list, cars_reservations_list=cars_reservations_list, reservations_status_list=reservations_status_list, users_list_for_reservations=users_list_for_reservations, reservations_list_mode=True) else: return render_template('home.html', cars_list=get_cars_preview(), news_list=get_news_list(), authjs=False, preview_length=get_cars_preview().__len__(), del_session_cookie=True)