arpakitlib 1.8.110__py3-none-any.whl → 1.8.111__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- arpakitlib/_arpakit_project_template_v_5/arpakitlib_project_template_info.json +1 -1
- arpakitlib/_arpakit_project_template_v_5/project/sqladmin_/model_view/common.py +56 -1
- {arpakitlib-1.8.110.dist-info → arpakitlib-1.8.111.dist-info}/METADATA +1 -1
- {arpakitlib-1.8.110.dist-info → arpakitlib-1.8.111.dist-info}/RECORD +7 -7
- {arpakitlib-1.8.110.dist-info → arpakitlib-1.8.111.dist-info}/LICENSE +0 -0
- {arpakitlib-1.8.110.dist-info → arpakitlib-1.8.111.dist-info}/WHEEL +0 -0
- {arpakitlib-1.8.110.dist-info → arpakitlib-1.8.111.dist-info}/entry_points.txt +0 -0
@@ -1,5 +1,14 @@
|
|
1
|
+
import datetime as dt
|
2
|
+
import io
|
3
|
+
import json
|
4
|
+
from typing import Any, List
|
5
|
+
|
6
|
+
import starlette.responses
|
7
|
+
from openpyxl import Workbook
|
1
8
|
from sqladmin import ModelView
|
2
9
|
|
10
|
+
from project.core.util import now_local_dt
|
11
|
+
|
3
12
|
|
4
13
|
class SimpleMV(ModelView):
|
5
14
|
can_create = True
|
@@ -11,7 +20,53 @@ class SimpleMV(ModelView):
|
|
11
20
|
page_size_options = [50, 100, 200, 500, 750, 1000]
|
12
21
|
save_as = True
|
13
22
|
save_as_continue = True
|
14
|
-
export_types = ["xlsx"
|
23
|
+
export_types = ["xlsx"]
|
24
|
+
|
25
|
+
async def export_data(
|
26
|
+
self,
|
27
|
+
data: List[Any],
|
28
|
+
export_type: str = "csv",
|
29
|
+
) -> starlette.responses.StreamingResponse:
|
30
|
+
if export_type == "xlsx":
|
31
|
+
return await self.export_data_into_xlsx(data=data)
|
32
|
+
else:
|
33
|
+
return await super().export_data(data=data, export_type=export_type)
|
34
|
+
|
35
|
+
async def export_data_into_xlsx(self, data: list[Any]) -> starlette.responses.StreamingResponse:
|
36
|
+
wb = Workbook()
|
37
|
+
wb.active.title = f"{self.model.__name__}"
|
38
|
+
wb.active.append(self.get_list_columns())
|
39
|
+
|
40
|
+
for d in data:
|
41
|
+
wb.active.append([
|
42
|
+
self._serialize_value_for_export_data_into_xlsx(getattr(d, column_name, ""))
|
43
|
+
for column_name in self.get_list_columns()
|
44
|
+
])
|
45
|
+
|
46
|
+
output = io.BytesIO()
|
47
|
+
wb.save(output)
|
48
|
+
output.seek(0)
|
49
|
+
|
50
|
+
filename = f"{self.model.__name__}_export_{now_local_dt().strftime("%d.%m.%YT%H-%M-%S-%Z%z")}.xlsx"
|
51
|
+
|
52
|
+
return starlette.responses.StreamingResponse(
|
53
|
+
output,
|
54
|
+
media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
55
|
+
headers={
|
56
|
+
"Content-Disposition": f"attachment; filename=\"{filename}\""
|
57
|
+
},
|
58
|
+
)
|
59
|
+
|
60
|
+
def _serialize_value_for_export_data_into_xlsx(self, value: Any) -> str:
|
61
|
+
if value is None:
|
62
|
+
return ""
|
63
|
+
if isinstance(value, dt.datetime):
|
64
|
+
return value.strftime("%d.%m.%Y %H:%M:%S %Z%z")
|
65
|
+
if isinstance(value, dt.date):
|
66
|
+
return value.strftime("%d.%m.%Y")
|
67
|
+
if isinstance(value, (dict, list)):
|
68
|
+
return json.dumps(value, ensure_ascii=False, default=str)
|
69
|
+
return str(value)
|
15
70
|
|
16
71
|
|
17
72
|
def get_simple_mv_class() -> type[SimpleMV]:
|
@@ -8,7 +8,7 @@ arpakitlib/_arpakit_project_template_v_5/alembic/env.py,sha256=Qesmnj5A2kB-Doeuf
|
|
8
8
|
arpakitlib/_arpakit_project_template_v_5/alembic/script.py.mako,sha256=MEqL-2qATlST9TAOeYgscMn1uy6HUS9NFvDgl93dMj8,635
|
9
9
|
arpakitlib/_arpakit_project_template_v_5/alembic/versions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
10
|
arpakitlib/_arpakit_project_template_v_5/alembic.ini,sha256=8fuyeEvGBiPGbxEFy8ISBV3xX_fgVmuhEGpB10_B5Uo,3733
|
11
|
-
arpakitlib/_arpakit_project_template_v_5/arpakitlib_project_template_info.json,sha256=
|
11
|
+
arpakitlib/_arpakit_project_template_v_5/arpakitlib_project_template_info.json,sha256=o3UxTcbS0YBkewD0pMMAWC8bJGs-V6tzvpFhgw0useE,98
|
12
12
|
arpakitlib/_arpakit_project_template_v_5/command/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
13
|
arpakitlib/_arpakit_project_template_v_5/command/alembic_history.sh,sha256=OMnDNtHIksGh9iavWnzbtxcudZW4vjdcISsBXvzZSPw,22
|
14
14
|
arpakitlib/_arpakit_project_template_v_5/command/alembic_revision_autogenerate.sh,sha256=yW2i-SBOtBx15Ya0poVQqKkJM5t2JZp06r9AEW-DmGE,46
|
@@ -233,7 +233,7 @@ arpakitlib/_arpakit_project_template_v_5/project/sqladmin_/create_sqladmin_app.p
|
|
233
233
|
arpakitlib/_arpakit_project_template_v_5/project/sqladmin_/event.py,sha256=LjAUYNlsX9Sj_QLMzYuTQbbYYbIMHhbsSjTXt-G7lOE,849
|
234
234
|
arpakitlib/_arpakit_project_template_v_5/project/sqladmin_/model_view/__init__.py,sha256=dc_swzjkRDj85SWQ3cGGgsrp_cq5evUYQYUg0g7C5nw,435
|
235
235
|
arpakitlib/_arpakit_project_template_v_5/project/sqladmin_/model_view/api_key.py,sha256=VZKCG2GQworbmB_PPHPU10qMf5IThP0LN27k50XlHlg,1570
|
236
|
-
arpakitlib/_arpakit_project_template_v_5/project/sqladmin_/model_view/common.py,sha256=
|
236
|
+
arpakitlib/_arpakit_project_template_v_5/project/sqladmin_/model_view/common.py,sha256=StdbfHZ92qAP-l2lnvAeyYCaZuMHKskHq1E19zJh6MA,2471
|
237
237
|
arpakitlib/_arpakit_project_template_v_5/project/sqladmin_/model_view/operation.py,sha256=4BFJEp_yIpZltfEjsBC__J_BfgIBYzOc6LeoWFxP1MI,2785
|
238
238
|
arpakitlib/_arpakit_project_template_v_5/project/sqladmin_/model_view/story_log.py,sha256=8N9ahbCzNVczqgO_g0luRqP8luCv5bmCLoz66UYZ0mU,1427
|
239
239
|
arpakitlib/_arpakit_project_template_v_5/project/sqladmin_/model_view/user.py,sha256=-QxTreqrSZkIUDrTWkkTH8jI--tH7kXwpWq9TRn_1X4,1984
|
@@ -392,8 +392,8 @@ arpakitlib/ar_ssh_runner_util.py,sha256=yvAwza480MkHKvLkDEsR7JNh2bYNs6P9rCVo4NA8
|
|
392
392
|
arpakitlib/ar_str_util.py,sha256=CAv0wH8nP5Ja59S-hEdmNhNrM_Fwy935d0zntLpJkx8,4309
|
393
393
|
arpakitlib/ar_type_util.py,sha256=Cs_tef-Fc5xeyAF54KgISCsP11NHyzIsglm4S3Xx7iM,4049
|
394
394
|
arpakitlib/ar_yookassa_api_client_util.py,sha256=VozuZeCJjmLd1zj2BdC9WfiAQ3XYOrIMsdpNK-AUlm0,5347
|
395
|
-
arpakitlib-1.8.
|
396
|
-
arpakitlib-1.8.
|
397
|
-
arpakitlib-1.8.
|
398
|
-
arpakitlib-1.8.
|
399
|
-
arpakitlib-1.8.
|
395
|
+
arpakitlib-1.8.111.dist-info/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
|
396
|
+
arpakitlib-1.8.111.dist-info/METADATA,sha256=Mjct-ehVPyOyZIp4nDKE5oJWtPvFcdJ_X2JmNcy45uI,3566
|
397
|
+
arpakitlib-1.8.111.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
398
|
+
arpakitlib-1.8.111.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
|
399
|
+
arpakitlib-1.8.111.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|