zrb 0.23.0__py3-none-any.whl → 0.24.0__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.
- zrb/__init__.py +2 -0
- zrb/builtin/devtool/install/_input.py +2 -2
- zrb/builtin/project/add/app/generator/template/src/kebab-zrb-package-name/src/snake_zrb_package_name/snake_zrb_generator_name/template/_automate/snake_zrb_app_name/container/start.py +5 -6
- zrb/builtin/project/add/app/python/template/_automate/snake_zrb_app_name/container/start.py +5 -6
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/_helper.py +1 -52
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/microservices/start.py +5 -6
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/monolith/start.py +5 -6
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/support/start.py +4 -6
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/README.md +84 -8
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/loadtest/locustfile.py +1 -3
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/loadtest/template.env +1 -1
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/config.py +59 -61
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/frontend/src/routes/+layout.svelte +1 -1
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/frontend/vite.config.ts +7 -1
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/app/__init__.py +0 -0
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/{app.py → app/app.py} +30 -29
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/{app_lifespan.py → app/app_lifespan.py} +16 -16
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/{app_state.py → app/app_state.py} +2 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/db_connection.py +14 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/frontend_index.py +2 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/log.py +6 -6
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/messagebus.py +33 -33
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/rpc.py +9 -9
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/main.py +1 -3
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/integration/access_token_scheme.py +2 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/integration/access_token_util.py +7 -7
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/integration/model/user_model.py +6 -6
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/integration/refresh_token_util.py +7 -7
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/integration/user.py +18 -18
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/migrate.py +2 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/register_module.py +9 -9
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/log/migrate.py +2 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/log/register_module.py +9 -9
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/template.env +5 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/test/auth/test_group_crud.py +7 -7
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/test/auth/test_permission_crud.py +7 -7
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/test/auth/test_user_crud.py +7 -7
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/test/auth/test_user_login.py +14 -14
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/test/test_liveness_and_readiness.py +3 -3
- zrb/builtin/project/add/fastapp/crud/_helper/__init__.py +7 -0
- zrb/builtin/project/add/fastapp/crud/_helper/_common.py +8 -0
- zrb/builtin/project/add/fastapp/crud/_helper/register_api.py +45 -0
- zrb/builtin/project/add/fastapp/crud/_helper/register_permission.py +40 -0
- zrb/builtin/project/add/fastapp/crud/_helper/register_rpc.py +45 -0
- zrb/builtin/project/add/fastapp/crud/crud.py +3 -12
- zrb/builtin/project/add/fastapp/crud/template/src/kebab-zrb-app-name/src/module/snake_zrb_module_name/entity/snake_zrb_entity_name/repo.py +12 -1
- zrb/builtin/project/add/fastapp/crud/template/src/kebab-zrb-app-name/src/module/snake_zrb_module_name/schema/snake_zrb_entity_name.py +1 -0
- zrb/builtin/project/add/fastapp/crud/template/src/kebab-zrb-app-name/test/snake_zrb_module_name/test_snake_zrb_entity_name.py +8 -7
- zrb/builtin/project/add/fastapp/field/_helper/__init__.py +17 -0
- zrb/builtin/project/add/fastapp/field/_helper/_common.py +102 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_delete_page.py +49 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_detail_page.py +49 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_insert_page.py +62 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_list_page.py +47 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_repo.py +47 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_schema.py +45 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_test.py +49 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_update_page.py +50 -0
- zrb/builtin/project/add/fastapp/field/_input.py +14 -2
- zrb/builtin/project/add/fastapp/field/field.py +70 -90
- zrb/builtin/project/add/fastapp/module/_helper/__init__.py +17 -0
- zrb/builtin/project/add/fastapp/module/_helper/append_all_disabled_env.py +22 -0
- zrb/builtin/project/add/fastapp/module/_helper/append_all_enabled_env.py +22 -0
- zrb/builtin/project/add/fastapp/module/_helper/append_deployment_template_env.py +25 -0
- zrb/builtin/project/add/fastapp/module/_helper/append_src_template_env.py +25 -0
- zrb/builtin/project/add/fastapp/module/_helper/create_app_config.py +29 -0
- zrb/builtin/project/add/fastapp/module/_helper/create_microservice_config.py +158 -0
- zrb/builtin/project/add/fastapp/module/_helper/register_migration.py +35 -0
- zrb/builtin/project/add/fastapp/module/_helper/register_module.py +33 -0
- zrb/builtin/project/add/fastapp/module/module.py +8 -37
- zrb/builtin/project/add/fastapp/module/template/src/kebab-zrb-app-name/src/module/snake_zrb_module_name/migrate.py +2 -2
- zrb/builtin/project/add/fastapp/module/template/src/kebab-zrb-app-name/src/module/snake_zrb_module_name/register_module.py +9 -9
- zrb/builtin/project/add/plugin/plugin.py +2 -2
- zrb/builtin/project/create/create.py +2 -2
- zrb/builtin/version.py +3 -3
- zrb/config/config.py +14 -14
- zrb/helper/callable.py +3 -1
- zrb/helper/cli.py +4 -4
- zrb/helper/file/copy_tree.py +26 -10
- zrb/helper/log.py +3 -3
- zrb/helper/string/parse_replacement.py +1 -1
- zrb/helper/typecheck.py +2 -2
- zrb/helper/typing.py +2 -2
- zrb/helper/util.py +12 -0
- zrb/runner.py +2 -2
- zrb/task/base_remote_cmd_task.py +5 -1
- zrb/task/base_task/base_task.py +3 -3
- zrb/task/base_task/component/base_task_model.py +9 -9
- zrb/task/cmd_task.py +15 -7
- zrb/task/docker_compose_start_task.py +151 -0
- zrb/task/docker_compose_task.py +35 -16
- zrb/task_input/base_input.py +2 -2
- zrb/task_input/multiline_input.py +2 -2
- {zrb-0.23.0.dist-info → zrb-0.24.0.dist-info}/METADATA +3 -3
- {zrb-0.23.0.dist-info → zrb-0.24.0.dist-info}/RECORD +98 -80
- zrb/builtin/project/add/app/generator/template/src/kebab-zrb-package-name/src/snake_zrb_package_name/snake_zrb_generator_name/template/_automate/snake_zrb_app_name/container/init.py +0 -34
- zrb/builtin/project/add/app/python/template/_automate/snake_zrb_app_name/container/init.py +0 -34
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/microservices/init.py +0 -36
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/monolith/init.py +0 -36
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/support/init.py +0 -26
- zrb/builtin/project/add/fastapp/crud/_helper.py +0 -118
- zrb/builtin/project/add/fastapp/field/_helper.py +0 -342
- zrb/builtin/project/add/fastapp/module/_helper.py +0 -313
- {zrb-0.23.0.dist-info → zrb-0.24.0.dist-info}/LICENSE +0 -0
- {zrb-0.23.0.dist-info → zrb-0.24.0.dist-info}/WHEEL +0 -0
- {zrb-0.23.0.dist-info → zrb-0.24.0.dist-info}/entry_points.txt +0 -0
zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/support/init.py
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
from zrb import DockerComposeTask
|
2
|
-
|
3
|
-
from ..._constant import RESOURCE_DIR
|
4
|
-
from ..._input import host_input, local_input
|
5
|
-
from ...image._input import image_input
|
6
|
-
from .._env import compose_env_file
|
7
|
-
from ..remove import remove_snake_zrb_app_name_container
|
8
|
-
from ._helper import activate_support_compose_profile, should_start_support_container
|
9
|
-
|
10
|
-
init_snake_zrb_app_name_support_container = DockerComposeTask(
|
11
|
-
icon="🔥",
|
12
|
-
name="init-kebab-zrb-app-name-support-container",
|
13
|
-
inputs=[
|
14
|
-
local_input,
|
15
|
-
host_input,
|
16
|
-
image_input,
|
17
|
-
],
|
18
|
-
should_execute=should_start_support_container,
|
19
|
-
upstreams=[remove_snake_zrb_app_name_container],
|
20
|
-
cwd=RESOURCE_DIR,
|
21
|
-
setup_cmd=activate_support_compose_profile,
|
22
|
-
compose_cmd="up",
|
23
|
-
compose_flags=["-d"],
|
24
|
-
compose_env_prefix="CONTAINER_ZRB_ENV_PREFIX",
|
25
|
-
env_files=[compose_env_file],
|
26
|
-
)
|
@@ -1,118 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
|
3
|
-
from zrb.helper.codemod.add_import_module import add_import_module
|
4
|
-
from zrb.helper.codemod.append_code_to_function import append_code_to_function
|
5
|
-
from zrb.helper.file.text import read_text_file_async, write_text_file_async
|
6
|
-
from zrb.helper.typecheck import typechecked
|
7
|
-
from zrb.task.task import Task
|
8
|
-
|
9
|
-
|
10
|
-
@typechecked
|
11
|
-
async def register_api(
|
12
|
-
task: Task,
|
13
|
-
project_dir: str,
|
14
|
-
kebab_app_name: str,
|
15
|
-
snake_module_name: str,
|
16
|
-
snake_entity_name: str,
|
17
|
-
):
|
18
|
-
module_api_file_path = os.path.join(
|
19
|
-
project_dir, "src", kebab_app_name, "src", "module", snake_module_name, "api.py"
|
20
|
-
)
|
21
|
-
register_function_path = ".".join(
|
22
|
-
["module", snake_module_name, "entity", snake_entity_name, "api"]
|
23
|
-
)
|
24
|
-
register_function = f"register_{snake_entity_name}_api"
|
25
|
-
task.print_out(f"Read code from: {module_api_file_path}")
|
26
|
-
code = await read_text_file_async(module_api_file_path)
|
27
|
-
task.print_out(
|
28
|
-
f'Add import "register_api" as "{register_function}" '
|
29
|
-
+ f'from "{register_function_path}" to the code'
|
30
|
-
)
|
31
|
-
code = add_import_module(
|
32
|
-
code=code,
|
33
|
-
module_path=register_function_path,
|
34
|
-
resource="register_api",
|
35
|
-
alias=register_function,
|
36
|
-
)
|
37
|
-
task.print_out(f'Add "{register_function}" call to the code')
|
38
|
-
code = append_code_to_function(
|
39
|
-
code=code,
|
40
|
-
function_name="register_api",
|
41
|
-
new_code=f"{register_function}(logger, app, authorizer, rpc_caller, publisher)", # noqa
|
42
|
-
)
|
43
|
-
task.print_out(f"Write modified code to: {module_api_file_path}")
|
44
|
-
await write_text_file_async(module_api_file_path, code)
|
45
|
-
|
46
|
-
|
47
|
-
@typechecked
|
48
|
-
async def register_rpc(
|
49
|
-
task: Task,
|
50
|
-
project_dir: str,
|
51
|
-
kebab_app_name: str,
|
52
|
-
snake_module_name: str,
|
53
|
-
snake_entity_name: str,
|
54
|
-
):
|
55
|
-
module_rpc_file_path = os.path.join(
|
56
|
-
project_dir, "src", kebab_app_name, "src", "module", snake_module_name, "rpc.py"
|
57
|
-
)
|
58
|
-
register_function_path = ".".join(
|
59
|
-
["module", snake_module_name, "entity", snake_entity_name, "rpc"]
|
60
|
-
)
|
61
|
-
register_function = f"register_{snake_entity_name}_rpc"
|
62
|
-
task.print_out(f"Read code from: {module_rpc_file_path}")
|
63
|
-
code = await read_text_file_async(module_rpc_file_path)
|
64
|
-
task.print_out(
|
65
|
-
f'Add import "register_rpc" as "{register_function}" '
|
66
|
-
+ f'from "{register_function_path}" to the code'
|
67
|
-
)
|
68
|
-
code = add_import_module(
|
69
|
-
code=code,
|
70
|
-
module_path=register_function_path,
|
71
|
-
resource="register_rpc",
|
72
|
-
alias=register_function,
|
73
|
-
)
|
74
|
-
task.print_out(f'Add "{register_function}" call to the code')
|
75
|
-
code = append_code_to_function(
|
76
|
-
code=code,
|
77
|
-
function_name="register_rpc",
|
78
|
-
new_code=f"{register_function}(logger, rpc_server, rpc_caller, publisher)", # noqa
|
79
|
-
)
|
80
|
-
task.print_out(f"Write modified code to: {module_rpc_file_path}")
|
81
|
-
await write_text_file_async(module_rpc_file_path, code)
|
82
|
-
|
83
|
-
|
84
|
-
@typechecked
|
85
|
-
async def register_permission(
|
86
|
-
task: Task,
|
87
|
-
project_dir: str,
|
88
|
-
kebab_app_name: str,
|
89
|
-
snake_module_name: str,
|
90
|
-
snake_entity_name: str,
|
91
|
-
):
|
92
|
-
module_register_permission_file_path = os.path.join(
|
93
|
-
project_dir,
|
94
|
-
"src",
|
95
|
-
kebab_app_name,
|
96
|
-
"src",
|
97
|
-
"module",
|
98
|
-
"auth",
|
99
|
-
"register_permission.py",
|
100
|
-
)
|
101
|
-
task.print_out(f"Read code from: {module_register_permission_file_path}")
|
102
|
-
code = await read_text_file_async(module_register_permission_file_path)
|
103
|
-
code = append_code_to_function(
|
104
|
-
code=code,
|
105
|
-
function_name="register_permission",
|
106
|
-
new_code="\n".join(
|
107
|
-
[
|
108
|
-
"await ensure_entity_permission(",
|
109
|
-
f" module_name='{snake_module_name}', entity_name='{snake_entity_name}'", # noqa
|
110
|
-
")",
|
111
|
-
]
|
112
|
-
),
|
113
|
-
)
|
114
|
-
task.print_out(
|
115
|
-
f'Add "ensure_entity_permission" call for {snake_entity_name} ' + "to the code"
|
116
|
-
)
|
117
|
-
task.print_out(f"Write modified code to: {module_register_permission_file_path}")
|
118
|
-
await write_text_file_async(module_register_permission_file_path, code)
|
@@ -1,342 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
import re
|
3
|
-
|
4
|
-
from zrb.helper.codemod.add_key_value_to_dict import add_key_value_to_dict
|
5
|
-
from zrb.helper.codemod.add_property_to_class import add_property_to_class
|
6
|
-
from zrb.helper.file.text import read_text_file_async, write_text_file_async
|
7
|
-
from zrb.helper.typecheck import typechecked
|
8
|
-
from zrb.task.task import Task
|
9
|
-
|
10
|
-
|
11
|
-
@typechecked
|
12
|
-
async def add_column_to_insert_page(
|
13
|
-
task: Task,
|
14
|
-
project_dir: str,
|
15
|
-
kebab_app_name: str,
|
16
|
-
kebab_module_name: str,
|
17
|
-
kebab_entity_name: str,
|
18
|
-
kebab_column_name: str,
|
19
|
-
snake_column_name: str,
|
20
|
-
capitalized_human_readable_column_name: str,
|
21
|
-
):
|
22
|
-
list_page_file_path = os.path.join(
|
23
|
-
project_dir,
|
24
|
-
"src",
|
25
|
-
kebab_app_name,
|
26
|
-
"src",
|
27
|
-
"frontend",
|
28
|
-
"src",
|
29
|
-
"routes",
|
30
|
-
kebab_module_name,
|
31
|
-
kebab_entity_name,
|
32
|
-
"new",
|
33
|
-
"+page.svelte",
|
34
|
-
)
|
35
|
-
task.print_out(f"Read HTML from: {list_page_file_path}")
|
36
|
-
html_content = await read_text_file_async(list_page_file_path)
|
37
|
-
task.print_out("Add default value to insert page")
|
38
|
-
default_value_regex = r"(.*)(// DON'T DELETE: set field default value here)" # noqa
|
39
|
-
default_value_subst = "\\n".join([f"\\1row.{snake_column_name} = '';", "\\1\\2"])
|
40
|
-
html_content = re.sub(
|
41
|
-
default_value_regex, default_value_subst, html_content, 0, re.MULTILINE
|
42
|
-
)
|
43
|
-
task.print_out("Add field to insert page")
|
44
|
-
field_regex = r"(.*)(<!-- DON'T DELETE: insert new field here-->)"
|
45
|
-
field_subst = "\\n".join(
|
46
|
-
[
|
47
|
-
'\\1<div class="mb-4">',
|
48
|
-
f'\\1 <label class="block text-gray-700 font-bold mb-2" for="{kebab_column_name}">{capitalized_human_readable_column_name}</label>', # noqa
|
49
|
-
f'\\1 <input type="text" class="input w-full" id="{kebab_column_name}" placeholder="{capitalized_human_readable_column_name}" bind:value='
|
50
|
-
+ "{row."
|
51
|
-
+ snake_column_name
|
52
|
-
+ "} />", # noqa
|
53
|
-
"\\1</div>",
|
54
|
-
"\\1\\2",
|
55
|
-
]
|
56
|
-
)
|
57
|
-
html_content = re.sub(field_regex, field_subst, html_content, 0, re.MULTILINE)
|
58
|
-
task.print_out(f"Write modified HTML to: {list_page_file_path}")
|
59
|
-
await write_text_file_async(list_page_file_path, html_content)
|
60
|
-
|
61
|
-
|
62
|
-
@typechecked
|
63
|
-
async def add_column_to_update_page(
|
64
|
-
task: Task,
|
65
|
-
project_dir: str,
|
66
|
-
kebab_app_name: str,
|
67
|
-
kebab_module_name: str,
|
68
|
-
kebab_entity_name: str,
|
69
|
-
kebab_column_name: str,
|
70
|
-
snake_column_name: str,
|
71
|
-
capitalized_human_readable_column_name: str,
|
72
|
-
):
|
73
|
-
list_page_file_path = os.path.join(
|
74
|
-
project_dir,
|
75
|
-
"src",
|
76
|
-
kebab_app_name,
|
77
|
-
"src",
|
78
|
-
"frontend",
|
79
|
-
"src",
|
80
|
-
"routes",
|
81
|
-
kebab_module_name,
|
82
|
-
kebab_entity_name,
|
83
|
-
"update",
|
84
|
-
"[id]",
|
85
|
-
"+page.svelte",
|
86
|
-
)
|
87
|
-
task.print_out(f"Read HTML from: {list_page_file_path}")
|
88
|
-
html_content = await read_text_file_async(list_page_file_path)
|
89
|
-
task.print_out("Add field to update page")
|
90
|
-
regex = r"(.*)(<!-- DON'T DELETE: insert new field here-->)"
|
91
|
-
subst = "\\n".join(
|
92
|
-
[
|
93
|
-
'\\1<div class="mb-4">',
|
94
|
-
f'\\1 <label class="block text-gray-700 font-bold mb-2" for="{kebab_column_name}">{capitalized_human_readable_column_name}</label>', # noqa
|
95
|
-
f'\\1 <input type="text" class="input w-full" id="{kebab_column_name}" placeholder="{capitalized_human_readable_column_name}" bind:value='
|
96
|
-
+ "{row."
|
97
|
-
+ snake_column_name
|
98
|
-
+ "} />", # noqa
|
99
|
-
"\\1</div>",
|
100
|
-
"\\1\\2",
|
101
|
-
]
|
102
|
-
)
|
103
|
-
html_content = re.sub(regex, subst, html_content, 0, re.MULTILINE)
|
104
|
-
task.print_out(f"Write modified HTML to: {list_page_file_path}")
|
105
|
-
await write_text_file_async(list_page_file_path, html_content)
|
106
|
-
|
107
|
-
|
108
|
-
@typechecked
|
109
|
-
async def add_column_to_delete_page(
|
110
|
-
task: Task,
|
111
|
-
project_dir: str,
|
112
|
-
kebab_app_name: str,
|
113
|
-
kebab_module_name: str,
|
114
|
-
kebab_entity_name: str,
|
115
|
-
kebab_column_name: str,
|
116
|
-
snake_column_name: str,
|
117
|
-
capitalized_human_readable_column_name: str,
|
118
|
-
):
|
119
|
-
list_page_file_path = os.path.join(
|
120
|
-
project_dir,
|
121
|
-
"src",
|
122
|
-
kebab_app_name,
|
123
|
-
"src",
|
124
|
-
"frontend",
|
125
|
-
"src",
|
126
|
-
"routes",
|
127
|
-
kebab_module_name,
|
128
|
-
kebab_entity_name,
|
129
|
-
"delete",
|
130
|
-
"[id]",
|
131
|
-
"+page.svelte",
|
132
|
-
)
|
133
|
-
task.print_out(f"Read HTML from: {list_page_file_path}")
|
134
|
-
html_content = await read_text_file_async(list_page_file_path)
|
135
|
-
task.print_out("Add field to delete page")
|
136
|
-
regex = r"(.*)(<!-- DON'T DELETE: insert new field here-->)"
|
137
|
-
subst = "\\n".join(
|
138
|
-
[
|
139
|
-
'\\1<div class="mb-4">',
|
140
|
-
f'\\1 <label class="block text-gray-700 font-bold mb-2" for="{kebab_column_name}">{capitalized_human_readable_column_name}</label>', # noqa
|
141
|
-
f'\\1 <span id="{kebab_column_name}">'
|
142
|
-
+ "{row."
|
143
|
-
+ snake_column_name
|
144
|
-
+ "}</span>", # noqa
|
145
|
-
"\\1</div>",
|
146
|
-
"\\1\\2",
|
147
|
-
]
|
148
|
-
)
|
149
|
-
html_content = re.sub(regex, subst, html_content, 0, re.MULTILINE)
|
150
|
-
task.print_out(f"Write modified HTML to: {list_page_file_path}")
|
151
|
-
await write_text_file_async(list_page_file_path, html_content)
|
152
|
-
|
153
|
-
|
154
|
-
@typechecked
|
155
|
-
async def add_column_to_detail_page(
|
156
|
-
task: Task,
|
157
|
-
project_dir: str,
|
158
|
-
kebab_app_name: str,
|
159
|
-
kebab_module_name: str,
|
160
|
-
kebab_entity_name: str,
|
161
|
-
kebab_column_name: str,
|
162
|
-
snake_column_name: str,
|
163
|
-
capitalized_human_readable_column_name: str,
|
164
|
-
):
|
165
|
-
list_page_file_path = os.path.join(
|
166
|
-
project_dir,
|
167
|
-
"src",
|
168
|
-
kebab_app_name,
|
169
|
-
"src",
|
170
|
-
"frontend",
|
171
|
-
"src",
|
172
|
-
"routes",
|
173
|
-
kebab_module_name,
|
174
|
-
kebab_entity_name,
|
175
|
-
"detail",
|
176
|
-
"[id]",
|
177
|
-
"+page.svelte",
|
178
|
-
)
|
179
|
-
task.print_out(f"Read HTML from: {list_page_file_path}")
|
180
|
-
html_content = await read_text_file_async(list_page_file_path)
|
181
|
-
task.print_out("Add field to detail page")
|
182
|
-
regex = r"(.*)(<!-- DON'T DELETE: insert new field here-->)"
|
183
|
-
subst = "\\n".join(
|
184
|
-
[
|
185
|
-
'\\1<div class="mb-4">',
|
186
|
-
f'\\1 <label class="block text-gray-700 font-bold mb-2" for="{kebab_column_name}">{capitalized_human_readable_column_name}</label>', # noqa
|
187
|
-
f'\\1 <span id="{kebab_column_name}">'
|
188
|
-
+ "{row."
|
189
|
-
+ snake_column_name
|
190
|
-
+ "}</span>", # noqa
|
191
|
-
"\\1</div>",
|
192
|
-
"\\1\\2",
|
193
|
-
]
|
194
|
-
)
|
195
|
-
html_content = re.sub(regex, subst, html_content, 0, re.MULTILINE)
|
196
|
-
task.print_out(f"Write modified HTML to: {list_page_file_path}")
|
197
|
-
await write_text_file_async(list_page_file_path, html_content)
|
198
|
-
|
199
|
-
|
200
|
-
@typechecked
|
201
|
-
async def add_column_to_list_page(
|
202
|
-
task: Task,
|
203
|
-
project_dir: str,
|
204
|
-
kebab_app_name: str,
|
205
|
-
kebab_module_name: str,
|
206
|
-
kebab_entity_name: str,
|
207
|
-
snake_column_name: str,
|
208
|
-
capitalized_human_readable_column_name: str,
|
209
|
-
):
|
210
|
-
list_page_file_path = os.path.join(
|
211
|
-
project_dir,
|
212
|
-
"src",
|
213
|
-
kebab_app_name,
|
214
|
-
"src",
|
215
|
-
"frontend",
|
216
|
-
"src",
|
217
|
-
"routes",
|
218
|
-
kebab_module_name,
|
219
|
-
kebab_entity_name,
|
220
|
-
"+page.svelte",
|
221
|
-
)
|
222
|
-
task.print_out(f"Read HTML from: {list_page_file_path}")
|
223
|
-
html_content = await read_text_file_async(list_page_file_path)
|
224
|
-
# process header
|
225
|
-
task.print_out("Add column header to table")
|
226
|
-
header_regex = r"(.*)(<!-- DON'T DELETE: insert new column header here-->)"
|
227
|
-
header_subst = "\\n".join(
|
228
|
-
[f"\\1<th>{capitalized_human_readable_column_name}</th>", "\\1\\2"]
|
229
|
-
)
|
230
|
-
html_content = re.sub(header_regex, header_subst, html_content, 0, re.MULTILINE)
|
231
|
-
# process column
|
232
|
-
task.print_out("Add column to table")
|
233
|
-
column_regex = r"(.*)(<!-- DON'T DELETE: insert new column here-->)"
|
234
|
-
column_subst = "\\n".join(["\\1<td>{row." + snake_column_name + "}</td>", "\\1\\2"])
|
235
|
-
html_content = re.sub(column_regex, column_subst, html_content, 0, re.MULTILINE)
|
236
|
-
task.print_out(f"Write modified HTML to: {list_page_file_path}")
|
237
|
-
await write_text_file_async(list_page_file_path, html_content)
|
238
|
-
|
239
|
-
|
240
|
-
@typechecked
|
241
|
-
async def add_column_to_test(
|
242
|
-
task: Task,
|
243
|
-
project_dir: str,
|
244
|
-
kebab_app_name: str,
|
245
|
-
snake_module_name: str,
|
246
|
-
snake_entity_name: str,
|
247
|
-
snake_column_name: str,
|
248
|
-
column_type: str,
|
249
|
-
):
|
250
|
-
test_file_path = os.path.join(
|
251
|
-
project_dir,
|
252
|
-
"src",
|
253
|
-
kebab_app_name,
|
254
|
-
"test",
|
255
|
-
snake_module_name,
|
256
|
-
f"test_{snake_entity_name}.py",
|
257
|
-
)
|
258
|
-
task.print_out(f"Read code from: {test_file_path}")
|
259
|
-
code = await read_text_file_async(test_file_path)
|
260
|
-
task.print_out(f'Add column "{snake_column_name}" to the test')
|
261
|
-
dict_names = [
|
262
|
-
"inserted_success_data",
|
263
|
-
"to_be_updated_success_data",
|
264
|
-
"updated_success_data",
|
265
|
-
"to_be_deleted_success_data",
|
266
|
-
]
|
267
|
-
for dict_name in dict_names:
|
268
|
-
code = add_key_value_to_dict(
|
269
|
-
code=code, dict_name=dict_name, key=f"'{snake_column_name}'", value="''"
|
270
|
-
)
|
271
|
-
task.print_out(f"Write modified code to: {test_file_path}")
|
272
|
-
await write_text_file_async(test_file_path, code)
|
273
|
-
|
274
|
-
|
275
|
-
@typechecked
|
276
|
-
async def add_column_to_schema(
|
277
|
-
task: Task,
|
278
|
-
project_dir: str,
|
279
|
-
kebab_app_name: str,
|
280
|
-
snake_module_name: str,
|
281
|
-
snake_entity_name: str,
|
282
|
-
pascal_entity_name: str,
|
283
|
-
snake_column_name: str,
|
284
|
-
column_type: str,
|
285
|
-
):
|
286
|
-
schema_file_path = os.path.join(
|
287
|
-
project_dir,
|
288
|
-
"src",
|
289
|
-
kebab_app_name,
|
290
|
-
"src",
|
291
|
-
"module",
|
292
|
-
snake_module_name,
|
293
|
-
"schema",
|
294
|
-
f"{snake_entity_name}.py",
|
295
|
-
)
|
296
|
-
task.print_out(f"Read code from: {schema_file_path}")
|
297
|
-
code = await read_text_file_async(schema_file_path)
|
298
|
-
task.print_out(f'Add column "{snake_column_name}" to the schema')
|
299
|
-
code = add_property_to_class(
|
300
|
-
code=code,
|
301
|
-
class_name=f"{pascal_entity_name}Data",
|
302
|
-
property_name=snake_column_name,
|
303
|
-
property_type="Optional[str]",
|
304
|
-
)
|
305
|
-
task.print_out(f"Write modified code to: {schema_file_path}")
|
306
|
-
await write_text_file_async(schema_file_path, code)
|
307
|
-
|
308
|
-
|
309
|
-
@typechecked
|
310
|
-
async def add_column_to_repo(
|
311
|
-
task: Task,
|
312
|
-
project_dir: str,
|
313
|
-
kebab_app_name: str,
|
314
|
-
snake_module_name: str,
|
315
|
-
snake_entity_name: str,
|
316
|
-
pascal_entity_name: str,
|
317
|
-
snake_column_name: str,
|
318
|
-
column_type: str,
|
319
|
-
):
|
320
|
-
repo_file_path = os.path.join(
|
321
|
-
project_dir,
|
322
|
-
"src",
|
323
|
-
kebab_app_name,
|
324
|
-
"src",
|
325
|
-
"module",
|
326
|
-
snake_module_name,
|
327
|
-
"entity",
|
328
|
-
snake_entity_name,
|
329
|
-
"repo.py",
|
330
|
-
)
|
331
|
-
task.print_out(f"Read code from: {repo_file_path}")
|
332
|
-
code = await read_text_file_async(repo_file_path)
|
333
|
-
task.print_out(f'Add column "{snake_column_name}" to the repo')
|
334
|
-
code = add_property_to_class(
|
335
|
-
code=code,
|
336
|
-
class_name=f"DBEntity{pascal_entity_name}",
|
337
|
-
property_name=snake_column_name,
|
338
|
-
property_type="Column",
|
339
|
-
property_value="Column(String)",
|
340
|
-
)
|
341
|
-
task.print_out(f"Write modified code to: {repo_file_path}")
|
342
|
-
await write_text_file_async(repo_file_path, code)
|