| Conditions | 7 |
| Total Lines | 101 |
| Code Lines | 78 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import base64 |
||
| 52 | def generate_excel(report, space_name, language): |
||
| 53 | locale_path = './i18n/' |
||
| 54 | if language == 'zh_CN': |
||
| 55 | trans = gettext.translation('myems', locale_path, languages=['zh_CN']) |
||
| 56 | elif language == 'de': |
||
| 57 | trans = gettext.translation('myems', locale_path, languages=['de']) |
||
| 58 | elif language == 'en': |
||
| 59 | trans = gettext.translation('myems', locale_path, languages=['en']) |
||
| 60 | else: |
||
| 61 | trans = gettext.translation('myems', locale_path, languages=['en']) |
||
| 62 | trans.install() |
||
| 63 | _ = trans.gettext |
||
| 64 | wb = Workbook() |
||
| 65 | ws = wb.active |
||
| 66 | ws.title = "EquipmentTracking" |
||
| 67 | |||
| 68 | # Row height |
||
| 69 | ws.row_dimensions[1].height = 118 |
||
| 70 | for i in range(2, 5000 + 1): |
||
| 71 | ws.row_dimensions[i].height = 30 |
||
| 72 | # Col width |
||
| 73 | ws.column_dimensions['A'].width = 1 |
||
| 74 | |||
| 75 | # Font |
||
| 76 | name_font = Font(name='Arial', size=15, bold=True) |
||
| 77 | title_font = Font(name='Arial', size=15, bold=True) |
||
| 78 | |||
| 79 | f_border = Border(left=Side(border_style='medium', color='00000000'), |
||
| 80 | right=Side(border_style='medium', color='00000000'), |
||
| 81 | bottom=Side(border_style='medium', color='00000000'), |
||
| 82 | top=Side(border_style='medium', color='00000000') |
||
| 83 | ) |
||
| 84 | |||
| 85 | b_c_alignment = Alignment(vertical='bottom', |
||
| 86 | horizontal='center', |
||
| 87 | text_rotation=0, |
||
| 88 | wrap_text=True, |
||
| 89 | shrink_to_fit=False, |
||
| 90 | indent=0) |
||
| 91 | c_c_alignment = Alignment(vertical='center', |
||
| 92 | horizontal='center', |
||
| 93 | text_rotation=0, |
||
| 94 | wrap_text=True, |
||
| 95 | shrink_to_fit=False, |
||
| 96 | indent=0) |
||
| 97 | for i in range(ord('B'), ord('F')): |
||
| 98 | ws.column_dimensions[chr(i)].width = 30.0 |
||
| 99 | |||
| 100 | # Img |
||
| 101 | img = Image("excelexporters/myems.png") |
||
| 102 | ws.add_image(img, 'A1') |
||
| 103 | |||
| 104 | # Title |
||
| 105 | ws['B3'].border = f_border |
||
| 106 | ws['B3'].font = name_font |
||
| 107 | ws['B3'].alignment = b_c_alignment |
||
| 108 | ws['B3'] = _('Name') + ':' |
||
| 109 | |||
| 110 | ws['C3'].border = f_border |
||
| 111 | ws['C3'].alignment = b_c_alignment |
||
| 112 | ws['C3'].font = name_font |
||
| 113 | ws['C3'] = _('Space') + ':' |
||
| 114 | |||
| 115 | ws['D3'].border = f_border |
||
| 116 | ws['D3'].font = name_font |
||
| 117 | ws['D3'].alignment = b_c_alignment |
||
| 118 | ws['D3'] = _('Cost Center') + ':' |
||
| 119 | |||
| 120 | ws['E3'].border = f_border |
||
| 121 | ws['E3'].alignment = b_c_alignment |
||
| 122 | ws['E3'].font = name_font |
||
| 123 | ws['E3'] = _('Description') + ':' |
||
| 124 | |||
| 125 | current_row_number = 4 |
||
| 126 | for i in range(0, len(report['equipments'])): |
||
| 127 | |||
| 128 | ws['B' + str(current_row_number)].font = title_font |
||
| 129 | ws['B' + str(current_row_number)].border = f_border |
||
| 130 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
||
| 131 | ws['B' + str(current_row_number)] = report['equipments'][i]['equipment_name'] |
||
| 132 | |||
| 133 | ws['C' + str(current_row_number)].font = title_font |
||
| 134 | ws['C' + str(current_row_number)].border = f_border |
||
| 135 | ws['C' + str(current_row_number)].alignment = c_c_alignment |
||
| 136 | ws['C' + str(current_row_number)] = report['equipments'][i]['space_name'] |
||
| 137 | |||
| 138 | ws['D' + str(current_row_number)].font = title_font |
||
| 139 | ws['D' + str(current_row_number)].border = f_border |
||
| 140 | ws['D' + str(current_row_number)].alignment = c_c_alignment |
||
| 141 | ws['D' + str(current_row_number)] = report['equipments'][i]['cost_center_name'] |
||
| 142 | |||
| 143 | ws['E' + str(current_row_number)].font = title_font |
||
| 144 | ws['E' + str(current_row_number)].border = f_border |
||
| 145 | ws['E' + str(current_row_number)].alignment = c_c_alignment |
||
| 146 | ws['E' + str(current_row_number)] = report['equipments'][i]['description'] |
||
| 147 | current_row_number += 1 |
||
| 148 | |||
| 149 | filename = str(uuid.uuid4()) + '.xlsx' |
||
| 150 | wb.save(filename) |
||
| 151 | |||
| 152 | return filename |
||
| 153 |