def design_conf_list(): meta = { 'title': '设计公司配置管理', 'css_nav_sub_design_conf': 'active', 'css_nav_design': 'active' } 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)) t = force_int(request.args.get('t', 1), 1) q = request.args.get('q', '') if q: if t == 1: query['mark'] = q.strip() 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: meta['css_all'] = 'active' query['deleted'] = deleted page_url = url_for('admin.design_conf_list', page="#p#", q=q, t=t, status=status) data = DesignConf.objects(**query).order_by('-created_at').paginate( page=page, per_page=per_page) total_count = DesignConf.objects(**query).count() # 过滤数据 for i, d in enumerate(data.items): pass meta['data'] = data.items pager = Pager(page, per_page, total_count, page_url) meta['pager'] = pager.render_view() return render_template('admin/design_conf/list.html', meta=meta)
def design_conf_delete(): meta = { 'title': '设计公司配置管理', 'css_nav_sub_design_conf': 'active', 'css_nav_design': 'active' } 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: design_conf = DesignConf.objects(_id=ObjectId(d)).first() design_conf.mark_delete() if design_conf 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.design_conf_list'))
def company_stat(mark, no): conf = DesignConf.objects(mark=mark).first() if not conf: print("配置文件不存在!") return page = 1 perPage = 100 isEnd = False successStatCount = 0 failStatCount = 0 query = {} query['deleted'] = 0 query['status'] = 1 while not isEnd: data = DesignCompany.objects(**query).order_by('-created_at').paginate( page=page, per_page=perPage) if not data: print("get data is empty! \n") continue # 过滤数据 for i, d in enumerate(data.items): options = {'company': d, 'conf': conf, 'mark': mark, 'no': no} result = company_stat_core(**options) if result['success']: successStatCount += 1 else: continue print("current page %s: \n" % page) page += 1 if len(data.items) < perPage: isEnd = True print("is over execute SuccessCount %d ---- failCount: %d\n" % (successStatCount, failStatCount)) ## 统计平均分 print("Begin stat average.....\n") company_average_stat(mark, no) # 更新排名 print("Begin update ranking....\n") company_update_rank(mark, no)
def design_conf_submit(): meta = { 'title': '设计公司配置管理', 'css_nav_sub_design_conf': 'active', 'css_nav_design': 'active' } id = request.args.get('id', None) meta['data'] = None if id: design_conf = DesignConf.objects(_id=ObjectId(id)).first() meta['data'] = design_conf form = SaveForm() meta['referer_url'] = request.environ.get( 'HTTP_REFERER') if request.environ.get('HTTP_REFERER') else '' return render_template('admin/design_conf/submit.html', meta=meta, form=form)
def design_record_list(): meta = { 'title': '设计公司统计管理', 'css_nav_sub_design_record': 'active', 'css_nav_design': 'active' } 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)) sort = force_int(request.args.get('sort', 0)) is_d3in = force_int(request.args.get('is_d3in', 0)) mark = request.args.get('mark', '') number = request.args.get('number', '') no = request.args.get('no', '') if mark: query['mark'] = mark if no: query['no'] = no if number: query['number'] = number if is_d3in: if is_d3in == -1: query['is_d3in'] = 0 elif is_d3in == 1: query['is_d3in'] = 1 if status == -1: meta['css_disable'] = 'active' query['status'] = 0 if status == 1: query['status'] = 1 meta['css_enable'] = 'active' else: meta['css_all'] = 'active' query['deleted'] = deleted # 排序 sortVal = '-created_at' nSortVal = '-base_average' if sort: if sort == 1: sortVal = '-ave_score' elif sort == 2: sortVal = '-base_average' elif sort == 3: sortVal = '-business_average' elif sort == 4: sortVal = '-innovate_average' elif sort == 5: sortVal = '-design_average' elif sort == 6: sortVal = '-effect_average' elif sort == 7: sortVal = '-credit_average' if sortVal == nSortVal: nSortVal = '-base_average' page_url = url_for('admin.design_record_list', page="#p#", mark=mark, no=no, number=number, sort=sort, is_d3in=is_d3in, status=status) data = DesignRecord.objects(**query).order_by(sortVal, nSortVal).paginate( page=page, per_page=per_page) total_count = DesignRecord.objects(**query).count() # 过滤数据 for i, d in enumerate(data.items): data.items[i].design_company = {} designCompany = DesignCompany.objects(number=int(d.number)).fields( ['_id', 'name', 'logo_url', 'd3ing_id']).first() if designCompany: data.items[i].design_company = designCompany meta['data'] = data.items # 获取配置列表 confArr = DesignConf.objects(status=1).fields(['mark', 'name']) meta['design_conf'] = confArr pager = Pager(page, per_page, total_count, page_url) meta['pager'] = pager.render_view() meta['total_count'] = total_count meta['design_dimension_options'] = design_dimension_options() meta['design_fields_label_options'] = design_fields_label_options() #current_app.logger.debug('aaaa') return render_template('admin/design_record/list.html', meta=meta)