def detail(): _id = request.args.get('_id') if not _id or not ObjectId.is_valid(_id): return jsonify({'code': 201, 'msg': u'参数错误'}) _obj = admin_user.find_one({'_id': ObjectId(_id)}) if not _obj: return jsonify({'code': 202, 'msg': u'不存在'}) _obj['_id'] = _id _obj['status_name'] = status_values.get(_obj.get('status', 0)) return jsonify({'code': 200, 'data': _obj})
def my_list(): criteria = {} # 支持表格字段里的任何搜索 access_status = judging_permissions('2_6_3') if access_status.get('code') != 200: return jsonify(access_status) for item in default_values: req_value = request.args.get(item) if req_value: req_value = req_value.strip() if item in int_key: try: req_value = int(req_value) except: return jsonify({'code': 201, 'msg': u'参数错误'}) criteria.update({item: req_value}) else: criteria.update({item: {'$regex': req_value}}) try: page_num = int(request.args.get('page_num', 1)) - 1 limit = int(request.args.get('limit', 20)) except: return jsonify({'code': 201, 'msg': u'参数错误'}) _cur = home_ad.find(criteria) _count = _cur.count() if _count % limit: num = _count / limit + 1 else: num = _count / limit if _count > (page_num * limit): _list = [] cur_list = _cur.sort([('status', -1), ('sort_id', 1)]).skip(page_num * limit).limit(limit) for _obj in cur_list: try: _obj['_id'] = str(_obj['_id']) _obj['status_name'] = status_values.get(_obj.get('status', 0), '-') _obj['type_num_name'] = type_num_values.get(_obj.get('type_num', 0), u'帮助文档') _obj['associated_name'] = '-' if _obj.get('associated_id', ''): try: task_obj = app_wake_task.find_one({'_id': ObjectId(_obj.get('associated_id', ''))}) _obj['associated_name'] = task_obj.get('name', '') except: pass _list.append(_obj) except Exception as e: print (e) return jsonify({'code': 200, 'data': {'num': num, 'count': _count, 'page': page_num + 1, 'list': _list}}) else: return jsonify({'code': 200, 'data': {'num': num, 'count': _count, 'page': page_num + 1, 'list': []}})
def my_list(): access_status = judging_permissions('0_7_3') if access_status.get('code') != 200: return jsonify(access_status) criteria = {} # 支持表格字段里的任何搜索 for item in default_values: req_value = request.args.get(item) if req_value: req_value = req_value.strip() if item in int_key: try: req_value = int(req_value) except: return jsonify({'code': 201, 'msg': u'参数错误'}) criteria.update({item: req_value}) else: criteria.update({item: {'$regex': req_value}}) try: page_num = int(request.args.get('page_num', 1)) - 1 limit = int(request.args.get('limit', 20)) except: return jsonify({'code': 201, 'msg': u'参数错误'}) _cur = guess_red.find(criteria) _count = _cur.count() if _count % limit: num = _count / limit + 1 else: num = _count / limit if _count > (page_num * limit): _list = [] cur_list = _cur.sort([('today_str', -1), ('hour_int', -1), ('minute_int', -1)]).skip(page_num * limit).limit( limit) for _obj in cur_list: try: _obj['_id'] = str(_obj['_id']) _obj['status_name'] = status_values.get(_obj.get('status', 0), '') _obj['hour_int_d'] = str(_obj.get('hour_int', 0)) + u' 点' _obj['value'] = '%.2f' % (float(_obj.get('value')) / float(100)) _list.append(_obj) except Exception as e: print(e) return jsonify({'code': 200, 'data': {'num': num, 'count': _count, 'page': page_num + 1, 'list': _list}}) else: return jsonify({'code': 200, 'data': {'num': num, 'count': _count, 'page': page_num + 1, 'list': []}})
def edit(): _id = request.args.get('_id') if not _id: return jsonify({'code': 201, 'msg': u'参数错误'}) _obj = user.find_one({'_id': ObjectId(_id)}) if not _obj: return jsonify({'code': 202, 'msg': u'不存在'}) access_status = judging_permissions('1_0_3') if access_status.get('code') != 200: return jsonify(access_status) _obj['_id'] = _id _obj['status_name'] = status_values.get(_obj.get('status', 0)) _obj['sex_name'] = sex_values.get(_obj.get('sex', 0)) _obj['new_value_name'] = new_value_values.get(_obj.get('new_value')) _obj['grade_name'] = grade_values.get(_obj.get('grade', 1)) _obj['verified_status_name'] = verified_status_values.get(_obj.get('verified_status')) return jsonify({'code': 200, 'data': _obj})
def my_list(): criteria = {} # 支持表格字段里的任何搜索 for item in default_values: req_value = request.args.get(item) if req_value: req_value = req_value.strip() if item in int_key: try: req_value = int(req_value) except: return jsonify({'code': 201, 'msg': u'参数错误'}) criteria.update({item: req_value}) else: criteria.update({item: {'$regex': req_value}}) try: page_num = int(request.args.get('page_num', 1)) - 1 limit = int(request.args.get('limit', 20)) except: return jsonify({'code': 201, 'msg': u'参数错误'}) _cur = admin_user.find(criteria) _count = _cur.count() if _count % limit: num = _count / limit + 1 else: num = _count / limit if _count > (page_num * limit): _list = [] cur_list = _cur.sort([('_id', -1)]).skip(page_num * limit).limit(limit) for _obj in cur_list: try: _obj['_id'] = str(_obj['_id']) _obj['status_name'] = status_values.get(_obj.get('status', 0)) role_id_list = [] user_role_cur = user_role.find({'user_id': _obj['_id']}) for user_role_obj in user_role_cur: role_id_list.append(ObjectId(user_role_obj.get('role_id'))) if role_id_list: role_cur = role.find({'_id': {'$in': role_id_list}}) role_list = [] for role_obj in role_cur: role_list.append(role_obj.get('name')) if role_list: _obj['role_name'] = ','.join(role_list) else: _obj['role_name'] = '-' else: _obj['role_name'] = '-' _obj['lgoin_times'] = login_log.find({ 'user_id': _obj['_id'] }).count() try: _obj['lgoin_time_last'] = login_log.find({ 'user_id': _obj['_id'] }).sort([('_id', -1)])[0].get('created_time') except: _obj['lgoin_time_last'] = '-' _obj['spread_c_name'] = u'无' _list.append(_obj) except Exception as e: print(e) return jsonify({ 'code': 200, 'data': { 'num': num, 'count': _count, 'page': page_num + 1, 'list': _list } }) else: return jsonify({ 'code': 200, 'data': { 'num': num, 'count': _count, 'page': page_num + 1, 'list': [] } })
def edit_list(): role_obj = role.find_one({'name': u'编辑'}) role_id = str(role_obj.get('_id')) user_id_list = [] user_role_cur = user_role.find({'role_id': role_id}) for user_role_obj in user_role_cur: user_id_list.append(ObjectId(user_role_obj.get('user_id'))) criteria = {'_id': {'$in': user_id_list}} try: page_num = int(request.args.get('page_num', 1)) - 1 limit = int(request.args.get('limit', 20)) except: return jsonify({'code': 201, 'msg': u'参数错误'}) _cur = admin_user.find(criteria) _count = _cur.count() if _count % limit: num = _count / limit + 1 else: num = _count / limit if _count > (page_num * limit): _list = [] cur_list = _cur.sort([('_id', -1)]).skip(page_num * limit).limit(limit) for _obj in cur_list: try: _obj['_id'] = str(_obj['_id']) _obj['status_name'] = status_values.get(_obj.get('status', 0)) role_id_list = [] user_role_cur = user_role.find({'user_id': _obj['_id']}) for user_role_obj in user_role_cur: role_id_list.append(ObjectId(user_role_obj.get('role_id'))) if role_id_list: role_cur = role.find({'_id': {'$in': role_id_list}}) role_list = [] for role_obj in role_cur: role_list.append(role_obj.get('name')) if role_list: _obj['role_name'] = ','.join(role_list) else: _obj['role_name'] = '-' else: _obj['role_name'] = '-' _obj['lgoin_times'] = login_log.find({ 'user_id': _obj['_id'] }).count() try: _obj['lgoin_time_last'] = login_log.find({ 'user_id': _obj['_id'] }).sort([('_id', -1)])[0].get('created_time') except: _obj['lgoin_time_last'] = '-' _list.append(_obj) except Exception as e: print(e) return jsonify({ 'code': 200, 'data': { 'num': num, 'count': _count, 'page': page_num + 1, 'list': _list } }) else: return jsonify({ 'code': 200, 'data': { 'num': num, 'count': _count, 'page': page_num + 1, 'list': [] } })
def my_list(): criteria = {} # 支持表格字段里的任何搜索 for item in default_values: req_value = request.args.get(item) if req_value: req_value = req_value.strip() if item in int_key: try: req_value = int(req_value) except: return jsonify({'code': 201, 'msg': u'参数错误'}) criteria.update({item: req_value}) else: criteria.update({item: {'$regex': req_value}}) try: page_num = int(request.args.get('page_num', 1)) - 1 limit = int(request.args.get('limit', 20)) except: return jsonify({'code': 201, 'msg': u'参数错误'}) _cur = version_manag.find(criteria) _count = _cur.count() if _count % limit: num = _count / limit + 1 else: num = _count / limit if _count > (page_num * limit): _list = [] cur_list = _cur.sort([('_id', -1)]).skip(page_num * limit).limit(limit) for _obj in cur_list: try: _obj['_id'] = str(_obj['_id']) _obj['status_name'] = status_values.get( _obj.get('status', 1), '-') _obj['is_upgrade_name'] = is_upgrade_values.get( _obj.get('is_upgrade', 1), '-') _obj['available_status_name'] = available_status_values.get( _obj.get('available_status', 1), '-') _list.append(_obj) except Exception as e: print(e) return jsonify({ 'code': 200, 'data': { 'num': num, 'count': _count, 'page': page_num + 1, 'list': _list } }) else: return jsonify({ 'code': 200, 'data': { 'num': num, 'count': _count, 'page': page_num + 1, 'list': [] } })
def _list(): access_status = judging_permissions('2_1_3') if access_status.get('code') != 200: return jsonify(access_status) criteria = {} # 支持表格字段里的任何搜索 for item in default_values: req_value = request.args.get(item) if req_value: req_value = req_value.strip() if item in int_key: try: req_value = int(req_value) except: return jsonify({'code': 201, 'msg': u'参数错误'}) criteria.update({item: req_value}) else: criteria.update({item: {'$regex': req_value}}) try: page_num = int(request.args.get('page_num', 1)) - 1 limit = int(request.args.get('limit', 20)) except: return jsonify({'code': 201, 'msg': u'参数错误'}) sort_list = [('type_num', 1), ('status', -1)] _cur = bulletin_notice.find(criteria) _count = _cur.count() if _count % limit: num = _count / limit + 1 else: num = _count / limit if _count > (page_num * limit): _list = [] cur_list = _cur.sort(sort_list).skip(page_num * limit).limit(limit) for _obj in cur_list: try: _obj['_id'] = str(_obj['_id']) _obj['status_name'] = status_values.get(_obj.get('status')) _obj['type_num_name'] = type_num_values.get( _obj.get('type_num')) _list.append(_obj) except Exception as e: print(e) return jsonify({ 'code': 200, 'data': { 'num': num, 'count': _count, 'page': page_num + 1, 'list': _list } }) else: return jsonify({ 'code': 200, 'data': { 'num': num, 'count': _count, 'page': page_num + 1, 'list': [] } })