"""Logic for Image. Handle logic for images. """ from images import response from images.models import image def post_image(filename, php_session_cookie_value): """Return a parsed response object from bulk upload call. The prepare_for_bulk_upload call will make a request to Workstation to prepare an asset to be uploaded using the bulk uploader. This function is taking the response from prepare_for_bulk_uploader and parsing it down to match the requirements by the frontend for the request to the bulk uploader. Args: filename (string): Filename of the file to be passed to the model layer. php_session_cookie_value (string): The php session cookie value to be passed to the model layer. Returns: Response: A response object containing the returned data from from the model layer. """ bulk_upload_response = image.prepare_for_bulk_upload( filename, php_session_cookie_value) if(bulk_upload_response.status == 500): return bulk_upload_response bulk_upload_message = bulk_upload_response.message upload_filename = bulk_upload_message.get('upload_filename') import_asset_id = bulk_upload_message.get('import_asset_id') vendor_id = bulk_upload_message.get('vendor_id') token = bulk_upload_message.get('token') asset_code = bulk_upload_message.get('asset_code') file_description = '{0}|{1}|{2}|{3}|{4}'.format( upload_filename, import_asset_id, vendor_id, token, asset_code) response_message = { 'file_description': file_description, 'id': bulk_upload_message.get('original_filename'), 'upload_filename': upload_filename, 'import_asset_id': import_asset_id} return response.Response(message=response_message, status=200)