Example #1
0
def settings_main():
    context = base_context()

    settings = Settings.query.all()

    context["settings"] = settings
    return render_template("settings/index.html", **context)
Example #2
0
def list_prods(category_name):
    context = base_context()
    products = Product.query.filter(
        Product.category_name == category_name).all()
    context["products"] = products
    context["category"] = category_name

    return render_template("prods/list.html", **context)
Example #3
0
def settings_edit(settings_name):
    context = base_context()

    s = Settings.query.get(settings_name)

    context["settings_name"] = settings_name
    context["current_value"] = s.value

    return render_template("settings/edit.html", **context)
Example #4
0
def prods_edit(category_name, barcode):
    context = base_context()

    product = Product.query.filter(
        Product.barcode == barcode
        and Product.category == category_name).first()

    context["product"] = product
    context["category"] = category_name
    return render_template("prods/edit.html", **context)
Example #5
0
def lookup_prods(category_name):
    context = base_context()

    context["category"] = category_name
    context["fields"] = [
        key.replace("_", " ") for key in Product.__table__.columns.keys()
        if key not in ["category_name"]
    ]

    return render_template("prods/lookup.html", **context)
Example #6
0
def user_list():
    """
           **Get The List of User**

            Lists all users in the database.

    """
    context = base_context()
    context["users"] = User.query.all()
    return render_template("admin/index.html", **context)
Example #7
0
def settings_update():
    context = base_context()

    settings_name = request.form["settings_name"]
    settings_value = request.form["settings_value"]
    s = Settings.query.get(settings_name)
    s.value = settings_value
    db.session.commit()
    settings = Settings.query.all()

    context["settings"] = settings
    return render_template("settings/index.html", **context)
Example #8
0
def admin_edit(id):
    """
                   **Update information for a User**

        :param id: id of the user
        :type id: int

    """
    context = base_context()
    user = User.query.get(id)
    context['user'] = user
    context['user_roles'] = [r.name for r in user.roles]
    context['roles'] = Role.query.all()
    return render_template("admin/edit.html", **context)
Example #9
0
def login():
    context = base_context()
    login_form = LoginForm()
    context['form'] = login_form
    if login_form.validate_on_submit():
        username = login_form.username.data
        password = login_form.password.data
        user = User.query.filter_by(username=username).first()
        if user is None or not user.check_hash(password):
            flash("please check your user id and password")
            return redirect(url_for("login.login"))
        login_user(user)
        return redirect(url_for("mock_app.index"))
    return render_template("/login.html", **context)
Example #10
0
def category_add():
    context = base_context()

    has_category = False
    if request.method == "POST":
        name = request.form["name"]
        has_category = Category.category_exists(name)
        if has_category is False:
            m = Category(name=name)
            m.insert()
        return render_template("category/add.html", **context)

    context["has_category"] = str(has_category)
    return render_template("category/add.html", **context)
Example #11
0
def prods_add(category_name):
    context = base_context()

    has_product = False
    if request.method == "POST":
        barcode = request.form["barcode"]
        name = request.form["name"]
        description = request.form["description"]
        date = request.form["date"]
        price = request.form["price"]
        selling_price = request.form["selling_price"]
        in_stock = request.form["in_stock"]
        if request.form["discontinued"] == "True":
            discontinued = True
        else:
            discontinued = False

        # category = Category.query.filter(
        #     Category.name == category_name).first()
        # print(category, category_name, category.name)
        has_product = db.session.query(
            exists().where(Product.barcode == barcode)).scalar()

        if has_product is False:
            p = Product(barcode=barcode,
                        name=name,
                        in_stock=in_stock,
                        category_name=category_name,
                        discontinued=discontinued)
            if description:
                p.description = description.strip()
            if date:
                p.date = date.strip()
            if price:
                p.price = price.strip()
            if selling_price:
                p.selling_price = selling_price.strip()

            db.session.add(p)
            db.session.commit()
        context["category"] = category_name
        context["has_product"] = str(has_product)
        return render_template("prods/add.html", **context)

    context["category"] = category_name
    context["has_product"] = str(has_product)
    context['barcodestr'] = uuid.uuid1()
    return render_template("prods/add.html", **context)
Example #12
0
def index():
    context = base_context()

    for module in os.listdir(
            os.path.join(current_app.config['BASE_DIR'], "modules")):
        if module.startswith("__"):
            continue
        if module not in ["mock_app"]:
            with open(
                    os.path.join(current_app.config['BASE_DIR'], 'modules',
                                 module, 'info.json')) as f:
                module_info = json.load(f)
                all_info[module] = module_info

    context["all_info"] = all_info
    flash(notify_success('Notif test'))
    return render_template("mock_app/index.html", **context)
Example #13
0
def category_update():
    context = base_context()

    if (
        request.method == "POST"
    ):  # this block is only entered when the form is submitted
        name = request.form["category_name"]
        old_name = request.form["old_category_name"]
        try:
            m = Category.query.filter_by(name=old_name).first()
            m.name = name
            m.update()
        except sqlalchemy.exc.IntegrityError:
            context[
                "message"
            ] = "you cannot modify to an already existing category"
            context["redirect_url"] = "/category/"
            render_template("category/message.html", **context)
        return redirect("/category/")
Example #14
0
def user_add():
    """
               **Adds a User**

            adds a user to database.

    """
    context = base_context()
    if request.method == "POST":
        username = request.form["name"]
        password = request.form["password"]
        admin_user = request.form.get("admin_user")
        if admin_user == "True":
            admin_user = True
        else:
            admin_user = False

        has_user = db.session.query(
            exists().where(User.username == username)).scalar()

        if has_user is False:
            new_user = User()
            new_user.username = username
            new_user.admin_user = admin_user
            new_user.set_hash(password)

            for key in request.form:
                if key.startswith('role_'):
                    roleid = key.split('_')[1]
                    role = Role.query.get(roleid)
                    new_user.roles.append(role)
            new_user.insert()
            return redirect(url_for('admin.user_add'))

    context['roles'] = Role.query.all()
    return render_template("admin/add.html", **context)
Example #15
0
def roles():
    context = base_context()
    context['roles'] = Role.query.all()
    return render_template('admin/roles.html', **context)
Example #16
0
def category():
    context = base_context()
    context["categorys"] = Category.query.all()
    context["active_page"] = get_setting("SECTION_NAME")
    return render_template("category/index.html", **context)
Example #17
0
def category_edit(category_name):
    context = base_context()
    context["category_name"] = category_name
    return render_template("category/edit.html", **context)