示例#1
0
 def upgrade(self, product):
     r1 = self.name.validate(self)
     r2 = self.memo.validate(self)
     r3 = self.img.validate(self)
     r4 = self.price.validate(self)
     if r1 and r2 and r3 and r4:
         category = Category.query.get(self.category.data)
         if category is None:
             self.category.errors.append(_(u'Category not found'))
             return False
         product.category = category
         product.name = self.name.data
         product.memo = self.memo.data
         if not self.img.data == '' and not self.img.data is None:
             if check_img(self.img.data):
                 if not product.img == self.img.data:
                     remove_img(product.img)
                     i = Upload.query.filter_by(url=self.img.data).first()
                     db.session.delete(i)
                 product.img = self.img.data
         product.price = self.price.data
         db.session.add(product)
         db.session.commit()
         self.product = product
         return True
     return False
示例#2
0
文件: forms.py 项目: RedBuld/Aviator
 def upgrade(self, product):
     r1 = self.name.validate(self)
     r2 = self.memo.validate(self)
     r3 = self.img.validate(self)
     r4 = self.price.validate(self)
     if r1 and r2 and r3 and r4:
         category = Category.query.get(self.category.data)
         if category is None:
             self.category.errors.append(_(u'Category not found'))
             return False
         product.category = category
         product.name = self.name.data
         product.memo = self.memo.data
         if not self.img.data == '' and not self.img.data is None:
             if check_img(self.img.data):
                 if not product.img == self.img.data:
                     remove_img(product.img)
                     i = Upload.query.filter_by(url=self.img.data).first()
                     db.session.delete(i)
                 product.img = self.img.data
         product.price = self.price.data
         db.session.add(product)
         db.session.commit()
         self.product = product
         return True
     return False
示例#3
0
 def create_new(self):
     r1 = self.name.validate(self)
     r2 = self.memo.validate(self)
     r3 = self.img.validate(self)
     r4 = self.price.validate(self)
     if r1 and r2 and r3 and r4:
         category = Category.query.get(self.category.data)
         if category is None:
             self.category.errors.append(_(u'Category not found'))
             return False
         if not check_img(self.img.data):
             self.img.errors.append(_(u'Image not found'))
             return False
         product = Product()
         product.init(self.name.data, self.memo.data, self.img.data, self.price.data)
         product.category = category
         i = Upload.query.filter_by(url=self.img.data).first()
         db.session.delete(i)
         db.session.add(product)
         db.session.commit()
         self.product = product
         return True
     return False
示例#4
0
文件: forms.py 项目: RedBuld/Aviator
 def create_new(self):
     r1 = self.name.validate(self)
     r2 = self.memo.validate(self)
     r3 = self.img.validate(self)
     r4 = self.price.validate(self)
     if r1 and r2 and r3 and r4:
         category = Category.query.get(self.category.data)
         if category is None:
             self.category.errors.append(_(u'Category not found'))
             return False
         if not check_img(self.img.data):
             self.img.errors.append(_(u'Image not found'))
             return False
         product = Product()
         product.init(self.name.data, self.memo.data, self.img.data,
                      self.price.data)
         product.category = category
         i = Upload.query.filter_by(url=self.img.data).first()
         db.session.delete(i)
         db.session.add(product)
         db.session.commit()
         self.product = product
         return True
     return False