def categories(*args, **kwargs): if request.method == "GET": categories = Category.query.filter_by(user_id=current_user.id) error = kwargs.get("error", "") return render_template("/categories/categories.html", categories=categories, form=CategoryForm(), error=error) else: form = CategoryForm(request.form) # If the user already has a category by that name, let's not create a duplicate alreadyExists = db.session.query( db.exists().where(Category.name == form.name.data).where( Category.user_id == current_user.id)).scalar() if alreadyExists: return redirect(url_for('categories', error=1)) c = Category() c.name = form.name.data c.user_id = current_user.id db.session().add(c) db.session().commit() return redirect(url_for('categories', error=""))
def categories_create(): form = CategoryForm(request.form) if not form.validate(): return render_template("categories/new.html", form=form) c = Category(form.name.data) 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, 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 category_create(): form = CategoryForm() if form.validate_on_submit(): c = Category(form.name.data) db.session().add(c) db.session().commit() return redirect(url_for("category_create")) categories = Category.query.all() return render_template("categories/new.html", form = form, categories = categories)
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(): if current_user.role != "ADMIN": return render_template("index.html", msg=msg_admin_feature) form = CategoryForm(request.form) if not form.validate(): return render_template("categories/new.html", form=form) c = Category(form.name.data) db.session().add(c) db.session().commit() return redirect(url_for("categories_index"))
def categories_modify(category_id): category = Category.query.get(category_id) form = CategoryForm() form.name.data = category.name return render_template("categories/modify.html", form=form, category=category)
def customsearch_search(): dateform = DateForm(request.form) categoryform = CategoryForm(request.form, False) newest = (dateform.radios.data == 'newest') return customsearch_search_with_parameters(categoryform.categories.data, newest)
def categories_index(): return render_template( "categories/list.html", categories=list( Category.query.filter(Category.account_id == current_user.id)), form=CategoryForm(), delete_error="")
def items_create(): form = ItemForm(request.form) form2 = CategoryForm(request.form) if not form.validate(): return render_template("items/new.html", form=form) name = form.name.data it = Item.query.filter_by(name=name).first() if it: return render_template("items/new.html", form=form, error="Item is already listed!") i = Item(name) cid = form.category_id.data c = Category.query.get(cid) if not c: return render_template("categories_index") c.size = c.size + 1 i.category_id = cid i.bought = form.bought.data i.account_id = current_user.id db.session().add(i) db.session().commit() return redirect(url_for("items_index"))
def edit_category(category_id): category = Category.query.get(category_id) if category: if category.account_id != current_user.id: return redirect('/categories') form = CategoryForm(formdata=request.form, obj=category) if request.method == 'POST' and form.validate(): category.name = form.name.data db.session().commit() flash('Category updated successfully') return redirect('/categories') return render_template('categories/edit.html', form=form) else: return 'Error loading #{category_id}'.format(id=id)
def categories_commit_changes(category_id): form = CategoryForm(request.form) category = Category.query.get(category_id) category.name = form.name.data 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 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"))
def categories_edit(category_id): if request.method == "GET": categories_index() if Category.query.filter_by( id=category_id).first().account_id == current_user.id: form = CategoryForm(request.form) if not form.validate(): form.description.data, form.description.data = "", "" return render_template( "categories/list.html", categories=list( Category.query.filter( Category.account_id == current_user.id)), 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/list.html", categories=list( Category.query.filter( Category.account_id == current_user.id)), form=form) c = Category.query.get(category_id) c.name = form.name.data c.description = form.description.data db.session().commit() return redirect(url_for("categories_index"))
def categories_update(category_id): form = CategoryForm(request.form) cat = Category.query.get(category_id) if form.name.data: cat.name = form.name.data try: db.session.commit() except IntegrityError: db.session.rollback() return render_template("categories/view.html", category=cat, form=form, category_name_taken=True) return redirect(url_for("categories_index"))
def categories_delete(category_id): if request.method == "GET": categories_index() if Category.query.filter_by( id=category_id).first().account_id == current_user.id: if not Event.query.filter_by(category_id=category_id).first() \ and not Category.query.join(Clip.categories).filter_by(id=category_id).first(): c = Category.query.get(category_id) db.session.delete(c) db.session().commit() else: return render_template( "categories/list.html", categories=list( Category.query.filter( Category.account_id == current_user.id)), form=CategoryForm(), delete_error= "This category can't be deleted as it has Events or Clips associated with it." ) return redirect(url_for("categories_index"))
def categories_form(): return render_template("categories/new.html", form=CategoryForm())
def categories_view(category_id): cat = Category.query.get(category_id) form = CategoryForm() return render_template("categories/view.html", category=cat, form=form)
def customsearch_open(): dateform = DateForm() return render_template("customsearch/customsearch.html", dateform=dateform, categoryform=CategoryForm(None, False))
def categories_form(): return render_template("categories/new.html", form = CategoryForm(), categories = Category.query.order_by(Category.name))
def categories_form(): if current_user.role != "ADMIN": return render_template("index.html", msg=msg_admin_feature) return render_template("categories/new.html", form=CategoryForm())