def add_project(): try: request.get_json()["status"] = True request.get_json()["createAt"] = datetime.datetime.utcnow() request.get_json()["lastUpdateTime"] = datetime.datetime.utcnow() filtered_data = Project.filter_field(request.get_json(), use_set_default=True) Project.insert(filtered_data) return jsonify({'status': 'ok', 'data': '新建成功'}) except BaseException as e: return jsonify({'status': 'failed', 'data': '新建失败 %s' % e})
def update_project(project_id): try: filtered_data = Project.filter_field(request.get_json()) for key, value in filtered_data.items(): Project.update({"_id": ObjectId(project_id)}, {'$set': {key: value}}) update_response = Project.update({"_id": ObjectId(project_id)}, {'$set': {'lastUpdateTime': datetime.datetime.utcnow()}},) if update_response["n"] == 0: return jsonify({'status': 'failed', 'data': '未找到相应更新数据!'}) return jsonify({'status': 'ok', 'data': '更新成功'}) except BaseException as e: return jsonify({'status': 'failed', 'data': '更新失败: %s' % e})