def save(): """保存一元云购活动""" g.title = u'保存一元云购活动' g.page_type = '' errmsg = {} form = request.form lottery_id = toint(form.get('lottery_id', '0')) section_number = toint(form.get('section_number', '0')) goods_id = toint(form.get('goods_id', '0')) lottery_name = form.get('lottery_name', '').strip() lottery_img = request.files.get('lottery_img', None) lottery_price = Decimal(form.get('lottery_price', '0.0')) max_quantity = toint(form.get('max_quantity', '0')) finish_quantity = toint(form.get('finish_quantity', '0')) # 每人最多参与次数 不能大于 达到开奖人次数量 if max_quantity > finish_quantity: max_quantity = u'每人最多参与次数 不能大于 达到开奖人次数量' g.errmsg = errmsg return render_template('lottery/add.html.j2', f=form, **locals()) # 检查 - 封面原图是否合法 if lottery_img: oss = AliyunOSS('lottery', current_app.config['SAVE_TARGET_PATH']) try: oss.save(lottery_img) lottery_img = oss.put_to_oss() except UploadNotAllowed, e: errmsg['lottery_img'] = u'图片只允许是图片文件' except Exception, e: errmsg['lottery_img'] = u'图片上传失败'
def column_save(): """保存商品栏目""" param_dict = get_params({'gc_id':int,'column_name':str,'column_img':None,'status':int,'sort_order':int, 'brief':str}) required_param_list = ['column_name','status'] form = request.form for param in required_param_list: val = request.form.get(param, '') val = val.strip() if not val: errmsg[param] = u'必填项' g.errmsg = errmsg log_debug('errmsg:%s'%g.errmsg) return render_template('goods/column_detail.html.j2', f=form,**locals()) # 检查 - 封面原图是否合法 column_img = param_dict['column_img'] if column_img: oss = AliyunOSS('goods', current_app.config['SAVE_TARGET_PATH']) try: oss.save(column_img) column_img = oss.put_to_oss() except UploadNotAllowed, e: errmsg['column_img'] = u'图片只允许是图片文件' except Exception, e: errmsg['column_img'] = u'图片上传失败'
def check(self): """ 检查 """ # 商品主图 _goods_img = request.files.get('goods_img', None) # 商品相册 _gallery_list = request.files.getlist('gallery') # 筛选属性 _attr_id_list = request.form.getlist('attr_id') _attr_id_list = list(set(_attr_id_list)) # SKU _sku_list = request.form.getlist('sku') _sku_name_list = request.form.getlist('sku_name') _sku_price_list = request.form.getlist('sku_price') _sku_quantity_list = request.form.getlist('sku_quantity') # 是否创建商品 self.is_new = True if self.goods_id == 0 else False # 检查 - 必填项 required_arr = ['goods_name', 'is_sale', 'is_hot', 'is_pre', 'is_new', 'goods_price', 'is_free_shipping', 'is_return'] for key in required_arr: value = self.form.get(key, '').strip() if not value: self.errmsg[key] = u'必填项' # 检查 - 新建商品是否上传商品主图 if self.is_new and not _goods_img: self.errmsg['goods_img'] = u'必填项' gc_id = toint(self.form.get('gc_id', '0')) if gc_id <= 0: self.errmsg['gc_id'] = u'必填项' # 检查 - 商品是否存在 if not self.is_new: self.goods = Goods.get(self.goods_id) if not self.goods: self.errmsg['submit'] = u'商品不存在' # 检查 - 商品主图是否合法 if _goods_img: oss = AliyunOSS('goods', current_app.config['SAVE_TARGET_PATH']) try: oss.save(_goods_img) self.goods_img = oss.put_to_oss() except UploadNotAllowed, e: self.errmsg['goods_img'] = u'商品图片只允许是图片文件' except Exception, e: self.errmsg['goods_img'] = u'商品图片上传失败'
def check(self): """ 检查 """ # 资讯主图 status = toint(self.form.get('status'), 0) is_top = toint(self.form.get('is_top'), 0) _news_img = request.files.get('news_img', None) # 是否创建资讯 self.is_new = True if self.news_id == 0 else False # 检查 - 必填项 # required_arr = ['title', 'detail', 'status', 'jingdu_weidu', 'nc_id'] required_arr = ['title', 'detail', 'status', 'is_top', 'nc_id'] for key in required_arr: value = self.form.get(key, '').strip() if not value: self.errmsg[key] = u'必填项' # 检查 - 新建资讯是否上传资讯主图 if self.is_new and not _news_img: self.errmsg['news_img'] = u'必填项' # 检查 - 资讯是否存在 if not self.is_new: self.news = News.get(self.news_id) if not self.news: self.errmsg['submit'] = u'资讯不存在' if status == -1: self.errmsg['status'] = u'请选择显示状态' if is_top == -1: self.errmsg['is_top'] = u'请选择是否推荐到首页' # 检查 - 资讯主图是否合法 if _news_img: oss = AliyunOSS('news', current_app.config['SAVE_TARGET_PATH']) try: oss.save(_news_img) self.news_img = oss.put_to_oss() except UploadNotAllowed, e: self.errmsg['news_img'] = u'资讯主图只允许是图片文件' except Exception, e: self.errmsg['news_img'] = u'资讯主图上传失败'
def ad_save(): """保存广告""" g.title = u'保存广告' g.page_type = '' form = request.form adv_id = toint(form.get('adv_id', '0')) ttype = toint(form.get('ttype', '0')) tid = toint(form.get('tid', '0')) is_show = toint(form.get('is_show', '0')) sort_order = toint(form.get('sort_order', '0')) ac_id = toint(form.get('ac_id', '0')) adv_category = form.get('adv_category', '') adv_title = form.get('adv_title', '') adv_title2 = form.get('adv_title2', '') adv_desc = form.get('adv_desc', '') adv_img = request.files.get('adv_img', None) errmsg = {} form = request.form required_param_list = ['is_show', 'ac_id', 'ttype', 'tid'] for param in required_param_list: val = form.get(param, '') val = val.strip() if not val: errmsg[param] = u'必填项' if errmsg: g.errmsg = errmsg log_debug('errmsg:%s' % g.errmsg) return render_template('sys/ad_edit.html.j2', f=form) # 检查 - 封面原图是否合法 if adv_img: oss = AliyunOSS('ad', current_app.config['SAVE_TARGET_PATH']) try: oss.save(adv_img) adv_img = oss.put_to_oss() except UploadNotAllowed, e: errmsg['adv_img'] = u'图片只允许是图片文件' except Exception, e: errmsg['adv_img'] = u'图片上传失败'
def goods_edit_save(): """保存编辑商品评价""" g.title = u'保存编辑商品评价' g.page_type = '' errmsg = {} param_dict = get_params({ 'comment_id': int, 'goods_id': int, 'tname': str, 'timg': None, 'star': int, 'content': str, 'add_time': str }) required_param_list = [ 'comment_id', 'tname', 'star', 'content', 'add_time' ] for param in required_param_list: val = request.form.get(param, '') val = val.strip() if not val: errmsg[param] = u'必填项' g.errmsg = errmsg log_debug('errmsg:%s' % g.errmsg) return render_template('comment/goods_edit.html.j2', f=form, **locals()) # 检查 - 封面原图是否合法 timg = param_dict['timg'] if timg: oss = AliyunOSS('comment', current_app.config['SAVE_TARGET_PATH']) try: oss.save(timg) timg = oss.put_to_oss() except UploadNotAllowed, e: errmsg['timg'] = u'图片只允许是图片文件' except Exception, e: errmsg['timg'] = u'图片上传失败'
def category_save(): """ 保存分类 """ g.page_type = '' g.title = u'保存分类' form = request.form edit_gc_id = toint(form.get('edit_gc_id', '0')) category_name = form.get('category_name', '').strip() brief = form.get('brief', '') sort_order = toint(form.get('sort_order', '0')) status = toint(form.get('status', '-1')) category_img = request.files['category_img'] errmsg = {} # GoodsCategory表是否为空 goods_category_list = GoodsCategory.query.all() if edit_gc_id <= 0: gs = GoodsCategory() db.session.add(gs) else: gs = GoodsCategory.query.get_or_404(edit_gc_id) #判段新增商品分类是否重复 is_exit_category = GoodsCategory.query.filter(GoodsCategory.gc_id != edit_gc_id).\ filter(GoodsCategory.category_name == category_name).first() if is_exit_category: errmsg['category_name'] = u'新增商品分类已经存在' g.errmsg = errmsg return render_template('goods/category_add.html.j2', f=form,**locals()) if category_img: oss = AliyunOSS('user', current_app.config['SAVE_TARGET_PATH']) try: oss.save(category_img) gs.category_img = oss.put_to_oss() except UploadNotAllowed, e: errmsg['category_img'] = u'只允许是图片文件' return render_template('goods/category_add.html.j2', f=form,**locals()) except Exception, e: errmsg['category_img'] = u'原图上传失败' return render_template('goods/category_add.html.j2', f=form,**locals())
def upload(): """图片导入""" form = request.form ic_id = toint(form.get('hidden_ic_id', '0')) img_title = form.get('hidden_img_title', '').strip() _img_list = request.files.getlist('image[]') i = None ic = ImgCategory.query.get(ic_id) ic_name = ic.ic_name if ic else '' # 处理 for _img in _img_list: img_title = _img.filename[:-4] if not img_title else img_title oss = AliyunOSS('img', current_app.config['SAVE_TARGET_PATH']) try: oss.save(_img) _img = oss.put_to_oss() except UploadNotAllowed, e: return u'头像必须是图片文件' except Exception, e: return u'发生错误,上传失败'
def check(self): """ 检查 """ # 群组原图 _salon_img = request.files.get('salon_img', None) # 是否创建群组 self.is_new = True if self.us_id == 0 else False # 检查 - 必填项 required_arr = ['salon_name', 'sort_order', 'desc'] for key in required_arr: value = self.form.get(key, '').strip() if not value: self.errmsg[key] = u'必填项' # 检查 - 新建群组是否上传群组原图 if self.is_new and not _salon_img: self.errmsg['salon_img'] = u'必填项' # 检查 - 群组是否存在 if not self.is_new: self.salon = UserSalon.query.get(self.us_id) if not self.salon: self.errmsg['submit'] = u'群组不存在' # 检查 - 群组原图是否合法 if _salon_img: oss = AliyunOSS('user', current_app.config['SAVE_TARGET_PATH']) try: oss.save(_salon_img) self.salon_img = oss.put_to_oss() except UploadNotAllowed, e: self.errmsg['salon_img'] = u'只允许是图片文件' except Exception, e: self.errmsg['salon_img'] = u'原图上传失败'
def save(): """保存图片""" form = request.form img_id = toint(form.get('img_id', '0')) ic_id = toint(form.get('ic_id', '0')) _img = request.files.get('_img', None) img_title = form.get('img_title', '').strip() ttype = toint(form.get('ttype', '0')) tid = toint(form.get('tid', '0')) sort_order = toint(form.get('sort_order', '0')) is_display = toint(form.get('is_display', '-1')) img_desc = form.get('img_desc', '').strip() errmsg = {} if img_id <= 0: img = Img.create(add_time=int(time.time())) is_img_title = Img.query.filter(Img.img_title == img_title).first() else: img = Img.query.get(img_id) is_img_title = Img.query.filter(Img.img_title == img_title).\ filter(Img.img_id != img_id).first() if not img: g.errmsg = errmsg['img'] = u'获取图片信息失败' log_debug('errmsg:%s' % g.errmsg) return render_template('img/detail.html.j2', f=form, **locals()) if _img: oss = AliyunOSS('img', current_app.config['SAVE_TARGET_PATH']) try: oss.save(_img) _img = oss.put_to_oss() except UploadNotAllowed, e: errmsg['img'] = u'头像必须是图片文件' except Exception, e: errmsg['img'] = u'发生错误,上传失败'
if file_type == 2: # push_type 1.图片 2.视频 3.音频 4.文档 push_type = 2 oss = QiNiuOSS('video', push_type, current_app.config['SAVE_TARGET_PATH']) try: oss.save(one_file) file_url = oss.put_to_oss() except IOError, e: log_info(u'### 只允许是视频文件:%s' % e) pass except Exception, e: log_info(u'### 视频上传失败:%s' % e) pass else: oss = AliyunOSS(cat, current_app.config['SAVE_TARGET_PATH']) try: oss.save(one_file) file_url = oss.put_to_oss() except UploadNotAllowed, e: pass except Exception, e: pass log_debug(file_url) return file_url @sys.route('/setting', methods=['GET', 'POST']) def setting():
self.errmsg['submit'] = u'商品不存在' # 检查 - 商品主图是否合法 if _goods_img: oss = AliyunOSS('goods', current_app.config['SAVE_TARGET_PATH']) try: oss.save(_goods_img) self.goods_img = oss.put_to_oss() except UploadNotAllowed, e: self.errmsg['goods_img'] = u'商品图片只允许是图片文件' except Exception, e: self.errmsg['goods_img'] = u'商品图片上传失败' # 检查 - 商品相册是否合法 for gallery in _gallery_list: oss = AliyunOSS('goods', current_app.config['SAVE_TARGET_PATH']) try: oss.save(gallery) goods_gallery = oss.put_to_oss() self.goods_gallery_list.append(goods_gallery) except UploadNotAllowed, e: self.errmsg['gallery'] = u'商品相册图片只允许是图片文件' except Exception, e: self.errmsg['gallery'] = u'商品相册图片上传失败' # 检查 - 筛选属性是否合法 for attr_id in _attr_id_list: if not self.is_new: goods_attr = GoodsAttr.query.filter(GoodsAttr.goods_id == self.goods_id).\ filter(GoodsAttr.attr_id == attr_id).first() if goods_attr:
def save_temp(): """保存一元云购活动""" g.title = u'保存一元云购活动' g.page_type = '' errmsg = {} param_dict = get_params({ 'lt_id': int, 'section_number': int, 'goods_id': int, 'lottery_name': str, 'lottery_img': None, 'lottery_price': Decimal, 'max_quantity': int, 'finish_quantity': int }) lt_id = param_dict['lt_id'] is_new = True if lt_id <= 0 else False goods_list = Goods.query.filter(Goods.kind == 2).\ filter(Goods.is_sale == 1).all() finish_quantity = param_dict['finish_quantity'] if finish_quantity < 1: errmsg['finish_quantity'] = u'达到开奖人次数量不能小于1' required_param_list = [ 'goods_id', 'lottery_price', 'max_quantity', 'finish_quantity' ] form = request.form for param in required_param_list: val = request.form.get(param, '') val = val.strip() if not val: errmsg[param] = u'必填项' g.errmsg = errmsg log_debug('errmsg:%s' % g.errmsg) return render_template('lottery/add_template.html.j2', f=form, **locals()) goods = Goods.query.get_or_404(param_dict['goods_id']) # 每人最多参与次数 不能大于 达到开奖人次数量 if param_dict['max_quantity'] > finish_quantity: errmsg['max_quantity'] = u'每人最多参与次数 不能大于 达到开奖人次数量' g.errmsg = errmsg return render_template('lottery/add_template.html.j2', f=form, **locals()) # 检查 - 封面原图是否合法 lottery_img = param_dict['lottery_img'] if lottery_img: oss = AliyunOSS('lottery', current_app.config['SAVE_TARGET_PATH']) try: oss.save(lottery_img) lottery_img = oss.put_to_oss() except UploadNotAllowed, e: errmsg['lottery_img'] = u'图片只允许是图片文件' except Exception, e: errmsg['lottery_img'] = u'图片上传失败'