def _process(): res_dict = dict() processed_list = list() for res_file in request.files: if res_file in res_names: result, url = upload_img(request.files.get(res_file)) if not result: raise FlaskProcessError(10003, u'资源上传失败: %s' % res_file) res_dict.update({res_file + suffix: url}) processed_list.append(res_file) if require: result = filter(lambda x: x not in processed_list, res_names) if result: raise FlaskProcessError(10003, '', result) return res_dict
def update(): access_status = judging_permissions('2_2_2') if access_status.get('code') != 200: return jsonify(access_status) _update = {} data = {key: dict(request.form)[key][0] for key in dict(request.form)} if not data: data = request.get_json() _id = data.get('_id') if not _id or not ObjectId.is_valid(_id): return jsonify({'code': 201, 'msg': u'参数错误'}) _obj = help_center.find_one({'_id': ObjectId(_id)}) if not _obj: return jsonify({'code': 202, 'msg': u'不存在'}) for key in default_values: if key in data: _values = data.get(key) if _values: # if isinstance(_values, str) or isinstance(_values, unicode): if isinstance(_values, str): _values = _values.strip() if key in int_key: try: _values = int(_values) except: return jsonify({'code': 201, 'msg': u'参数错误'}) if _obj.get(key) != _values: if key == 'password': _values = generate_password_hash(_values) _update.update({key: _values}) if 'img_url' in _update: del _update['img_url'] _file = request.files img_url_file = _file.get('img_url') if img_url_file: result, img_url = upload_img(img_url_file) if not result: return jsonify({'code': 206, 'msg': img_url}) _update.update({'img_url': img_url}) if _update: try: help_center.update_one({'_id': ObjectId(_id)}, {'$set': _update}) return jsonify({'code': 200, 'msg': u'成功'}) except: pass else: return jsonify({'code': 203, 'msg': u'无更新数据'}) return jsonify({'code': 204, 'msg': u'失败'})
def add(): data = {key: dict(request.form)[key][0] for key in dict(request.form)} if not data: data = request.get_json() access_status = judging_permissions('2_2_0') if access_status.get('code') != 200: return jsonify(access_status) _file = request.files img_url_file = _file.get('img_url') if img_url_file: result, img_url = upload_img(img_url_file) if not result: return jsonify({'code': 206, 'msg': img_url}) data.update({'img_url': img_url}) result = _insert(data) if result.get('status', False): return jsonify({'code': 200, 'msg': u'成功'}) else: return jsonify({'code': 203, 'msg': result.get('msg', '')})
def update(): _update = {} data = {key: dict(request.form)[key][0] for key in dict(request.form)} if not data: data = request.get_json() _obj = system.find_one() if not _obj: result = _insert(data) if result.get('status'): return jsonify({'code': 200, 'msg': u'成功'}) return jsonify({'code': 200, 'msg': u'不存在'}) for key in default_values: if key in data: _values = data.get(key) # if isinstance(_values, str) or isinstance(_values, unicode): if isinstance(_values, str): _values = _values.strip() if key in int_key: try: _values = int(_values) except: return jsonify({'code': 201, 'msg': u'参数错误'}) if key in float_key: try: _values = float(_values) except: return jsonify({'code': 201, 'msg': u'参数错误'}) if _obj.get(key) != _values: _update.update({key: _values}) if 'img_url' in _update: del _update['img_url'] _file = request.files img_url_file = _file.get('img_url') if img_url_file: result, img_url = upload_img(img_url_file) if not result: return jsonify({'code': 206, 'msg': img_url}) _update.update({'img_url': img_url}) if 'ball_avatar' in _update: del _update['ball_avatar'] _file = request.files ball_avatar_file = _file.get('ball_avatar') if ball_avatar_file: result, img_url = upload_img(ball_avatar_file) if not result: return jsonify({'code': 206, 'msg': img_url}) _update.update({'ball_avatar': img_url}) if 'gzh_qrcode' in _update: del _update['gzh_qrcode'] _file = request.files gzh_qrcode_file = _file.get('gzh_qrcode') if gzh_qrcode_file: result, img_url = upload_img(gzh_qrcode_file) if not result: return jsonify({'code': 206, 'msg': img_url}) _update.update({'gzh_qrcode': img_url}) if _update: try: system.update_one({'_id': _obj.get('_id')}, {'$set': _update}) return jsonify({'code': 200, 'msg': u'成功'}) except: pass else: return jsonify({'code': 203, 'msg': u'无更新数据'}) return jsonify({'code': 204, 'msg': u'失败'})