def settings_main(): context = base_context() settings = Settings.query.all() context["settings"] = settings return render_template("settings/index.html", **context)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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/")
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)
def roles(): context = base_context() context['roles'] = Role.query.all() return render_template('admin/roles.html', **context)
def category(): context = base_context() context["categorys"] = Category.query.all() context["active_page"] = get_setting("SECTION_NAME") return render_template("category/index.html", **context)
def category_edit(category_name): context = base_context() context["category_name"] = category_name return render_template("category/edit.html", **context)