diff options
author | Santo Cariotti <dcariotti24@gmail.com> | 2020-03-29 17:03:08 +0200 |
---|---|---|
committer | Santo Cariotti <dcariotti24@gmail.com> | 2020-03-29 17:03:08 +0200 |
commit | 6188a952974b3e268936beb1027ea58fbfaa67aa (patch) | |
tree | cdb1aa7357ec819ff9031c95266c00662ee1936c /src | |
parent | 84ef988d7e8ae22925b51ea2b3447e471dd38c0c (diff) |
feat: create routes file
Diffstat (limited to 'src')
-rw-r--r-- | src/frest/manage/utils.py | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/frest/manage/utils.py b/src/frest/manage/utils.py index ed07477..f8e76d1 100644 --- a/src/frest/manage/utils.py +++ b/src/frest/manage/utils.py @@ -147,6 +147,8 @@ def create_model_cli(name): with open(modelpath, "w") as f: f.write(modeltext) + return fields + def create_forms(name): with open("templates/form.txt") as f: @@ -157,6 +159,37 @@ def create_forms(name): f.write(formstext) +def create_routes(name, fields): + fields_l = [f"{name}Id"] + fields_l.extend([i["name"] for i in fields]) + fields_l.extend(["created_at", "updated_at"]) + + params_form = "" + for i in fields: + params_form += f"{i['name']}=form.get('{i['name']}'),\n\t\t\t".replace( + "'", '"' + ).replace("\t", " " * 4) + + params_put = "" + for i in fields: + params_put += f"{name[0]}.{i['name']} = form.get('{i['name']}')\n\t\t".replace( + "'", '"' + ).replace("\t", " " * 4) + + with open("templates/routes.txt") as f: + routestext = "".join(f.readlines()) + + routestext = routestext.replace("%%NAME%%", name.capitalize()) + routestext = routestext.replace("%%name%%", name) + routestext = routestext.replace("%%params%%", ",".join(fields_l)) + routestext = routestext.replace("%%first_char%%", name[0]) + routestext = routestext.replace("%%params_form%%", params_form[:-13]) + routestext = routestext.replace("%%params_put%%", params_put[:-9]) + + with open(f"scheme/{name}/routes.py", "w") as f: + f.write(routestext) + + def create_app(name): name = name.lower().replace("-", "_") @@ -181,9 +214,13 @@ def create_app(name): logging("OK", 3, "\n") logging_arg("Create model for {}...\n", name) - create_model_cli(name) + fields = create_model_cli(name) logging("OK", 3, "\n") logging_arg("Create {}... ", f"scheme/{name}/forms.py") create_forms(name) logging("OK", 3, "\n") + + logging_arg("Create {}... ", f"scheme/{name}/routes.py") + create_routes(name, fields) + logging("OK", 3, "\n") |