Use openpyxl at runtime

- See discussion 'import openpyxl' 
- Projects that don't use ReportView (or SpreadsheetExportMixin) and wagtail.contrib.redirects should see a memory use decrease
pull/11636/head
SebCorbin 2024-12-02 15:25:15 +01:00 zatwierdzone przez LB (Ben Johnston)
rodzic bc34020e0d
commit fceda14872
4 zmienionych plików z 8 dodań i 5 usunięć
docs/releases
wagtail
admin/views
contrib/redirects

Wyświetl plik

@ -82,6 +82,7 @@ Changelog
* Maintenance: Enhance the Stimulus `ZoneController` (`w-zone`) to support inactive class and a mechanism to switch the mode based on data within events (Ayaan Qadri)
* Maintenance: Use the Stimulus `ZoneController` (`w-zone`) to remove ad-hoc jQuery for the privacy switch when toggling visibility of private/public elements (Ayaan Qadri)
* Maintenance: Remove unused `is_active` & `active_menu_items` from `wagtail.admin.menu.MenuItem` (Srishti Jaiswal)
* Maintenance: Only call `openpyxl` at runtime to improve performance for projects that do not use `ReportView`, `SpreadsheetExportMixin` and `wagtail.contrib.redirects` (Sébastien Corbin)
6.3.2 (xx.xx.xxxx) - IN DEVELOPMENT

Wyświetl plik

@ -100,7 +100,7 @@ depth: 1
* Enhance the Stimulus `ZoneController` (`w-zone`) to support inactive class and a mechanism to switch the mode based on data within events (Ayaan Qadri)
* Use the Stimulus `ZoneController` (`w-zone`) to remove ad-hoc jQuery for the privacy switch when toggling visibility of private/public elements (Ayaan Qadri)
* Remove unused `is_active` & `active_menu_items` from `wagtail.admin.menu.MenuItem` (Srishti Jaiswal)
* Only call `openpyxl` at runtime to improve performance for projects that do not use `ReportView`, `SpreadsheetExportMixin` and `wagtail.contrib.redirects` (Sébastien Corbin)
## Upgrade considerations - changes affecting all projects

Wyświetl plik

@ -14,8 +14,6 @@ from django.utils.formats import get_format
from django.utils.functional import cached_property
from django.utils.text import capfirst
from django.utils.translation import gettext as _
from openpyxl import Workbook
from openpyxl.cell import WriteOnlyCell
from wagtail.admin.widgets.button import Button
from wagtail.coreutils import multigetattr
@ -208,6 +206,8 @@ class SpreadsheetExportMixin:
def generate_xlsx_row(self, worksheet, row_dict, date_format=None):
"""Generate cells to append to the worksheet"""
from openpyxl.cell import WriteOnlyCell
for field, value in row_dict.items():
cell = WriteOnlyCell(
worksheet, self.preprocess_field_value(field, value, self.FORMAT_XLSX)
@ -246,6 +246,8 @@ class SpreadsheetExportMixin:
def write_xlsx(self, queryset, output):
"""Write an xlsx workbook from a queryset"""
from openpyxl import Workbook
workbook = Workbook(write_only=True, iso_dates=True)
worksheet = workbook.create_sheet(title="Sheet1")

Wyświetl plik

@ -1,8 +1,6 @@
import csv
from io import BytesIO, StringIO
import openpyxl
class Dataset(list):
def __init__(self, rows=(), headers=None):
@ -66,6 +64,8 @@ class XLSX:
"""
Create dataset from the first sheet of a xlsx workbook.
"""
import openpyxl
workbook = openpyxl.load_workbook(BytesIO(data), read_only=True, data_only=True)
sheet = workbook.worksheets[0]
try: