|
|
|
@ -21,7 +21,6 @@ from .base import (
|
|
|
|
ExchangeTemplateSnapshot,
|
|
|
|
ExchangeTemplateSnapshot,
|
|
|
|
ExchangeTaskKind,
|
|
|
|
ExchangeTaskKind,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
from .excel import ExcelTemplateCodec, ExcelWorkbookCodec
|
|
|
|
|
|
|
|
from .models import (
|
|
|
|
from .models import (
|
|
|
|
ExchangeTaskModel,
|
|
|
|
ExchangeTaskModel,
|
|
|
|
ExchangeTaskRowModel,
|
|
|
|
ExchangeTaskRowModel,
|
|
|
|
@ -136,7 +135,7 @@ class ExchangeService:
|
|
|
|
with storage.download(version.file_key) as file_stream:
|
|
|
|
with storage.download(version.file_key) as file_stream:
|
|
|
|
return file_stream.read()
|
|
|
|
return file_stream.read()
|
|
|
|
snapshot = self.snapshot_from_model(version)
|
|
|
|
snapshot = self.snapshot_from_model(version)
|
|
|
|
return ExcelTemplateCodec().dump(snapshot)
|
|
|
|
return _excel_template_codec().dump(snapshot)
|
|
|
|
|
|
|
|
|
|
|
|
def build_plan_template_file(self, plan: ExchangePlan) -> bytes:
|
|
|
|
def build_plan_template_file(self, plan: ExchangePlan) -> bytes:
|
|
|
|
if plan.version_id:
|
|
|
|
if plan.version_id:
|
|
|
|
@ -145,7 +144,7 @@ class ExchangeService:
|
|
|
|
storage = get_exchange_storage(self.app)
|
|
|
|
storage = get_exchange_storage(self.app)
|
|
|
|
with storage.download(version.file_key) as file_stream:
|
|
|
|
with storage.download(version.file_key) as file_stream:
|
|
|
|
return file_stream.read()
|
|
|
|
return file_stream.read()
|
|
|
|
return ExcelTemplateCodec().dump(plan)
|
|
|
|
return _excel_template_codec().dump(plan)
|
|
|
|
|
|
|
|
|
|
|
|
def export_rows(
|
|
|
|
def export_rows(
|
|
|
|
self,
|
|
|
|
self,
|
|
|
|
@ -155,7 +154,7 @@ class ExchangeService:
|
|
|
|
fields: list[ExchangeField] | None = None,
|
|
|
|
fields: list[ExchangeField] | None = None,
|
|
|
|
sheet_name: str | None = None,
|
|
|
|
sheet_name: str | None = None,
|
|
|
|
) -> bytes:
|
|
|
|
) -> bytes:
|
|
|
|
workbook_codec = ExcelWorkbookCodec()
|
|
|
|
workbook_codec = _excel_workbook_codec()
|
|
|
|
if plan is not None:
|
|
|
|
if plan is not None:
|
|
|
|
return workbook_codec.export_rows_with_plan(
|
|
|
|
return workbook_codec.export_rows_with_plan(
|
|
|
|
plan=plan,
|
|
|
|
plan=plan,
|
|
|
|
@ -180,7 +179,7 @@ class ExchangeService:
|
|
|
|
plan: ExchangePlan | None = None,
|
|
|
|
plan: ExchangePlan | None = None,
|
|
|
|
fields: list[ExchangeField] | None = None,
|
|
|
|
fields: list[ExchangeField] | None = None,
|
|
|
|
) -> list[dict[str, Any]]:
|
|
|
|
) -> list[dict[str, Any]]:
|
|
|
|
workbook_codec = ExcelWorkbookCodec()
|
|
|
|
workbook_codec = _excel_workbook_codec()
|
|
|
|
if plan is not None and plan.fields:
|
|
|
|
if plan is not None and plan.fields:
|
|
|
|
return workbook_codec.import_rows_with_fields(content, fields=list(plan.fields))
|
|
|
|
return workbook_codec.import_rows_with_fields(content, fields=list(plan.fields))
|
|
|
|
if fields is not None:
|
|
|
|
if fields is not None:
|
|
|
|
@ -501,6 +500,18 @@ def _excel_mime_type() -> str:
|
|
|
|
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
|
|
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _excel_template_codec():
|
|
|
|
|
|
|
|
from .excel import ExcelTemplateCodec
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ExcelTemplateCodec()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _excel_workbook_codec():
|
|
|
|
|
|
|
|
from .excel import ExcelWorkbookCodec
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ExcelWorkbookCodec()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _jsonable(value: Any) -> Any:
|
|
|
|
def _jsonable(value: Any) -> Any:
|
|
|
|
if isinstance(value, Enum):
|
|
|
|
if isinstance(value, Enum):
|
|
|
|
return value.value
|
|
|
|
return value.value
|
|
|
|
|