from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime


app = Flask(__name__, static_folder='static', static_url_path='')
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///product.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)


class Product(db.Model):
    """Class for products."""
    """another string"""

    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(length=50), nullable=False, unique=True)
    description = db.Column(db.String(), nullable=False)
    price = db.Column(db.String(length=10), nullable=False)
    img = db.Column(db.String(length=50), nullable=False)
    alt = db.Column(db.String(length=50), nullable=False)
    group = db.Column(db.String(length=25), nullable=False)


menu = [
    {"name": "Главная", "url": "home", "active": "", "aria": ""},
    {"name": "ЭЦП + Отчетность", "url": "astral_page", "active": "", "aria": ""},
    {"name": "Программы 1С", "url": "one_c_page", "active": "", "aria": ""},
    {"name": "Онлайн-кассы", "url": "kassa_page", "active": "", "aria": ""},
    {"name": "Контакты", "url": "contacts_page", "active": "", "aria": ""}
]


@app.context_processor
def inject_now():
    return {'now': datetime.utcnow()}


@app.route("/")
@app.route("/home")
def home():
    """Render home page."""
    for m in menu:
        m["active"] = ""
        m['aria'] = ''

    menu[0]['active'] = 'active'
    menu[0]['aria'] = 'page'
    return render_template("home.html", menu=menu,
                           title="ЭЦП, Программы 1С, Онлайн-кассы в Клину")


@app.route("/astral")
def astral_page():
    """Render astral page."""
    for m in menu:
        m['active'] = ''
        m['aria'] = ''

    menu[1]['active'] = 'active'
    menu[1]['aria'] = 'page'

    product_astral = Product.query.filter_by(group="astral")
    return render_template("astral.html", menu=menu, product=product_astral,
                           title="ЭЦП в Клину")


@app.route("/1c")
def one_c_page():
    """Render 1c page."""
    for m in menu:
        m['active'] = ''
        m['aria'] = ''

    menu[2]['active'] = 'active'
    menu[2]['aria'] = 'page'

    product_1c = Product.query.filter(Product
                                      .group.in_(["buh", "cloud", "trade"]))
    return render_template("1c.html", menu=menu,
                           title="программы 1С в Клину", product_1c=product_1c)


@app.route("/online-kassa")
def kassa_page():
    """Render kassa page."""
    for m in menu:
        m['active'] = ''
        m['aria'] = ''

    menu[3]['active'] = 'active'
    menu[3]['aria'] = 'page'

    product_kkt = Product.query.filter_by(group="kkt")
    product_fn = Product.query.filter_by(group="fn")
    return render_template("online-kassa.html", menu=menu,
                           title="Онлайн кассы в Клину",
                           product_kkt=product_kkt, product_fn=product_fn)


@app.route("/contacts")
def contacts_page():
    """Render contact page."""
    for m in menu:
        m['active'] = ''
        m['aria'] = ''

    menu[4]['active'] = 'active'
    menu[4]['aria'] = 'page'

    return render_template("contacts.html", menu=menu, title="Контакты")


@app.route("/1c/buhgalteria")
def buh_page():
    """Render buh page."""
    for m in menu:
        m['active'] = ''
        m['aria'] = ''

    menu[2]['active'] = 'active'
    menu[2]['aria'] = 'page'
    return render_template("buh.html", menu=menu, title="Программный продукт «1С:Бухгалтерия 8» для автоматизации бухгалтерского и налогового учета в Клину")


@app.route("/1c/zup")
def zup_page():
    """Render zup page."""
    for m in menu:
        m['active'] = ''
        m['aria'] = ''

    menu[2]['active'] = 'active'
    menu[2]['aria'] = 'page'
    return render_template("zup.html", menu=menu, title="Программный продукт 1С:Зарплата и управление персоналом в Клину")


@app.route("/1c/ut")
def ut_page():
    """Render ut page."""
    for m in menu:
        m['active'] = ''
        m['aria'] = ''

    menu[2]['active'] = 'active'
    menu[2]['aria'] = 'page'
    return render_template("ut.html", menu=menu, title="Программный продукт 1С:Управление торговлей в Клину")


@app.route("/1c/roznitsa")
def rozn_page():
    """Render rozn page."""
    for m in menu:
        m['active'] = ''
        m['aria'] = ''

    menu[2]['active'] = 'active'
    menu[2]['aria'] = 'page'
    return render_template("rozn.html", menu=menu, title="Программный продукт 1С: Розница в Клину")


@app.route("/1c/fresh")
def fresh_page():
    """Render fresh page."""
    for m in menu:
        m['active'] = ''
        m['aria'] = ''

    menu[2]['active'] = 'active'
    menu[2]['aria'] = 'page'
    return render_template("fresh.html", menu=menu, title="Программный продукт 1C: ФРЕШ в Клину")


@app.route("/1c/its")
def its_page():
    """Render its page."""
    for m in menu:
        m['active'] = ''
        m['aria'] = ''

    menu[2]['active'] = 'active'
    menu[2]['aria'] = 'page'
    return render_template("its.html", menu=menu, title="Программный продукт 1C: ИТС (КП) в Клину")


if __name__ == '__main__':
    app.run(host='0.0.0.0', debug=True)
