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