Exemplo n.º 1
0
def purchase_form_handler(form):
    purchase_data = Purchase(rstnumber=form.rst_number.data,
                             weight=form.weight.data,
                             moisture=form.moisture.data,
                             rate=form.rate.data,
                             variety_id=form.variety.data,
                             agent_id=form.agent.data,
                             timestamp=form.date.data,
                             amount=form.amount.data)
    return write_to_db(purchase_data)
Exemplo n.º 2
0
def user_form_handler(form, action):
    if action == "add":
        user = User(username=form.username.data,
                    email=form.email.data,
                    role_id=form.roles.data)
        user.set_password(form.password.data)
        user.active = form.active.data
        return write_to_db(user, db.session.add)
    elif action == "delete":
        user = User.query.filter_by(form.id.data).first()
        if user is None:
            abort(404)
        return write_to_db(user, db.session.delete)
    elif action == "update":
        user = User(email=form.email.data,
                    role_id=form.roles.data,
                    active=form.active.data)
        return write_to_db(user, db.session.add)
    return 500, Exception(f"Invalid action: {action}")
Exemplo n.º 3
0
def sale_form_handler(form):
    quintol = form.quintol.data
    rate = form.rate.data
    gst = 5
    amt = (quintol * rate) + (quintol * rate * gst / 100)
    sale_data = Sale(party_name=form.party_name.data,
                     party_address=form.party_address.data,
                     gst_number=form.gst_number.data,
                     vehicle_number=form.vehicle_number.data,
                     no_of_bags=form.no_of_bags.data,
                     variety_id=form.variety.data,
                     agent_id=form.agent.data,
                     quintol=form.quintol.data,
                     rate=form.rate.data,
                     timestamp=form.date.data,
                     amount=amt)
    return write_to_db(sale_data)
Exemplo n.º 4
0
def agent_form_handler(form, action):
    agent_type_2_model = {
        "1": PurchaseAgent,
        "2": SaleAgent
    }
    # logger.info("data is coming")
    cur_model = agent_type_2_model.get(form.agent_type.data)
    if cur_model is None:
        abort(500)

    agent = cur_model(
        name=form.name.data,
        email=form.email.data,
        mobile=form.mobile.data,
        address=form.address.data
    )
    return write_to_db(agent, db.session.add)
Exemplo n.º 5
0
def change_password():
    generic_data = {"title": "Change Password", "heading": "Change Password"}
    form = ChangePasswordForm()
    if form.validate_on_submit():
        user = current_user
        user.set_password(form.new_password.data)
        status, e = write_to_db(user)
        db.session.commit()
        if status != 200:
            # logger.error(f"status: {status}, {e}")
            abort(status)
        return redirect(
            url_for('auth.logout',
                    message=("Your password changed succesfully."
                             " Please Login")))
    return render_template(f"auth/change_password.html",
                           form=form,
                           data=generic_data)
Exemplo n.º 6
0
def reset_user_password():
    generic_data = {
        "title": "Change User Password",
        "heading": "Change User Password"
    }
    form = ChangeUserPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        user.set_password(form.new_password.data)
        status, e = write_to_db(user)
        db.session.commit()
        if status != 200:
            # logger.error(f"status: {status}, {e}")
            abort(status)
        flash(f"Password for {form.username.data} changed succesfully.")
        return redirect(url_for('auth.reset_user_password'))
    return render_template(f"auth/reset_user_password.html",
                           form=form,
                           data=generic_data)
Exemplo n.º 7
0
def variety_form_handler(form, action):
    variety = Variety(name=form.name.data)
    return write_to_db(variety, db.session.add)