Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @doc.summary('Update engagement by ID')
- @doc.consumes(EngagementUpdateBody, location='body')
- @doc.consumes(XClientHeader, location='header')
- @last_modified('match_info', 'engagement_id')
- async def patch(self, request, engagement_id):
- """HTTP PATCH method for Engagement update.
- Args:
- request (sanic.request.Request): Request object that should contain X-Client header.
- engagement_id (str): String representation of the MongoDB engagement
- document id.
- Returns:
- sanic.response.HTTPResponse object with engagement document data:
- {
- "data": {"isUpdated": True or False},
- "response_datetime": "2019-01-24T11:35:02.078577",
- "status": "success"
- }
- Raises:
- sanic.exceptions.InvalidUsage: If request doesn't contains X-Client header.
- """
- try:
- await parser.parse(EngagementUpdateSchema(strict=True), request, locations=('headers', "json"))
- except Exception as e:
- print(e)
- controller = request.app.controllers.EngagementsController
- is_update_template = request.json.get('uploadTemplateId')
- is_with_option_wizard = 'entities' in request.json
- user_data = await self.get_session_data(request)
- user_id = user_data.get("useracct_id")
- force_update = util.strtobool(request.args.get('force_update', 'False'))
- if is_update_template or force_update or not is_with_option_wizard:
- result = await controller.patch_upload_template_by_engagement(request, engagement_id, user_id=user_id)
- else:
- if not request.json.get('entities'):
- raise BadRequestError("The field 'entities' is empty - there is must be at least one entity")
- result = await controller.patch_engagement_by_id(request, engagement_id)
- return self.get_response(result)
- @doc.summary('Update engagement by ID')
- @doc.consumes(EngagementUpdateBody, location='body')
- @doc.consumes(XClientHeader, location='header')
- @last_modified('match_info', 'engagement_id')
- async def patch(self, request, engagement_id):
- """HTTP PATCH method for Engagement update.
- Args:
- request (sanic.request.Request): Request object that should contain X-Client header.
- engagement_id (str): String representation of the MongoDB engagement
- document id.
- Returns:
- sanic.response.HTTPResponse object with engagement document data:
- {
- "data": {"isUpdated": True or False},
- "response_datetime": "2019-01-24T11:35:02.078577",
- "status": "success"
- }
- Raises:
- sanic.exceptions.InvalidUsage: If request doesn't contains X-Client header.
- """
- try:
- await parser.parse(EngagementUpdateSchema(strict=True),
- request,
- locations=('headers', "json"))
- except Exception as e:
- print(e)
- controller = request.app.controllers.EngagementsController
- request_data = await self.get_session_data(request)
- user_id = request_data.get("useracct_id")
- if not self.is_update_engagement(request_data):
- result = await controller.patch_upload_template_by_engagement(
- request,
- engagement_id,
- user_id=user_id
- )
- else:
- result = await controller.patch_engagement_by_id(request, engagement_id)
- return self.get_response(result)
- @staticmethod
- def is_update_engagement(request_data: dict) -> bool:
- is_with_optional_wizard = "entities" in request_data
- is_upload_template = request_data.get("uploadTemplateId", False)
- force_update = util.strtobool(request_data.get("force_update", "False"))
- if is_upload_template or force_update or not is_with_optional_wizard:
- return False
- if not request_data.get('entities'):
- raise BadRequestError(
- "The field 'entities' is empty - there is must be at least one entity"
- )
- return True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement