def add(): """ :return: :rtype: """ if not request.json \ or 'name' not in request.json \ or 'type' not in request.json: return jsonify({'response': 'insufficient arguments'}), 400 user_token = request.headers.get('Authorization').split()[1] user_ID = get_jwt_identity() data = request.get_json() name = data.pop('name') type = "app" # data.pop('type') description = data.pop('description') tags = data.pop('tags', '') tags = str_utility.split_without_empty(tags) project = AppService.create_project(name, description, user_ID, tags=tags, type=type, user_token=user_token, **data) project = json_utility.convert_to_json(project.to_mongo()) return jsonify({'response': project}), 200
def update_user_request(cls, user_request_id, **kwargs): tags = kwargs.pop('tags', []) if not isinstance(tags, list): tags = str_utility.split_without_empty(tags) select_project_id = kwargs.pop('select_project') if select_project_id: select_project = ProjectBusiness.get_by_id(select_project_id) kwargs.update({'select_project': select_project}) request = UserRequestBusiness.update_by_id( user_request_id=user_request_id, **kwargs) # todo 判断是否更新到Elasticsearch 那边的数据 if 'description' in kwargs or 'title' in kwargs: try: SearchService.add_request(request.title, request.description, request.type, request.user.username, request.id) except: pass oldtags = [tag.id for tag in request.tags] # update tags cls.update_tags(oldtags=oldtags, newtags=tags, entity_type='request', entities=[request]) # request.add_tags(tags) return request
def create_project(): if not request.json \ or 'name' not in request.json \ or 'type' not in request.json: return jsonify({'response': 'insufficient arguments'}), 400 user_token = request.headers.get('Authorization').split()[1] user_ID = get_jwt_identity() data = request.get_json() name = data.pop('name') type = data.pop('type') description = data.pop('description') tags = data.pop('tags', '') if not isinstance(tags, list) and tags is not None: data['tags'] = str_utility.split_without_empty(tags) type_mapper = { "app": AppService, "module": ModuleService, "dataset": DatasetService, } try: project = type_mapper[type].create_project(name, description, user_ID, tags=tags, type=type, user_token=user_token, **data) except Exception as e: return jsonify({'response': str(e)}), 400 project = json_utility.convert_to_json(project.to_mongo()) return jsonify({'response': project}), 200
def update_project(project_identity): data = request.get_json() tags = data.get('tags') if not isinstance(tags, list) and tags is not None: data['tags'] = str_utility.split_without_empty(tags) if request.args.get('by') == 'name': project = ProjectBusiness.update_project_by_identity( project_identity, **data) else: project = ProjectBusiness.update_project(project_identity, **data) project = json_utility.convert_to_json(project.to_mongo()) return jsonify({'response': project}), 200