def brands(): brands = Brand.query().order(Brand.name) form = BrandForm() if form.validate_on_submit(): new_series = Brand() form.populate_obj(new_series) new_series.put() return redirect(url_for('admin.product.brands')) return render_template('product/admin/brand/all.html', brands=brands, form=form)
def brands(): brands = Brand.query().order(Brand.name) form = BrandForm() if form.validate_on_submit(): new_series = Brand() form.populate_obj(new_series) new_series.put() return redirect(url_for('admin.product.brands')) return render_template( 'product/admin/brand/all.html', brands=brands, form=form )
def validate(self, is_edit=False): rv = wtf.Form.validate(self) if not rv: return False name = self.name.data.lower() check_cat = Brand.query(Series.name_lowercase == name).count() if check_cat and not is_edit: self.name.errors.append(u'Название бренда должно быть уникальным') return False return True
def brands_stat(): brands_obj = Brand.query(Brand.is_public == True).order(Brand.name) brands = [] for b in brands_obj: if b.public_product_count: brands.append(b) brands_count = len(brands) if brands_count: brands_count = pytils.numeral.get_plural( brands_count, (u'бренда и производителя', u'брендов и производителей', u'брендов и производителей')) return brands, brands_count
def brand_edit(key_id): brand = Brand.retrieve_by_id(key_id) if not brand: return redirect(url_for('admin.product.brands')) form = SeriesForm(obj=brand) if request.method == 'POST' and 'delete_brand' in request.form: brand.key.delete() return redirect(url_for('admin.product.brands')) if form.is_submitted() and form.validate(is_edit=True): form.populate_obj(brand) brand.put() return redirect(url_for('admin.product.brands')) return render_template('product/admin/brand/edit.html', brand=brand, form=form)
def brand_edit(key_id): brand = Brand.retrieve_by_id(key_id) if not brand: return redirect(url_for('admin.product.brands')) form = SeriesForm(obj=brand) if request.method == 'POST' and 'delete_brand' in request.form: brand.key.delete() return redirect(url_for('admin.product.brands')) if form.is_submitted() and form.validate(is_edit=True): form.populate_obj(brand) brand.put() return redirect(url_for('admin.product.brands')) return render_template( 'product/admin/brand/edit.html', brand=brand, form=form )
def brands_stat(): brands_obj = Brand.query(Brand.is_public == True).order( Brand.name ) brands = [] for b in brands_obj: if b.public_product_count: brands.append(b) brands_count = len(brands) if brands_count: brands_count = pytils.numeral.get_plural( brands_count, (u'бренда и производителя', u'брендов и производителей', u'брендов и производителей') ) return brands, brands_count