Ejemplo n.º 1
0
def add_horse():
    """
    Добавление автомобиля
    """
    # если пользователь не авторизован, кидаем его на страницу входа
    if 'username' not in session:
        return redirect('login')
    # если админ, то его на свою страницу
    if session['username'] != 'admin':
        return redirect('index')
    form = AddCarForm()
    available_dealers = [(i[0], i[1]) for i in DealersModel(db.get_connection()).get_all()]
    form.dealer_id.choices = available_dealers
    if form.validate_on_submit():
        # создать автомобиль
        cars = CarsModel(db.get_connection())
        #file = form.image.data
        #print(form.image.data)
        #file.save(os.path.join(
        #          "static", "img", file.filename
        #      ))   
        filename = os.path.join(
                  "static", "img", "horse.jpg"
              )      
        cars.insert(model=form.model.data,
                    price=form.price.data,
                    power=form.power.data,
                    image_id=filename,
                    dealer=form.dealer_id.data)
        # редирект на главную страницу
        return redirect(url_for('horse_admin'))
    return render_template("add_car.html", title='Добавление автомобиля', form=form)
Ejemplo n.º 2
0
def add_car():
    """
    Добавление модели обуви
    """
    # если пользователь не авторизован, кидаем его на страницу входа
    if 'username' not in session:
        return redirect('login')
    # если админ, то его на свою страницу
    if session['username'] != 'admin':
        return redirect('index')
    form = AddCarForm()
    available_dealers = [(i[0], i[1])
                         for i in DealersModel(db.get_connection()).get_all()]
    form.dealer_id.choices = available_dealers
    if form.validate_on_submit():
        # создать автомобиль
        cars = CarsModel(db.get_connection())
        cars.insert(model=form.model.data,
                    price=form.price.data,
                    power=form.power.data,
                    color=form.color.data,
                    dealer=form.dealer_id.data)
        # редирект на главную страницу
        return redirect(url_for('car_admin'))
    return render_template("add_car.html", title='Добавление обуви', form=form)
Ejemplo n.º 3
0
def add_car():
    """
    Добавление автомобиля
    """
    # если пользователь не авторизован, кидаем его на страницу входа
    if 'username' not in session:
        return redirect('login')
    # если админ, то его на свою страницу
    if session['username'] != 'admin':
        return redirect('index')
    form = AddCarForm()
    available_dealers = [(i[0], i[1]) for i in DealersModel(db.get_connection()).get_all()]
    form.country.choices = available_dealers

    if form.validate_on_submit():
        # создать автомобиль
        form.save_im()
        print(form.image, form.image.data)
        cars = CarsModel(db.get_connection())
        cars.insert(model=form.name.data,
                    price=form.price.data,
                    power=form.adress.data,
                    color=form.description.data,
                    dealer=form.country.data,
                    image=os.path.join('static', 'img', form.image.data.filename))
        # редирект на главную страницу
        return redirect(url_for('car_admin'))
    return render_template("add_car.html", title='Добавление отеля', form=form)
Ejemplo n.º 4
0
def delete_horse(car_id):
    if 'username' not in session:
        return redirect('/login')
    if session['username'] != 'admin':
        return redirect(url_for('index'))
    CarsModel(db.get_connection()).delete(car_id)
    return redirect(url_for('horse_admin'))
Ejemplo n.º 5
0
def add_car():
    if 'username' not in session:
        return redirect('login')
    if session['username'] != 'admin':
        return redirect('index')
    form = AddCarForm()
    available_dealers = [(i[0], i[1])
                         for i in DealersModel(db.get_connection()).get_all()]
    form.dealer_id.choices = available_dealers
    if form.validate_on_submit():
        cars = CarsModel(db.get_connection())
        cars.insert(model=form.model.data,
                    price=form.price.data,
                    power=form.power.data,
                    color=form.color.data,
                    dealer=form.dealer_id.data)
        return redirect(url_for('car_admin'))
    return render_template("add_car.html", title='Добавление дома', form=form)
Ejemplo n.º 6
0
def search_dealer():

    form = SearchDealerForm()
    available_dealers = [(i[0], i[1]) for i in DealersModel(db.get_connection()).get_all()]
    form.dealer_id.choices = available_dealers
    if form.validate_on_submit():
        #
        cars = CarsModel(db.get_connection()).get_by_dealer(form.dealer_id.data)
        # редирект на главную страницу
        return render_template('car_user.html', username=session['username'], title='Просмотр базы', cars=cars)
    return render_template("search_dealer.html", title='Подбор по цене', form=form)
Ejemplo n.º 7
0
def search_price():
    """
    Запрос автомобилей, удовлетворяющих определенной цене
    """
    form = SearchPriceForm()
    if form.validate_on_submit():
        # получить все машины по определенной цене
        cars = CarsModel(db.get_connection()).get_by_price(form.start_price.data, form.end_price.data)
        # редирект на страницу с результатами
        return render_template('car_user.html', username=session['username'], title='Просмотр базы', cars=cars)
    return render_template("search_price.html", title='Подбор по цене', form=form)
Ejemplo n.º 8
0
def car_admin():
    if 'username' not in session:
        return redirect('/login')
    if session['username'] != 'admin':
        flash('Доступ запрещен')
        redirect('index')
    cars = CarsModel(db.get_connection()).get_all()
    return render_template('car_admin.html',
                           username=session['username'],
                           title='Просмотр домов',
                           cars=cars)
Ejemplo n.º 9
0
def index():
    if 'username' not in session:
        return redirect('/login')
    if session['username'] == 'admin':
        return render_template('index_admin.html',
                               username=session['username'])
    cars = CarsModel(db.get_connection()).get_all()
    return render_template('car_user.html',
                           username=session['username'],
                           title='Просмотр базы',
                           cars=cars)
Ejemplo n.º 10
0
def car(car_id):
    if 'username' not in session:
        return redirect('/login')
    '''if session['username'] != 'admin':
        return redirect(url_for('index'))'''
    car = CarsModel(db.get_connection()).get(car_id)
    dealer = DealersModel(db.get_connection()).get(car[5])
    return render_template('car_info.html',
                           username=session['username'],
                           title='Просмотр дома',
                           car=car,
                           dealer=dealer[1])
Ejemplo n.º 11
0
def search_price():
    form = SearchPriceForm()
    if form.validate_on_submit():
        cars = CarsModel(db.get_connection()).get_by_price(
            form.start_price.data, form.end_price.data)
        return render_template('car_user.html',
                               username=session['username'],
                               title='Просмотр базы',
                               cars=cars)
    return render_template("search_price.html",
                           title='Подбор по цене',
                           form=form)
Ejemplo n.º 12
0
def car_admin():
    # если пользователь не авторизован, кидаем его на страницу входа
    if 'username' not in session:
        return redirect('/login')
    # если админ, то его на свою страницу
    if session['username'] != 'admin':
        flash('Доступ запрещен')
        redirect('index')
    # если обычный пользователь, то его на свою
    cars = CarsModel(db.get_connection()).get_all()
    return render_template('car_admin.html',
                           username=session['username'],
                           title='Просмотр игр',
                           cars=cars)
Ejemplo n.º 13
0
def index():
    """
    Главная страница
    :return:
    Основная страница сайта, либо редирект на авторизацю
    """
    # если пользователь не авторизован, кидаем его на страницу входа
    if 'username' not in session:
        return redirect('/login')
    # если админ, то его на свою страницу
    if session['username'] == 'admin':
        return render_template('index_admin.html', username=session['username'])
    # если обычный пользователь, то его на свою
    cars = CarsModel(db.get_connection()).get_all()
    return render_template('car_user.html', username=session['username'], title='Просмотр базы', cars=cars)
Ejemplo n.º 14
0
def car(car_id):

    # если пользователь не авторизован, кидаем его на страницу входа
    if 'username' not in session:
        return redirect('/login')
    # если не админ, то его на главную страницу
    '''if session['username'] != 'admin':
        return redirect(url_for('index'))'''
    # иначе выдаем информацию
    car = CarsModel(db.get_connection()).get(car_id)
    dealer = DealersModel(db.get_connection()).get(car[5])
    return render_template('car_info.html',
                           username=session['username'],
                           title='Просмотр игры',
                           car=car,
                           dealer=dealer[1])
Ejemplo n.º 15
0
def car_admin():
    """
    Вывод всей информации об всех моделях обуви
    :return:
    информация для авторизованного пользователя
    """
    # если пользователь не авторизован, кидаем его на страницу входа
    if 'username' not in session:
        return redirect('/login')
    # если админ, то его на свою страницу
    if session['username'] != 'admin':
        flash('Доступ запрещен')
        redirect('index')
    # если обычный пользователь, то его на свою
    cars = CarsModel(db.get_connection()).get_all()
    return render_template('car_admin.html',
                           username=session['username'],
                           title='Просмотр обуви',
                           cars=cars)
Ejemplo n.º 16
0
def search_dealer():
    """
    Запрос автомобилей, продающихся в определенном дилерском центре
    """
    form = SearchDealerForm()
    available_dealers = [(i[0], i[1])
                         for i in DealersModel(db.get_connection()).get_all()]
    form.dealer_id.choices = available_dealers
    if form.validate_on_submit():
        #
        cars = CarsModel(db.get_connection()).get_by_dealer(
            form.dealer_id.data)
        # редирект на главную страницу
        return render_template('car_user.html',
                               username=session['username'],
                               title='Просмотр каталога',
                               cars=cars)
    return render_template("search_dealer.html",
                           title='Подбор по магазину',
                           form=form)
Ejemplo n.º 17
0
def car(car_id):
    """
    Вывод всей информации об автомобиле
    :return:
    информация для авторизованного пользователя
    """
    # если пользователь не авторизован, кидаем его на страницу входа
    if 'username' not in session:
        return redirect('/login')
    # если не админ, то его на главную страницу
    '''if session['username'] != 'admin':
        return redirect(url_for('index'))'''
    # иначе выдаем информацию
    car = CarsModel(db.get_connection()).get(car_id)
    dealer = DealersModel(db.get_connection()).get(car[5])
    isAdmin = session['username'] == "admin"
    print(session['username'] == "admin", session['username'])
    return render_template('car_info.html',
                           isAdmin=isAdmin,
                           car_id=car_id,
                           username=session['username'],
                           title='Просмотр автомобиля',
                           car=car,
                           dealer=dealer[1])
Ejemplo n.º 18
0
from flask import Flask, session, redirect, render_template, flash, url_for
from werkzeug.security import generate_password_hash, check_password_hash
from models import UsersModel, CarsModel, DealersModel
from forms import LoginForm, RegisterForm, AddCarForm, SearchPriceForm, SearchDealerForm, AddDealerForm
from db import DB

app = Flask(__name__)
app.config['SECRET_KEY'] = 'yandexlyceum_secret_key'
db = DB()
UsersModel(db.get_connection()).init_table()
CarsModel(db.get_connection()).init_table()
DealersModel(db.get_connection()).init_table()


@app.route('/')
@app.route('/index')
def index():
    """
    Главная страница
    :return:
    Основная страница сайта, либо редирект на авторизацю
    """
    # если пользователь не авторизован, кидаем его на страницу входа
    if 'username' not in session:
        return redirect('/login')
    # если админ, то его на свою страницу
    if session['username'] == 'admin':
        return render_template('index_admin.html',
                               username=session['username'])
    # если обычный пользователь, то его на свою
    cars = CarsModel(db.get_connection()).get_all()
Ejemplo n.º 19
0
def buy_horse(car_id):
    if 'username' not in session:
        return redirect('/login')
    CarsModel(db.get_connection()).delete(car_id)
    return redirect(url_for('index'))
Ejemplo n.º 20
0
def delete_car(car_id):
    cars = CarsModel(db.get_connection())
    cars.delete(car_id=car_id)
    return redirect(url_for('car_admin'))