def brand_list(): meta = metaInit.copy() query = {} page = force_int(request.args.get('page', 1)) per_page = force_int(request.args.get('per_page', 100)) status = force_int(request.args.get('status', 0)) deleted = force_int(request.args.get('deleted', 0)) kind = force_int(request.args.get('kind', 0)) t = force_int(request.args.get('t', 1), 1) q = request.args.get('q', '') if q: if t==1: query['_id'] = force_int(q) if t==2: query['name'] = {"$regex": q.strip()} if status == -1: meta['css_disable'] = 'active' query['status'] = 0 if status == 1: query['status'] = 1 meta['css_enable'] = 'active' else: pass if deleted == 1: query['deleted'] = 1 meta['css_deleted'] = 'active' else: query['deleted'] = 0 if not status and not deleted: meta['css_all'] = 'active' else: meta['css_all'] = '' page_url = url_for('admin.brand_list', page="#p#", q=q, t=t, kind=kind, status=status) data = Brand.objects(**query).order_by('-created_at').paginate(page=page, per_page=per_page) total_count = Brand.objects(**query).count() # 过滤数据 for i, d in enumerate(data.items): data.items[i].cover = d.cover() data.items[i].user = d.user() meta['data'] = data.items meta['total_count'] = total_count pager = Pager(page, per_page, total_count, page_url) meta['pager'] = pager.render_view() return render_template('admin/brand/list.html', meta=meta)
def get_by_filters(): filters = request.get_json() items = Item.get_by_filters(filters) print(items) if not items: return jsonify([]) brands = Brand.get_by_items([i['item_uuid'] for i in items]) return jsonify(brands)
def get_brand_list(): try: brand_list = mongo.db.brand.find() except: error_message = 'Error occured in the fetch for brands' LOG.error(error_message) raise LookupError(error_message) else: formatted_list = [] for brand in brand_list: formatted_brand = Brand.fromdict(brand) formatted_list.append(formatted_brand) return formatted_list
def image_submit(): meta = metaInit.copy() id = request.args.get('id', None) meta['data'] = None if id: item = Image.objects(_id=ObjectId(id)).first() item._id = str(item._id) item.thumb = item.get_thumb_path() item.tags_s = ','.join(item.tags) item.color_tags_s = ','.join(item.color_tags) item.brand_tags_s = ','.join(item.brand_tags) item.material_tags_s = ','.join(item.material_tags) item.style_tags_s = ','.join(item.style_tags) item.technique_tags_s = ','.join(item.technique_tags) item.other_tags_s = ','.join(item.other_tags) item.color_ids_s = ','.join(item.color_ids) meta['data'] = item form = SaveForm() meta['default_tags'] = re.split('[,,]', get_block_content('default_tags')) meta['default_color_tags'] = re.split( '[,,]', get_block_content('default_color_tags')) meta['default_brand_tags'] = re.split( '[,,]', get_block_content('default_brand_tags')) meta['default_material_tags'] = re.split( '[,,]', get_block_content('default_material_tags')) meta['default_style_tags'] = re.split( '[,,]', get_block_content('default_style_tags')) meta['default_technique_tags'] = re.split( '[,,]', get_block_content('default_technique_tags')) meta['default_other_tags'] = re.split( '[,,]', get_block_content('default_other_tags')) meta['prize_options'] = prize_options() categories = Category.objects(kind=2, status=1, deleted=0)[:20] meta['categories'] = categories # 获取品牌列表 brands = Brand.objects(status=1, deleted=0)[:1000] meta['brands'] = brands meta['referer_url'] = request.environ.get( 'HTTP_REFERER') if request.environ.get('HTTP_REFERER') else url_for( 'admin.image_list') return render_template('admin/image/submit.html', meta=meta, form=form)
def brand_submit(): meta = metaInit.copy() id = force_int(request.args.get('id', None)) meta['data'] = None meta['is_edit'] = False if id: item = Brand.objects(_id=id).first() if not item: return jsonify(success=False, message='内容不存在!') meta['data'] = item meta['is_edit'] = True form = SaveForm() meta['referer_url'] = request.environ.get('HTTP_REFERER') if request.environ.get('HTTP_REFERER') else '' return render_template('admin/brand/submit.html', meta=meta, form=form)
def brand_recovery(): meta = {} ids = request.values.get('ids', '') type = request.values.get('type', 1) if not ids: return jsonify(success=False, message='缺少请求参数!') try: arr = ids.split(',') for d in arr: item = Brand.objects(_id=int(d)).first() item.mark_recovery() if item else None except(Exception) as e: return jsonify(success=False, message=str(e)) return jsonify(success=True, message='操作成功!', data={'ids': ids, 'type':type}, redirect_to=url_for('admin.brand_list'))
def get_all(): """ Get all brands of a given retailer /brand?retailer=ims&p=1&ipp=200 """ retailer = request.args.get('retailer') or 'byprice' p = None ipp = None try: p = int(request.args.get('p')) if 'p' in request.args else 1 ipp = int(request.args.get('ipp')) if 'ipp' in request.args else 100000 except: raise errors.ApiError('invalid_data_type', "Query params with wrong data types!") brands = Brand.get_all(retailer=retailer, p=p, ipp=ipp) if not brands: raise errors.ApiError("invalid_request", "Could not fetch data from Postgres Providers") return jsonify(brands)
def image_list(): meta = metaInit.copy() query = {} page = force_int(request.args.get('page', 1)) per_page = force_int(request.args.get('per_page', 20)) status = force_int(request.args.get('status', 1)) deleted = force_int(request.args.get('deleted', 0)) kind = force_int(request.args.get('kind', 1)) prize_id = force_int(request.args.get('prize_id', 0)) tag = request.args.get('tag', '') t = force_int(request.args.get('t', 1), 1) q = request.args.get('q', '') if q: if t == 1: query['_id'] = ObjectId(q.strip()) if t == 2: query['channel'] = q.strip() if t == 3: query['evt'] = force_int(q.strip()) if tag: query['total_tags'] = tag if prize_id: query['prize_id'] = prize_id if kind: if kind == 1: meta['css_industry'] = 'active' elif kind == 2: meta['css_plane'] = 'active' meta['css_all'] = '' query['kind'] = kind if status == -1: meta['css_disable'] = 'active' query['status'] = 0 if status == 1: query['status'] = 1 meta['css_enable'] = 'active' else: pass if deleted == 1: query['deleted'] = 1 meta['css_deleted'] = 'active' else: query['deleted'] = 0 if not status and not deleted: meta['css_all'] = 'active' else: meta['css_all'] = '' page_url = url_for('main.image_list', page="#p#", q=q, t=t, tag=tag, prize_id=prize_id, kind=kind, status=status, deleted=deleted) data = Image.objects(**query).order_by('random').paginate( page=page, per_page=per_page) total_count = Image.objects(**query).count() # 过滤数据 for i, d in enumerate(data.items): prize_label = '' brand = None data.items[i]._id = str(d._id) data.items[i].thumb = d.get_thumb_path() if d.prize_id: prize_label = prize_options(d.prize_id)['name'] if d.brand_id: brand = Brand.objects(_id=d.brand_id).first() data.items[i].prize_label = prize_label data.items[i].brand = brand # 过滤数据 rows = t_image_list(data) meta['data'] = rows meta['total_count'] = total_count meta['prize_options'] = prize_options() pager = Pager(page, per_page, total_count, page_url) meta['pager'] = pager.render_view() return render_template('image/list.html', meta=meta)
def fetch_brand(brand_id): brand = None if brand_id: brand = Brand.objects(_id=brand_id).first() return brand