def get_legacy_attachment_stream(filename): # Filenames come prefixed with SID by convention. for i, c in enumerate(filename): if not c.isdigit(): break sid = filename[:i] if not sid: return None # Ensure that the file exists. attachment_result = data_loch.get_sis_advising_note_attachment( sid, filename) if not attachment_result or not attachment_result[0]: return None if attachment_result[0].get('created_by') == 'UCBCONVERSION': display_filename = filename else: display_filename = attachment_result[0].get('user_file_name') if attachment_result[0].get('is_historical'): s3_key = '/'.join([ app.config['DATA_LOCH_S3_ADVISING_NOTE_ATTACHMENT_PATH'], sid, filename ]) else: s3_key = '/'.join([ app.config['DATA_LOCH_S3_ADVISING_NOTE_ATTACHMENT_INCR_PATH'], filename ]) return { 'filename': display_filename, 'stream': s3.stream_object(app.config['DATA_LOCH_S3_ADVISING_NOTE_BUCKET'], s3_key), }
def get_boa_attachment_stream(attachment): if attachment: path = attachment.path_to_attachment return { 'filename': attachment.get_user_filename(), 'stream': s3.stream_object(app.config['DATA_LOCH_S3_ADVISING_NOTE_BUCKET'], path), } else: return None