Beispiel #1
0
def delete(client_id):
    try:
        run_custom_query("""DELETE FROM CLIENTS WHERE ID = {}""".format(client_id), fetch=False)
        return redirect(url_for("clients.list"))
    except IntegrityError:
        flash("Client has got orders. Delete orders at first, then delete client.", "error")
        return redirect(url_for("clients.list"))
Beispiel #2
0
def delete_image(id):
    run_custom_query("""UPDATE product_images
        SET deleted = {}
        WHERE id = \'{}\'""".format(True, id), fetch=False)

    return jsonify({
        'success': True
    })
Beispiel #3
0
def delete(client_id):
    try:
        run_custom_query(
            """DELETE FROM CLIENTS WHERE ID = {}""".format(client_id),
            fetch=False)
        return redirect(url_for('clients.list'))
    except IntegrityError:
        flash(
            'Client has got orders. Delete orders at first, then delete client.',
            'error')
        return redirect(url_for('clients.list'))
Beispiel #4
0
def delete(id):
    product = select_row_from_table_by_id("products", id)
    if product is not None:
        run_custom_query("""SELECT delete_product({})""".format(id), fetch=False)
        flash(
            "Succesfully deleted product {}".format(product[0].name),
            "success"
        )
    else:
        flash("Product with ID={} does not exist".format(id), "danger")

    return redirect(url_for('product.list'))
Beispiel #5
0
def delete(id):
    if session.get('user') == id:
        flash("Don't delete yourself, it's bad idea :)", 'error')
        return redirect(url_for('users.list'))

    try:
        run_custom_query("""DELETE FROM users WHERE ID = {}""".format(id),
                         fetch=False)
        return redirect(url_for('users.list'))
    except IntegrityError:
        flash("User has got orders. Delete user's orders at first", 'error')

    return redirect(url_for('users.list'))
Beispiel #6
0
def delete(id):
    if session.get('user') == id:
        flash("Don't delete yourself, it's bad idea :)", 'error')
        return redirect(url_for('users.list'))

    try:
        run_custom_query(
            """DELETE FROM users WHERE ID = {}""".format(id),
            fetch=False
        )
        return redirect(url_for('users.list'))
    except IntegrityError:
        flash("User has got orders. Delete user's orders at first", 'error')

    return redirect(url_for('users.list'))
Beispiel #7
0
def edit_client(form, client_id):
    client_data = {
        'name': form.data['name'],
        'surname': form.data['surname'],
        'email': form.data['email'],
    }

    utils.run_custom_query(
            """DELETE FROM CLIENT_PHONES WHERE CLIENT_ID = {}""".format(
                client_id
            ),
            fetch=False
        )
    utils.update('clients', {'id': client_id},  client_data)
    for phone in form.data['phones']:
        if phone['phone']:
            utils.insert(
                'client_phones',
                {'client_id': client_id, 'phone': phone['phone']}
            )
    if form.data['billing_address']:
        billing = utils.select('client_addresses', {'client_id': client_id, 'type': 'billing'})
        data = form.data['billing_address']
        utils.update(
            'addresses',
            {
                'id': billing[0].id,
            },
            {
                'country': data['country'],
                'city': data['city'],
                'street': data['street']
            }
        )
    if form.data['delivery_address']:
        delivery = utils.select('client_addresses', {'client_id': client_id, 'type': 'delivery'})
        data = form.data['delivery_address']
        utils.update(
            'addresses',
            {
                'id': delivery[0].id,
            },
            {
                'country': data['country'],
                'city': data['city'],
                'street': data['street']
            }
        )
Beispiel #8
0
def get_orders_with_query(query):
    orders_list = []
    orders = run_custom_query("""
            SELECT o.*, c.name, c.surname, c.email, s.status_name,
                sum_order(o.id) as sum
            FROM orders o
            JOIN clients c ON c.id = o.client_id
            JOIN order_statuses s ON s.id = o.status_id

            WHERE (
                LOWER(c.name) LIKE '%{0}%' OR
                LOWER(c.surname) LIKE '%{0}%' OR
                LOWER(c.email) LIKE '%{0}%' OR
                LOWER(s.status_name) LIKE '%{0}%'
            ) OR EXISTS (
                SELECT  1
                FROM order_products op
                    INNER JOIN products p
                    ON op.product_id = p.id
                WHERE
                    LOWER(p.name) LIKE '%{0}%'
                    OR LOWER(p.description) LIKE '%{0}%'
            )
        """.format(query.lower()))
    for order in orders:
        order_products = select('order_products', {'order_id': order.id})
        orders_list.append(
            Order(id=order.id,
                  client=order.client_id,
                  status=order.status_name,
                  suma=order.sum))
    return sorted(orders_list, key=lambda x: x.id)
Beispiel #9
0
def get_full_client_dict(client):
    client_dict = dict(client.__dict__)  # Kinda hack  :-) Don't learn that :P
    phones = utils.run_custom_query(
        '''SELECT phone FROM client_phones WHERE client_id = {}'''.format(
            client.id))
    client_dict['phones'] = [phone.phone for phone in phones if phone.phone]
    return client_dict
Beispiel #10
0
def get_phones_for_client(client):
    phones = utils.run_custom_query(
        '''SELECT phone FROM client_phones WHERE client_id = {}'''.format(
            client.id
        )
    )
    return [phone.phone for phone in phones if phone.phone]
Beispiel #11
0
def get_full_client_dict(client):
    client_dict = dict(client.__dict__)  # Kinda hack  :-) Don't learn that :P
    phones = utils.run_custom_query(
        '''SELECT phone FROM client_phones WHERE client_id = {}'''.format(
            client.id
        )
    )
    client_dict['phones'] = [phone.phone for phone in phones if phone.phone]
    return client_dict
Beispiel #12
0
def get_product_main_image(id):
    images = utils.run_custom_query("""
        SELECT * FROM product_images
        WHERE product_id = {}
        ORDER BY default_image DESC
        """.format(id))

    if not images:
        return None
    return images[0]
Beispiel #13
0
def get_product_main_image(id):
    images = utils.run_custom_query("""
        SELECT * FROM product_images
        WHERE product_id = {}
        ORDER BY default_image DESC
        """.format(id))

    if not images:
        return None
    return images[0]
Beispiel #14
0
def list():
    query = request.args.get('query', '')

    users = run_custom_query("""
        SELECT * FROM users
        WHERE username LIKE '%{}%'
        ORDER BY id ASC;
        """.format(query))

    return render_template('users/list.html', users=users, query=query)
Beispiel #15
0
def edit_client(form, client_id):
    client_data = {
        'name': form.data['name'],
        'surname': form.data['surname'],
        'email': form.data['email'],
    }

    utils.run_custom_query(
        """DELETE FROM CLIENT_PHONES WHERE CLIENT_ID = {}""".format(client_id),
        fetch=False)
    utils.update('clients', {'id': client_id}, client_data)
    for phone in form.data['phones']:
        if phone['phone']:
            utils.insert('client_phones', {
                'client_id': client_id,
                'phone': phone['phone']
            })
    if form.data['billing_address']:
        billing = utils.select('client_addresses', {
            'client_id': client_id,
            'type': 'billing'
        })
        data = form.data['billing_address']
        utils.update('addresses', {
            'id': billing[0].id,
        }, {
            'country': data['country'],
            'city': data['city'],
            'street': data['street']
        })
    if form.data['delivery_address']:
        delivery = utils.select('client_addresses', {
            'client_id': client_id,
            'type': 'delivery'
        })
        data = form.data['delivery_address']
        utils.update('addresses', {
            'id': delivery[0].id,
        }, {
            'country': data['country'],
            'city': data['city'],
            'street': data['street']
        })
Beispiel #16
0
def list():
    query = request.args.get('query', '')

    users = run_custom_query("""
        SELECT * FROM users
        WHERE username LIKE '%{}%'
        ORDER BY id ASC;
        """.format(query)
    )

    return render_template('users/list.html', users=users, query=query)
Beispiel #17
0
def list():
    query = request.args.get('query', '')
    if not query:
        products = run_custom_query(
            """SELECT * FROM products
            WHERE deleted = False""")
    else:
        products = run_custom_query(
            """
                SELECT * FROM products
                WHERE (LOWER(name) LIKE '%{0}%'
                    OR LOWER(description) LIKE '%{0}%')
                AND deleted = False
            """.format(query.lower())
        )

    return render_template(
        'products/list.html',
        products=products,
        query=query
    )
Beispiel #18
0
def get_all_orders():
    orders_list = []
    orders = run_custom_query("""
            SELECT o.*, c.name, c.surname, c.email, s.status_name,
                sum_order(o.id) as sum
            FROM orders o
            JOIN clients c ON c.id = o.client_id
            JOIN order_statuses s ON s.id = o.status_id
        """)
    for order in orders:
        order_products = select('order_products', {'order_id': order.id})
        orders_list.append(
            Order(id=order.id,
                  client=order.client_id,
                  status=order.status_name,
                  suma=order.sum))
    return sorted(orders_list, key=lambda x: x.id)
Beispiel #19
0
def get_all_orders():
    orders_list = []
    orders = run_custom_query(
        """
            SELECT o.*, c.name, c.surname, c.email, s.status_name,
                sum_order(o.id) as sum
            FROM orders o
            JOIN clients c ON c.id = o.client_id
            JOIN order_statuses s ON s.id = o.status_id
        """
    )
    for order in orders:
        order_products = select('order_products', {'order_id': order.id})
        orders_list.append(
            Order(
                id=order.id,
                client=order.client_id,
                status=order.status_name,
                suma=order.sum
            )
        )
    return sorted(orders_list, key=lambda x: x.id)
Beispiel #20
0
def get_orders_with_query(query):
    orders_list = []
    orders = run_custom_query(
        """
            SELECT o.*, c.name, c.surname, c.email, s.status_name,
                sum_order(o.id) as sum
            FROM orders o
            JOIN clients c ON c.id = o.client_id
            JOIN order_statuses s ON s.id = o.status_id

            WHERE (
                LOWER(c.name) LIKE '%{0}%' OR
                LOWER(c.surname) LIKE '%{0}%' OR
                LOWER(c.email) LIKE '%{0}%' OR
                LOWER(s.status_name) LIKE '%{0}%'
            ) OR EXISTS (
                SELECT  1
                FROM order_products op
                    INNER JOIN products p
                    ON op.product_id = p.id
                WHERE
                    LOWER(p.name) LIKE '%{0}%'
                    OR LOWER(p.description) LIKE '%{0}%'
            )
        """.format(query.lower())
    )
    for order in orders:
        order_products = select('order_products', {'order_id': order.id})
        orders_list.append(
            Order(
                id=order.id,
                client=order.client_id,
                status=order.status_name,
                suma=order.sum
            )
        )
    return sorted(orders_list, key=lambda x: x.id)
Beispiel #21
0
def get_product_images(id):
    return utils.run_custom_query(
        """SELECT * FROM {}
        WHERE product_id = {}
        AND deleted={};""".format("product_images", id, False))
Beispiel #22
0
def delete_status(status_id):
    utils.run_custom_query(
        """DELETE FROM order_statuses WHERE ID = {}""".format(status_id),
        fetch=False
    )
Beispiel #23
0
def get_phones_for_client(client):
    phones = utils.run_custom_query(
        '''SELECT phone FROM client_phones WHERE client_id = {}'''.format(
            client.id))
    return [phone.phone for phone in phones if phone.phone]
Beispiel #24
0
def get_product_images(id):
    return utils.run_custom_query("""SELECT * FROM {}
        WHERE product_id = {}
        AND deleted={};""".format("product_images", id, False))
Beispiel #25
0
def delete_status(status_id):
    utils.run_custom_query("""DELETE FROM order_statuses WHERE ID = {}""".format(status_id), fetch=False)