def validate(self): initial_validation = super(ItemForm, self).validate() if not initial_validation: return False item = Item.query.filter(Item.item_code==self.item_code.data, Item.id != self.id.data).first() if item: self.item_code.errors.append(_("Item Code already existed")) return False item = Item.query.filter(Item.item_name==self.item_name.data, Item.id != self.id.data).first() if item: self.item_name.errors.append(_("Item Name already existed")) return False return True
def unit_create(): """Unit Create""" return_url = request.args.get('next', url_for(".units")) model = Unit('') 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')
def validate(self): initial_validation = super(WarehouseForm, self).validate() if not initial_validation: return False warehouse = Warehouse.query.filter(Warehouse.warehouse_name==self.warehouse_name.data, Warehouse.id != self.id.data).first() if warehouse: self.warehouse_name.errors.append(_("Warehouse Name already existed")) return False return True
def validate(self): initial_validation = super(UnitForm, self).validate() if not initial_validation: return False unit = Unit.query.filter(Unit.unit_name==self.unit_name.data, Unit.id != self.id.data).first() if unit: self.unit_name.errors.append(_("Unit Name already existed")) return False return True
def warehouse_create(): """Warehouse Create""" return_url = request.args.get('next', url_for(".warehouses")) model = Warehouse('') form = WarehouseForm(next=return_url, disabled=False) 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')
def validate(self): initial_validation = super(CompanyForm, self).validate() if not initial_validation: return False company = Company.query.filter(Company.company_name == self.company_name.data, Company.id != self.id.data).first() if company: self.company_name.errors.append(_("Company Name already existed")) return False return True
def validate(self): initial_validation = super(ItemGroupForm, self).validate() if not initial_validation: return False item_group = ItemGroup.query.filter(ItemGroup.item_group_name==self.item_group_name.data, ItemGroup.id != self.id.data).first() if item_group: self.item_group_name.errors.append(_("Item Group Name already existed")) return False return True
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 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 item_group_create(): """Item Group Create""" return_url = request.args.get('next', url_for(".item_groups")) model = ItemGroup('') form = ItemGroupForm(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.add(model) db.session.commit() if '_add_another' in request.form: flash(_('Created successfully.')) return redirect(url_for('.item_group_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')
def process_formdata(self, valuelist): if valuelist: date_str = u" ".join(valuelist) if date_str.strip(): for format in self.formats: try: timetuple = time.strptime(date_str, format) self.data = datetime.time(timetuple.tm_hour, timetuple.tm_min, timetuple.tm_sec) return except ValueError: pass raise ValueError(_("Invalid time format")) else: self.data = None
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 logout(): logout_user() flash(_('You are logged out.'), 'info') return redirect(url_for('public.home'))