| @@ 23-64 (lines=42) @@ | ||
| 20 | #################################################################################################################### |
|
| 21 | ||
| 22 | ||
| 23 | def export(result, |
|
| 24 | name, |
|
| 25 | reporting_start_datetime_local, |
|
| 26 | reporting_end_datetime_local, |
|
| 27 | period_type): |
|
| 28 | #################################################################################################################### |
|
| 29 | # Step 1: Validate the report data |
|
| 30 | #################################################################################################################### |
|
| 31 | if result is None: |
|
| 32 | return None |
|
| 33 | ||
| 34 | if "reporting_period" not in result.keys() or \ |
|
| 35 | "names" not in result['reporting_period'].keys() or len(result['reporting_period']['names']) == 0: |
|
| 36 | return None |
|
| 37 | #################################################################################################################### |
|
| 38 | # Step 2: Generate excel file from the report data |
|
| 39 | #################################################################################################################### |
|
| 40 | filename = generate_excel(result, |
|
| 41 | name, |
|
| 42 | reporting_start_datetime_local, |
|
| 43 | reporting_end_datetime_local, |
|
| 44 | period_type) |
|
| 45 | ||
| 46 | #################################################################################################################### |
|
| 47 | # Step 3: Encode the excel file to Base64 |
|
| 48 | #################################################################################################################### |
|
| 49 | try: |
|
| 50 | with open(filename, 'rb') as binary_file: |
|
| 51 | binary_file_data = binary_file.read() |
|
| 52 | except IOError as ex: |
|
| 53 | pass |
|
| 54 | ||
| 55 | # Base64 encode the bytes |
|
| 56 | base64_encoded_data = base64.b64encode(binary_file_data) |
|
| 57 | # get the Base64 encoded data using human-readable characters. |
|
| 58 | base64_message = base64_encoded_data.decode('utf-8') |
|
| 59 | # delete the file from server |
|
| 60 | try: |
|
| 61 | os.remove(filename) |
|
| 62 | except NotImplementedError as ex: |
|
| 63 | pass |
|
| 64 | return base64_message |
|
| 65 | ||
| 66 | ||
| 67 | def generate_excel(report, |
|
| @@ 22-62 (lines=41) @@ | ||
| 19 | #################################################################################################################### |
|
| 20 | ||
| 21 | ||
| 22 | def export(report, |
|
| 23 | name, |
|
| 24 | reporting_start_datetime_local, |
|
| 25 | reporting_end_datetime_local, |
|
| 26 | period_type): |
|
| 27 | #################################################################################################################### |
|
| 28 | # Step 1: Validate the report data |
|
| 29 | #################################################################################################################### |
|
| 30 | if report is None: |
|
| 31 | return None |
|
| 32 | print(report) |
|
| 33 | if "reporting_period" not in report.keys() or \ |
|
| 34 | "names" not in report['reporting_period'].keys() or len(report['reporting_period']['names']) == 0: |
|
| 35 | return None |
|
| 36 | #################################################################################################################### |
|
| 37 | # Step 2: Generate excel file from the report data |
|
| 38 | #################################################################################################################### |
|
| 39 | filename = generate_excel(report, |
|
| 40 | name, |
|
| 41 | reporting_start_datetime_local, |
|
| 42 | reporting_end_datetime_local, |
|
| 43 | period_type) |
|
| 44 | #################################################################################################################### |
|
| 45 | # Step 3: Encode the excel file to Base64 |
|
| 46 | #################################################################################################################### |
|
| 47 | try: |
|
| 48 | with open(filename, 'rb') as binary_file: |
|
| 49 | binary_file_data = binary_file.read() |
|
| 50 | except IOError as ex: |
|
| 51 | pass |
|
| 52 | ||
| 53 | # Base64 encode the bytes |
|
| 54 | base64_encoded_data = base64.b64encode(binary_file_data) |
|
| 55 | # get the Base64 encoded data using human-readable characters. |
|
| 56 | base64_message = base64_encoded_data.decode('utf-8') |
|
| 57 | # delete the file from server |
|
| 58 | try: |
|
| 59 | os.remove(filename) |
|
| 60 | except NotImplementedError as ex: |
|
| 61 | pass |
|
| 62 | return base64_message |
|
| 63 | ||
| 64 | ||
| 65 | def generate_excel(report, |
|
| @@ 21-57 (lines=37) @@ | ||
| 18 | # Step 3: Encode the excelexporters file to Base64 |
|
| 19 | #################################################################################################################### |
|
| 20 | ||
| 21 | def export(result, name, reporting_start_datetime_local, reporting_end_datetime_local, period_type): |
|
| 22 | #################################################################################################################### |
|
| 23 | # Step 1: Validate the report data |
|
| 24 | #################################################################################################################### |
|
| 25 | if result is None: |
|
| 26 | return None |
|
| 27 | ||
| 28 | if "reporting_period" not in result.keys() or \ |
|
| 29 | "values" not in result['reporting_period'].keys() or len(result['reporting_period']['values']) == 0: |
|
| 30 | return None |
|
| 31 | #################################################################################################################### |
|
| 32 | # Step 2: Generate excel file from the report data |
|
| 33 | #################################################################################################################### |
|
| 34 | filename = generate_excel(result, |
|
| 35 | name, |
|
| 36 | reporting_start_datetime_local, |
|
| 37 | reporting_end_datetime_local, |
|
| 38 | period_type) |
|
| 39 | #################################################################################################################### |
|
| 40 | # Step 3: Encode the excel file to Base64 |
|
| 41 | #################################################################################################################### |
|
| 42 | try: |
|
| 43 | with open(filename, 'rb') as binary_file: |
|
| 44 | binary_file_data = binary_file.read() |
|
| 45 | except IOError as ex: |
|
| 46 | pass |
|
| 47 | ||
| 48 | # Base64 encode the bytes |
|
| 49 | base64_encoded_data = base64.b64encode(binary_file_data) |
|
| 50 | # get the Base64 encoded data using human-readable characters. |
|
| 51 | base64_message = base64_encoded_data.decode('utf-8') |
|
| 52 | # delete the file from server |
|
| 53 | try: |
|
| 54 | os.remove(filename) |
|
| 55 | except NotImplementedError as ex: |
|
| 56 | pass |
|
| 57 | return base64_message |
|
| 58 | ||
| 59 | ||
| 60 | def generate_excel(report, name, reporting_start_datetime_local, reporting_end_datetime_local, period_type): |
|
| @@ 21-57 (lines=37) @@ | ||
| 18 | # Step 3: Encode the excelexporters file to Base64 |
|
| 19 | #################################################################################################################### |
|
| 20 | ||
| 21 | def export(report, name, reporting_start_datetime_local, reporting_end_datetime_local, period_type): |
|
| 22 | #################################################################################################################### |
|
| 23 | # Step 1: Validate the report data |
|
| 24 | #################################################################################################################### |
|
| 25 | if report is None: |
|
| 26 | return None |
|
| 27 | ||
| 28 | if "reporting_period" not in report.keys() or \ |
|
| 29 | "values" not in report['reporting_period'].keys() or len(report['reporting_period']['values']) == 0: |
|
| 30 | return None |
|
| 31 | #################################################################################################################### |
|
| 32 | # Step 2: Generate excel file from the report data |
|
| 33 | #################################################################################################################### |
|
| 34 | filename = generate_excel(report, |
|
| 35 | name, |
|
| 36 | reporting_start_datetime_local, |
|
| 37 | reporting_end_datetime_local, |
|
| 38 | period_type) |
|
| 39 | #################################################################################################################### |
|
| 40 | # Step 3: Encode the excel file to Base64 |
|
| 41 | #################################################################################################################### |
|
| 42 | try: |
|
| 43 | with open(filename, 'rb') as binary_file: |
|
| 44 | binary_file_data = binary_file.read() |
|
| 45 | except IOError as ex: |
|
| 46 | pass |
|
| 47 | ||
| 48 | # Base64 encode the bytes |
|
| 49 | base64_encoded_data = base64.b64encode(binary_file_data) |
|
| 50 | # get the Base64 encoded data using human-readable characters. |
|
| 51 | base64_message = base64_encoded_data.decode('utf-8') |
|
| 52 | # delete the file from server |
|
| 53 | try: |
|
| 54 | os.remove(filename) |
|
| 55 | except NotImplementedError as ex: |
|
| 56 | pass |
|
| 57 | return base64_message |
|
| 58 | ||
| 59 | ||
| 60 | def generate_excel(report, name, reporting_start_datetime_local, reporting_end_datetime_local, period_type): |
|