Example #1
0
 def update_model(self, form, model):
     """改写了update函数"""
     try:
         model.update(**form_to_dict(form))
         self.session.commit()
     except Exception, ex:
         flash(gettext('Failed to update model. %(error)s', error=str(ex)), 'error')
         logging.exception('Failed to update model')
         self.session.rollback()
         return False
Example #2
0
    def create_model(self, form):
        """改写flask的新建model的函数"""

        try:
            model = self.model(**form_to_dict(form))
            self.session.add(model)
            self.session.commit()
        except Exception, ex:
            flash(gettext('Failed to create model. %(error)s', error=str(ex)), 'error')
            logging.exception('Failed to create model')
            self.session.rollback()
            return False
Example #3
0
 def update_model(self, form, model):
     """改写了update函数"""
     try:
         pub_type_pictures = request.files.getlist("picture")  # 获取分类图片
         model.update(**form_to_dict(form))
         if not check_save_pub_type_pictures(pub_type_pictures, model, update=1):
             return False  # 保存图片, 同时更新model的路径消息
         self.session.commit()
     except Exception, ex:
         flash(gettext("Failed to update model. %(error)s", error=str(ex)), "error")
         logging.exception("Failed to update model")
         self.session.rollback()
         return False
Example #4
0
 def update_model(self, form, model):
     """改写了update函数"""
     try:
         model.update(**form_to_dict(form))
         self.session.commit()
         activity_id = model.id  # 获取和保存酒吧id
         activity_pictures = request.files.getlist("picture")  # 获取酒吧图片
         save_activity_pictures(activity_id, activity_pictures)
     except Exception, ex:
         flash(gettext('Failed to update model. %(error)s', error=str(ex)), 'error')
         logging.exception('Failed to update model')
         self.session.rollback()
         return False
Example #5
0
 def update_model(self, form, model):
     """改写了update函数"""
     try:
         gift_pictures = request.files.getlist("picture")
         model.update(**form_to_dict(form))
         if not check_save_gift_pictures(gift_pictures, model, update=1):
             return False  # 保存图片, 同时更新model的路径消息,不删除历史图片
         self.session.commit()
     except Exception, ex:
         flash(gettext('Failed to update model. %(error)s', error=str(ex)), 'error')
         logging.exception('Failed to update model')
         self.session.rollback()
         return False
Example #6
0
 def update_model(self, form, model):
     '''更新model函数'''
     try:
         advertisement_pictures = request.files.getlist("picture") #todo 图片是list么不是应该获取file么
         model = self.model(**form_to_dict(form))
         if not check_save_advertisement_pictures(advertisement_pictures, model):
             return False
         self.session.add(model) # 添加到数据库中
         self.session.commit()
     except Exception, ex:
         flash(gettext('Failed to create model. %(error)s', error=str(ex)), 'error')
         self.session.rollback() # 如若发生异常回滚事物
         return False
Example #7
0
    def create_model(self, form):
        """改写flask的新建model的函数"""

        try:
            pub_type_pictures = request.files.getlist("picture")  # 获取分类图片
            model = self.model(**form_to_dict(form))  # 更新pub_type的消息
            if not check_save_pub_type_pictures(pub_type_pictures, model):
                return False  # 保存图片, 同时更新model的路径消息
            self.session.add(model)  # 保存酒吧基本资料
            self.session.commit()
        except Exception, ex:
            flash(gettext("Failed to create model. %(error)s", error=str(ex)), "error")
            logging.exception("Failed to create model")
            self.session.rollback()
            return False
Example #8
0
 def update_model(self, form, model):
     """改写了update函数"""
     try:
         model.update(**form_to_dict(form))
         self.session.commit()
         pub_id = model.id  # 获取和保存酒吧id
         pub_type_list = form.pub_type.data  # 获取酒吧的类型字符串
         pub_pictures = request.files.getlist("picture")  # 获取酒吧图片
         delete_pub_type(pub_id)
         save_pub_type(pub_id, pub_type_list)
         save_pub_pictures(pub_id, pub_pictures)
     except Exception, ex:
         flash(gettext("Failed to update model. %(error)s", error=str(ex)), "error")
         logging.exception("Failed to update model")
         self.session.rollback()
         return False
Example #9
0
    def create_model(self, form):
        """改写flask的新建model的函数"""

        try:
            pub_id = request.args.get('pub_id')
            form._fields['pub_id'] = TextField()
            form._fields['pub_id'].data = int(pub_id)
            model = self.model(**form_to_dict(form))
            self.session.add(model)  # 保存酒吧基本资料
            self.session.commit()
            flash(u'活动添加完成,开始上传图片', 'info')
            activity_id = model.id
            activity_pictures = request.files.getlist("picture")  # 获取酒吧图片
            save_activity_pictures(activity_id, activity_pictures)
            flash(u'图片添加完成', 'info')

        except Exception, ex:
            flash(gettext('Failed to create model. %(error)s', error=str(ex)), 'error')
            logging.exception('Failed to create model')
            self.session.rollback()
            return False