def categories_create(): form = CategoryForm(request.form) if not form.validate(): return render_template("categories/new.html", form = form, categories = Category.query.order_by(Category.name)) t = Category(form.name.data) t.account_id = current_user.id db.session().add(t) db.session().commit() return redirect(url_for("categories_form"))
def categories_create(): form = CategoryForm(request.form) if not form.validate(): return render_template("categories/new.html", form=form) c = Category(form.name.data, form.description.data) c.account_id = current_user.id db.session().add(c) db.session().commit() return redirect(url_for("categories_index"))
def categories_create(): form = CategoryForm(request.form) if not form.validate(): return render_template("categories/new.html", form=form) if Category.query.filter(Category.account_id == current_user.id).filter( Category.name == form.name.data).first(): form.name.errors.append("Category named " + form.name.data + " already exists.") return render_template("categories/new.html", form=form) c = Category(form.name.data, form.description.data) c.account_id = current_user.id db.session().add(c) db.session().commit() return redirect(url_for("categories_index"))
def items_form(): category_list = Category.query.order_by('name').filter_by( account_id=current_user.id) c_list = [] for c in category_list: c_list.append(c) if len(c_list) == 0: c = Category("Ei kategoriaa") c.account_id = current_user.id db.session().add(c) db.session().commit() form = ItemForm() form.item_category.choices = [ (c.id, c.name) for c in Category.query.order_by('name').filter_by( account_id=current_user.id) ] return render_template('items/new.html', form=form)
def categories_create(): form = CategoryForm(request.form) c_test = Category.query.filter_by(name=form.name.data, account_id=current_user.id).first() if c_test: return render_template( "categories/new.html", form=form, error= "Kategoria on jo olemassa, valitse jokin toinen nimi kategorialle!" ) else: if not form.validate(): return render_template("categories/new.html", form=form) c = Category(form.name.data) c.account_id = current_user.id db.session().add(c) db.session().commit() return redirect(url_for("categories_index"))
app.config["SECRET_KEY"] = urandom(32) from flask_login import LoginManager login_manager = LoginManager() login_manager.init_app(app) login_manager.login_view = "auth_login" login_manager.login_message = "Please login to use this functionality." @login_manager.user_loader def load_user(user_id): return User.query.get(user_id) try: db.create_all() # Adding the administrator account hashed_password = bcrypt.generate_password_hash("unlimitedpower").decode( 'utf-8') u = User("Administrator", "admin", hashed_password) db.session().add(u) db.session().commit() # Adding the first category c = Category("No category") c.account_id = 1 db.session.add(c) db.session.commit() except: pass