예제 #1
0
def cars():
    """
    Show the car hire page
    :return: the car hire page
    """
    session_id = request.args.get('session-id', None)
    user_id = request.args.get('user-id', None)
    cars_list = get_cars_list()
    current_year = get_current_year()
    brands_list = get_car_brands_list()
    car_types_list = get_car_types_list()
    car_n_seats_list = get_car_n_seats_list()
    fuel_list = get_fuel_list()
    min_power = get_min_car_power_value()
    max_power = get_max_car_power_value()
    oldest_car_age_value = get_oldest_car_age()
    min_price = get_min_car_price_per_day()
    max_price = get_max_car_price_per_day()
    today = datetime.date.today()
    if check_authentication(session_id, user_id):
        return render_template('cars.html', user=user_id, session_id=session_id, cars_list=cars_list,
                               n_cars=cars_list.__len__(), current_year=current_year, brands_list=brands_list,
                               car_types_list=car_types_list, car_n_seats_list=car_n_seats_list, fuel_list=fuel_list,
                               min_power=min_power, max_power=max_power, oldest_car_age_value=oldest_car_age_value,
                               min_price=min_price, max_price=max_price, today=today)
    else:
        return render_template('cars.html',  cars_list=cars_list, n_cars=cars_list.__len__(), current_year=current_year,
                               brands_list=brands_list, car_types_list=car_types_list,
                               car_n_seats_list=car_n_seats_list, fuel_list=fuel_list, min_power=min_power,
                               max_power=max_power, oldest_car_age_value=oldest_car_age_value, min_price=min_price,
                               max_price=max_price, today=today)
예제 #2
0
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)
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
def after_auth_redirect(template, car_id, username):
    """
    Redirect the user to the page previously visited before the login
    :param template: the page previously visited before the login
    :param car_id: the ID of the selected car
    :param username: the email address of the user logged in
    :return: the page previously visited before the login
    """
    session_id = generate_session(username)
    current_year = get_current_year()
    today = datetime.date.today()
    if template == "cars.html":
        return render_template('cars.html', user=username, session_id=session_id, current_year=current_year,
                               oldest_car_age_value=get_oldest_car_age(), n_cars=get_cars_list().__len__(),
                               cars_list=get_cars_list(), today=today)
    elif template == "car_details.html":
        car = get_car_identified_by_id(car_id)
        return render_template('car_details.html', car=car, user=username, session_id=session_id, today=today)
    elif template == "about.html":
        return render_template('about.html', user=username, session_id=session_id)
    else:
        return render_template('home.html', cars_list=get_cars_preview(), news_list=get_news_list(), user=username, session_id=session_id, authjs=False, preview_length=get_cars_preview().__len__())
예제 #6
0
def filter_cars():
    """
    Filter the list of cars on the base of the filters selected by the user
    :return: the web page of car hire with the search results
    """
    session_id = request.args.get('session-id', None)
    user_id = request.args.get('user-id', None)
    current_year = get_current_year()
    brands_list = get_car_brands_list()
    car_types_list = get_car_types_list()
    car_n_seats_list = get_car_n_seats_list()
    fuel_list = get_fuel_list()
    min_power = get_min_car_power_value()
    max_power = get_max_car_power_value()
    oldest_car_age_value = get_oldest_car_age()
    min_price = get_min_car_price_per_day()
    max_price = get_max_car_price_per_day()
    today = datetime.date.today()

    if request.method == 'POST':
        brand_filter = request.form['car-brand']
        type_filter = request.form['car-type']
        n_seats_filter = request.form['n-seats']
        min_power_filter = request.form['car-min-power']
        max_power_filter = request.form['car-max-power']
        fuel_filter = request.form['car-fuel']
        transmission_filter = request.form['car-transmission']
        car_year_from_filter = request.form['car-year-from']
        car_year_to_filter = request.form['car-year-to']
        driver_age_filter = request.form['driver-age']
        min_price_day_filter = request.form['min-price-day']
        max_price_day_filter = request.form['max-price-day']
        rent_date_from_filter = request.form['rent-date-from']
        rent_date_to_filter = request.form['rent-date-to']
        cars_list = filter_cars_by_user_parameters(brand_filter, type_filter, n_seats_filter, min_power_filter,
                                                   max_power_filter, fuel_filter, transmission_filter,
                                                   car_year_from_filter, car_year_to_filter, driver_age_filter,
                                                   min_price_day_filter, max_price_day_filter, rent_date_from_filter,
                                                   rent_date_to_filter)
        try:
            driver_age_filter = int(driver_age_filter)
        except ValueError:
            pass

        if check_authentication(session_id, user_id):
            return render_template('cars.html', user=user_id, session_id=session_id, cars_list=cars_list,
                                   n_cars=cars_list.__len__(), current_year=int(current_year), brands_list=brands_list,
                                   car_types_list=car_types_list, car_n_seats_list=car_n_seats_list,
                                   fuel_list=fuel_list, min_power=min_power, max_power=max_power,
                                   oldest_car_age_value=oldest_car_age_value, min_price=min_price, max_price=max_price,
                                   brand_filter=brand_filter, type_filter=type_filter,
                                   n_seats_filter=n_seats_filter, min_power_filter=min_power_filter,
                                   max_power_filter=max_power_filter, fuel_filter=fuel_filter,
                                   transmission_filter=transmission_filter,
                                   car_year_from_filter=int(car_year_from_filter),
                                   car_year_to_filter=int(car_year_to_filter), driver_age_filter=driver_age_filter,
                                   min_price_day_filter=min_price_day_filter, max_price_day_filter=max_price_day_filter,
                                   rent_date_from_filter=rent_date_from_filter, rent_date_to_filter=rent_date_to_filter,
                                   today=today)
        else:
            return render_template('cars.html',  cars_list=cars_list, n_cars=cars_list.__len__(),
                                   current_year=int(current_year), brands_list=brands_list,
                                   car_types_list=car_types_list, car_n_seats_list=car_n_seats_list,
                                   fuel_list=fuel_list, min_power=min_power, max_power=max_power,
                                   oldest_car_age_value=oldest_car_age_value, min_price=min_price, max_price=max_price,
                                   brand_filter=brand_filter, type_filter=type_filter,
                                   n_seats_filter=n_seats_filter, min_power_filter=min_power_filter,
                                   max_power_filter=max_power_filter, fuel_filter=fuel_filter,
                                   transmission_filter=transmission_filter,
                                   car_year_from_filter=int(car_year_from_filter),
                                   car_year_to_filter=int(car_year_to_filter), driver_age_filter=driver_age_filter,
                                   min_price_day_filter=min_price_day_filter, max_price_day_filter=max_price_day_filter,
                                   rent_date_from_filter=rent_date_from_filter, rent_date_to_filter=rent_date_to_filter,
                                   today=today)
    else:
        cars_list = get_cars_list()
        if check_authentication(session_id, user_id):
            return render_template('cars.html', user=user_id, session_id=session_id, cars_list=cars_list,
                                   n_cars=cars_list.__len__(), current_year=current_year, brands_list=brands_list,
                                   car_types_list=car_types_list, car_n_seats_list=car_n_seats_list,
                                   fuel_list=fuel_list, min_power=min_power, max_power=max_power,
                                   oldest_car_age_value=oldest_car_age_value, min_price=min_price,
                                   max_price=max_price, today=today)
        else:
            return render_template('cars.html',  cars_list=cars_list, n_cars=cars_list.__len__(),
                                   current_year=current_year, brands_list=brands_list, car_types_list=car_types_list,
                                   car_n_seats_list=car_n_seats_list, fuel_list=fuel_list, min_power=min_power,
                                   max_power=max_power, oldest_car_age_value=oldest_car_age_value, min_price=min_price,
                                   max_price=max_price, today=today)