Ejemplo n.º 1
0
def add_trader_page():
    if (login.is_logged_in() == 0):  #Only logged in users can view this page!
        return redirect("/login/not_logged_in")

    if (request.method == 'POST'
        ):  #Adding form was sent - then add the new trader
        form_t_name = validate.sql_escape(request.form["t_name"])
        form_contact_name = validate.sql_escape(request.form["contact_name"])
        form_phone = validate.sql_escape(request.form["phone"])
        form_address = validate.sql_escape(request.form["address"])
        form_notes = validate.sql_escape(request.form["notes"])
        form_is_active = validate.is_boolean(request.form["is_active"])
        form_is_supplier = validate.is_boolean(request.form["is_supplier"])
        form_is_costumer = validate.is_boolean(request.form["is_costumer"])

        new_trader_id = traders.add_trader(form_t_name, form_contact_name,
                                           form_phone, form_address,
                                           form_notes, form_is_active,
                                           form_is_supplier, form_is_costumer)
        return redirect('/traders/edit/' + str(new_trader_id))

    #If the request is get - then print the add new trader form
    return render_template('index.html',
                           page_title="Add new trader: ",
                           content=traders.add_trader_form())
Ejemplo n.º 2
0
def update_trader_page():
    if (login.is_logged_in() == 0):  #Only logged in users can view this page!
        return redirect("/login/not_logged_in")

    form_t_id = validate.is_trader(request.form["t_id"])
    form_t_name = validate.sql_escape(request.form["t_name"])
    form_contact_name = validate.sql_escape(request.form["contact_name"])
    form_phone = validate.sql_escape(request.form["phone"])
    form_address = validate.sql_escape(request.form["address"])
    form_notes = validate.sql_escape(request.form["notes"])
    form_is_active = validate.is_boolean(request.form["is_active"])
    form_is_supplier = validate.is_boolean(request.form["is_supplier"])
    form_is_costumer = validate.is_boolean(request.form["is_costumer"])

    is_success = traders.trader_update(form_t_id, form_t_name,
                                       form_contact_name, form_phone,
                                       form_address, form_notes,
                                       form_is_active, form_is_supplier,
                                       form_is_costumer)
    if (is_success):
        return render_template('index.html',
                               page_title="Edit trader: ",
                               message="trader details updated! ",
                               content=traders.traders_list())
    else:
        return render_template('index.html',
                               page_title="Edit trader: ",
                               warning="Error - update failed! ",
                               content=traders.trader_edit(form_t_id))
Ejemplo n.º 3
0
def add_user_page():
    if (login.is_logged_in_admin() == 0
        ):  #Only logged in ADMIN users can view this page!
        return redirect("/login/not_admin")

    form_u_name = validate.sql_escape(request.form["u_name"])
    form_password = validate.sql_escape(request.form["password"])
    form_d_name = validate.sql_escape(request.form["d_name"])
    return render_template('index.html',
                           page_title="Users list: ",
                           message=users.user_add(form_u_name, form_password,
                                                  form_d_name),
                           content=users.users_list())
Ejemplo n.º 4
0
def update_user_page():
    if (login.is_logged_in_admin() == 0
        ):  #Only logged in ADMIN users can view this page!
        return redirect("/login/not_admin")

    form_u_id = validate.is_user(request.form["u_id"])
    form_u_name = validate.sql_escape(request.form["u_name"])
    form_d_name = validate.sql_escape(request.form["d_name"])
    form_is_active = validate.is_boolean(request.form["is_active"])
    return render_template('index.html',
                           page_title="Edit user: ",
                           message=users.user_update(form_u_id, form_u_name,
                                                     form_is_active,
                                                     form_d_name),
                           content=users.user_edit(form_u_id))
Ejemplo n.º 5
0
def update_transaction_page():
    #this page allows editing transaction, adding actions to it - and eventually to apply it!

    if (login.is_logged_in() == 0):  #Only logged in users can view this page!
        return redirect("/login/not_logged_in")

    form_transaction_id = validate.is_transaction(
        request.form["transaction_id"])
    form_title = validate.sql_escape(request.form["title"])
    form_reason = validate.sql_escape(request.form["reason"])
    form_transaction_type = validate.is_number(
        request.form["transaction_type"])
    form_trader_id = validate.is_trader(request.form["trader_id"])
    form_notes = validate.sql_escape(request.form["notes"])

    is_success = transactions.transaction_update(form_transaction_id,
                                                 form_title, form_reason,
                                                 form_transaction_type,
                                                 form_trader_id, form_notes)
    return redirect('/transactions/edit/' + str(form_transaction_id))
Ejemplo n.º 6
0
def add_action_page():

    if (login.is_logged_in() == 0):  #Only logged in users can view this page!
        return redirect("/login/not_logged_in")

    form_transaction_id = validate.is_transaction(
        request.form["transaction_id"])
    form_item_id = validate.is_item(request.form["item_id"])
    form_amount = validate.is_number(request.form["amount"])
    form_notes = validate.sql_escape(request.form["notes"])
    transactions.add_action(form_transaction_id, form_item_id, form_amount,
                            form_notes)
    return redirect('/transactions/edit/' + str(form_transaction_id))
Ejemplo n.º 7
0
def update_item_page():
    form_item_id = validate.is_item(request.form["item_id"])
    form_item_name = validate.sql_escape(request.form["item_name"])
    form_amount = validate.is_number(request.form["amount"])
    form_m_unit = validate.sql_escape(request.form["m_unit"])
    form_price = validate.is_number(request.form["price"])
    form_supplier_id = validate.is_trader(request.form["supplier_id"])
    form_warehouse_id = validate.is_wh(request.form["warehouse_id"])
    form_notes = validate.sql_escape(request.form["notes"])

    is_success = items.item_update(form_item_id, form_item_name, form_amount,
                                   form_m_unit, form_price, form_supplier_id,
                                   form_warehouse_id, form_notes)
    if (is_success):
        return render_template('index.html',
                               page_title="Edit item: ",
                               message="Item updated successfully! ",
                               content=items.item_edit(form_item_id))
    return render_template('index.html',
                           page_title="Edit item: ",
                           warning="Item update failed",
                           content=items.item_edit(form_item_id))
Ejemplo n.º 8
0
def items_add__page():
    if (request.method == 'GET'
        ):  #In case request method is GET, then lead to the creation form.
        return render_template('index.html',
                               page_title="Add item: ",
                               content=items.item_add_form())
    elif (
            request.method == 'POST'
    ):  #If request method is POST , then it means the form was sent - then add the item.
        form_item_name = validate.sql_escape(request.form["item_name"])
        form_amount = validate.is_number(request.form["amount"])
        form_m_unit = validate.sql_escape(request.form["m_unit"])
        form_price = validate.is_number(request.form["price"])
        form_supplier_id = validate.is_trader(request.form["supplier_id"])
        form_warehouse_id = validate.is_wh(request.form["warehouse_id"])
        form_notes = validate.sql_escape(request.form["notes"])

        items.item_add(form_item_name, form_amount, form_m_unit, form_price,
                       form_supplier_id, form_warehouse_id, form_notes)
        return render_template('index.html',
                               page_title="Edit item: ",
                               message="New item was added successfully! ",
                               content=items.items_list())
Ejemplo n.º 9
0
def add_warehouse_page():
    if (login.is_logged_in() == 0):  #Only logged in users can view this page!
        return redirect("/login/not_logged_in")

    form_wh_name = validate.sql_escape(request.form["wh_name"])
    form_is_active = validate.is_boolean(request.form["is_active"])
    if (wh.wh_add(form_wh_name, form_is_active)):
        return render_template('index.html',
                               page_title="Warehouses list: ",
                               message="Warehouse sucessfully added! ",
                               content=wh.wh_list())
    return render_template('index.html',
                           page_title="Warehouses list: ",
                           warning="Error - Warehouse wasn't added! ",
                           content=wh.wh_list())
Ejemplo n.º 10
0
def update_warehouse_page():
    if (login.is_logged_in() == 0):  #Only logged in users can view this page!
        return redirect("/login/not_logged_in")

    form_wh_id = validate.is_wh(request.form["wh_id"])
    form_wh_name = validate.sql_escape(request.form["wh_name"])
    form_is_active = validate.is_boolean(request.form["is_active"])
    if (wh.wh_update(form_wh_id, form_wh_name, form_is_active)):
        return render_template('index.html',
                               page_title="Edit warehouse: ",
                               message="Warehouse updated! ",
                               content=wh.wh_edit(form_wh_id))
    return render_template('index.html',
                           page_title="Edit warehouse: ",
                           warning="Update failed! ",
                           content=wh.wh_edit(form_wh_id))
Ejemplo n.º 11
0
def change_user_password_page():
    if (login.is_logged_in_admin() == 0
        ):  #Only logged in ADMIN users can view this page!
        return redirect("/login/not_admin")

    form_u_id = validate.is_user(request.form["u_id"])
    form_new_password = validate.sql_escape(request.form["new_password"])
    if (users.user_change_password(form_u_id, form_new_password)):
        return render_template('index.html',
                               page_title="Edit user: "******" Password changed succesfully! ",
                               content=users.user_edit(form_u_id))
    return render_template(
        'index.html',
        page_title="Edit user: "******" Password wasn't changed - please try again! ",
        content=users.user_edit(form_u_id))