def home(): form = LoginForm(request.form) # Handle logging in if request.method == 'POST': if form.validate_on_submit(): login_user(form.user) flash(_("You are logged in."), 'success') redirect_url = request.args.get("next") or url_for("user.members") return redirect(redirect_url) else: flash_errors(form) return render("home.html", form=form)
def register(): form = RegisterForm(request.form, csrf_enabled=False) if form.validate_on_submit(): new_user = User.create(username=form.username.data, email=form.email.data, password=form.password.data, active=True) flash(_("Thank you for registering. You can now log in."), 'success') return redirect(url_for('public.home')) else: flash_errors(form) return render('register.html', form=form)
def unit_edit(id): """Unit Edit""" return_url = request.args.get('next', url_for(".units")) model = Unit.query.get(id) if model is None: return redirect(return_url) form = UnitForm(obj=model, next=return_url) if form.validate_on_submit(): try: form.populate_obj(model) db.session.commit() return redirect(return_url) except Exception: db.session.rollback() flash(_('Failed to update model.')) return render('unit_edit.html', form=form, return_url=return_url)
def warehouse_edit(id): """Warehouse Edit""" return_url = request.args.get('next', url_for(".warehouses")) model = Warehouse.query.get(id) if model is None: return redirect(return_url) form = WarehouseForm(obj=model, next=return_url) form.company_id.choices = [(r.id, r.company_name) for r in Company.query.filter_by().order_by('company_name')] if form.validate_on_submit(): try: form.populate_obj(model) db.session.commit() return redirect(return_url) except Exception: db.session.rollback() flash(_('Failed to update model.')) return render('warehouse_edit.html', form=form, return_url=return_url)
def item_group_edit(id): """Item Group Edit""" return_url = request.args.get('next', url_for(".item_groups")) model = ItemGroup.query.get(id) if model is None: return redirect(return_url) form = ItemGroupForm(obj=model, next=return_url) form.parent_id.choices = [(r.id, r.item_group_name) for r in ItemGroup.query.filter_by().order_by('item_group_name')] if form.validate_on_submit(): try: form.populate_obj(model) db.session.commit() return redirect(return_url) except Exception: db.session.rollback() flash(_('Failed to update model.')) return render('item_group_edit.html', form=form, return_url=return_url)
def members(): return render("users/members.html")
def about(): form = LoginForm(request.form) return render("about.html", form=form)
def units(): """Unit Query""" return_url = request.args.get('next', url_for(".units")) models = Unit.query.all() return render('units.html', models=models, return_url=return_url)
def companies(): """Companies Query""" return_url = request.args.get('next', url_for(".companies")) models = Company.query.all() return render('companies.html', models=models, return_url=return_url)
def item_groups(): """Item Group Query""" return_url = request.args.get('next', url_for(".item_groups")) models = ItemGroup.query.all() return render('item_groups.html', models=models, return_url=return_url)
form = UnitForm(next=return_url) if form.validate_on_submit(): try: form.populate_obj(model) db.session.add(model) db.session.commit() if '_add_another' in request.form: flash(_('Created successfully.')) return redirect(url_for('.unit_create', url=return_url)) else: return redirect(return_url) except Exception, ex: db.session.rollback() flash(_('Failed to update model.') + '%(error)s' % {'error':str(ex)}, 'danger') return render('unit_create.html', form=form, return_url=return_url) @blueprint.route('/unit/edit/id=<int:id>', methods=['GET', 'POST']) @login_required def unit_edit(id): """Unit Edit""" return_url = request.args.get('next', url_for(".units")) model = Unit.query.get(id) if model is None: return redirect(return_url) form = UnitForm(obj=model, next=return_url) if form.validate_on_submit(): try: form.populate_obj(model)
def warehouses(): """Warehouse Query""" return_url = request.args.get('next', url_for(".warehouses")) models = Warehouse.query.all() return render('warehouses.html', models=models, return_url=return_url)
form.company_id.choices = [(r.id, r.company_name) for r in Company.query.filter_by().order_by('company_name')] if form.validate_on_submit(): try: form.populate_obj(model) db.session.add(model) db.session.commit() if '_add_another' in request.form: flash(_('Created successfully.')) return redirect(url_for('.warehouse_create', url=return_url)) else: return redirect(return_url) except Exception, ex: db.session.rollback() flash(_('Failed to update model.') + '%(error)s' % {'error':str(ex)}, 'danger') return render('warehouse_create.html', form=form, return_url=return_url) @blueprint.route('/warehouse/edit/id=<int:id>', methods=['GET', 'POST']) @login_required def warehouse_edit(id): """Warehouse Edit""" return_url = request.args.get('next', url_for(".warehouses")) model = Warehouse.query.get(id) if model is None: return redirect(return_url) form = WarehouseForm(obj=model, next=return_url) form.company_id.choices = [(r.id, r.company_name) for r in Company.query.filter_by().order_by('company_name')] if form.validate_on_submit(): try: