Exemplo n.º 1
0
def login_view():
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate():
        query = f"""
        SELECT * FROM Buser where login='******' and password='******';
        """
        user = db.db_get(query)
        if not user:
            return redirect('/register')
        session['current_user'] = user
        session['current_user_cart'] = db.db_get(
            f"select * from cart where Buser_id={user['id']}")
        if session.get('current_user')['role_id'] == 1:
            return redirect('/manage_orders/1')
        return redirect('/')
    return render_template('login.html', form=form)
Exemplo n.º 2
0
def services():
    if not session.get('current_user'):
        return redirect('/login')
    query = """
    SELECT * FROM Service;
    """
    data = db.db_get(query, cur_type='all')
    return render_template('services.html', data=data)
Exemplo n.º 3
0
 def post(self):
     json_data = request.get_json(force=True)
     data = {}
     key = json_data['key']
     val = db.db_get(key)
     if val is not None:
         data[key] = val
     return jsonify(data)
Exemplo n.º 4
0
def view_cart():
    if not session.get('current_user') or not session.get('current_user_cart'):
        return redirect('/login')
    data = db.db_get(
        f"""select * from service where id in (select service_id  from Service_cart_rel where cart_id={session.get('current_user_cart')['id']});""",
        cur_type='all')
    price = 0
    if data:
        for item in data:
            price += item['price']
    context = {'data': data, 'price': price}
    return render_template('cart.html', data=context)
Exemplo n.º 5
0
def register():
    form = RegisterForm(request.form)
    if request.method == 'POST' and form.validate():
        user = db.db_get(
            f"""select * from Buser where login='******';""")
        if user:
            return render_template(
                'register.html',
                form=form,
                alert='Юзер с таким логином уже существует'), 400
        query = f"insert into Buser (login, password, Role_id) values ('{form.login.data}', '{form.password.data}', 2);"
        db.db_save(query)
        user = db.db_get(
            f"""select * from Buser where login='******';""")
        session['current_user'] = user
        db.db_save(
            f"""insert into cart (Buser_id, Status_id) values ((SELECT MAX(id) FROM buser), 6);"""
        )
        session['current_user_cart'] = db.db_get(
            f"""select * from cart where Buser_id=(SELECT MAX(id) FROM buser);"""
        )
        return redirect('/')
    return render_template('register.html', form=form)
Exemplo n.º 6
0
def create_order():
    if not session.get('current_user'):
        return redirect('/login')
    form = OrderForm(request.form)
    price = request.args.get("price")
    user_id = session.get('current_user')['id']
    cart_id = session.get('current_user_cart')['id']
    if request.method == 'POST' and request.args.get("reject"):
        query = f"""update cart set status_id=7 where id={cart_id};
                     insert into cart (Buser_id, Status_id) values ({user_id}, 6);
                     insert into  border (Buser_id,Status_id,payment_type) values ({user_id}, 3, '{form.payment_type.data}');
                     insert into Order_cart_rel (Cart_id, Border_id) values ({cart_id},  (SELECT MAX(id) FROM border));"""
        db.db_save(query)
        session['current_user_cart'] = db.db_get(
            f'select * from cart where buser_id={user_id} and status_id=6;')
        return redirect('/rejected')
    elif request.method == 'POST' and price and form.validate():
        query = f"""UPDATE Buser set name='{form.name.data}', last_name='{form.last_name.data}', surname='{form.surname.data}', phone='{form.phone.data}' where id={user_id};
                    update cart set status_id=7 where id={cart_id};
                    insert into cart (Buser_id, Status_id) values ({user_id}, 6);
                    insert into  border (Buser_id,Status_id,payment_type, time, price) values ({user_id}, 1, '{form.payment_type.data}', to_timestamp('{form.time.data}', 'yyyy-mm-dd hh24:mi:ss'), {price});
                    insert into Order_cart_rel (Cart_id, Border_id) values ({cart_id},  (SELECT MAX(id) FROM border));
"""
        db.db_save(query)
        session['current_user_cart'] = db.db_get(
            f'select * from cart where buser_id={user_id} and status_id=6;')
        return redirect('/success')
    data = db.db_get(
        f"""select * from service where id in (select service_id  from Service_cart_rel where cart_id={session.get('current_user_cart')['id']});""",
        cur_type='all')
    price = 0
    if data:
        for item in data:
            price += item['price']
    context = {'data': data, 'price': price}
    return render_template('order.html', data=context, form=form)
Exemplo n.º 7
0
    def refresh(self):
        logging.debug("Refresh feed")
        if not self._last_refresh or time.time() - self._last_refresh > 10:
            self._last_refresh = time.time()

            logging.debug('Get feed from PlayUA')
            d = feedparser.parse(self.url)

            self.entries = []
            logging.debug(d['entries'])
            for entry in d['entries']:
                entry_in_db = db.db_get(entry['id'])

                if not entry_in_db:
                    logging.debug('Post %s not found in DB' % entry['id'])
                    db.db_set(entry['id'])
                    self.entries.append(entry)
            logging.debug("Refresh feed done")
Exemplo n.º 8
0
def manage_orders(status_id):
    if not session.get('current_user'):
        return redirect('/login')
    elif not session.get('current_user')['role_id'] == 1:
        return render_template('401.html')
    form = StatusForm(request.form)
    if request.method == 'POST':
        db.db_save(
            f'update border set Status_id={form.status.data} where id={request.args.get("ord_id")}'
        )

    query = f"""
            select distinct o.id, o.buser_id, o.payment_type, o.time , u.name, u.last_name, u.surname, u.phone , s.sname, o.price from border o
    full outer join buser u on o.buser_id = u.id inner join cart c on u.id = c.buser_id inner join Order_cart_rel ok
        on o.id = ok.border_id and c.id=ok.cart_id inner join  Service_cart_rel r on r.cart_id = c.id inner join
    service s on r.service_id = s.id and r.cart_id = c.id where o.status_id={status_id} and c.status_id=7 order by id;
"""

    db_data = db.db_get(query, cur_type='all')
    data = prepare_data(db_data)
    return render_template('orders.html',
                           data=data,
                           form=form,
                           status_id=status_id)