def create_new(self): rv = Form.validate(self) ri = self.img.validate(self) if rv and ri: category = Category() if not check_icon(self.img.data): self.img.errors.append(_(u'Image not found')) return False category.init(self.name.data, self.num.data, self.visible.data, self.img.data) i = Upload.query.filter_by(url=self.img.data).first() db.session.delete(i) db.session.add(category) db.session.commit() self.category = category return True return False
def upgrade(self, category): r1 = self.name.validate(self) r2 = self.num.validate(self) r3 = self.img.validate(self) if r1 and r2 and r3: category.name = self.name.data category.num = self.num.data category.visible = False print str(self.visible.data) if str(self.visible.data) == 'True': category.visible = True if not self.img.data == '' and not self.img.data is None: if check_icon(self.img.data): if not category.img == self.img.data: remove_icon(category.img) i = Upload.query.filter_by(url=self.img.data).first() db.session.delete(i) category.img = self.img.data db.session.add(category) db.session.commit() self.category = category return True return False