From 16b425e1f47ee9e0ff84eba1c8adc547752f68a0 Mon Sep 17 00:00:00 2001 From: mrAdiletDev Date: Mon, 21 Aug 2023 22:59:23 +0600 Subject: [PATCH] =?UTF-8?q?add=20custom=20scaffold=20support=20?= =?UTF-8?q?=F0=9F=93=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++ hogwarts/magic_templates/gen_templates.py | 9 ++++- templates/products/product_create.html | 18 --------- templates/products/product_detail.html | 42 --------------------- templates/products/product_list.html | 45 ----------------------- templates/products/product_update.html | 18 --------- 6 files changed, 12 insertions(+), 124 deletions(-) delete mode 100644 templates/products/product_create.html delete mode 100644 templates/products/product_detail.html delete mode 100644 templates/products/product_list.html delete mode 100644 templates/products/product_update.html diff --git a/README.md b/README.md index 9ba293d..b19897e 100644 --- a/README.md +++ b/README.md @@ -52,3 +52,7 @@ Arguments ``` python manage.py gentemplates ``` + +Want to create own scaffolding templates? +1. create folder, copy and customize from [this templates](https://github.com/adiletto64/django-hogwarts/tree/master/hogwarts/scaffold) +2. add that folder to setting `HOGWARTS_SCAFFOLD_FOLDER = ""` diff --git a/hogwarts/magic_templates/gen_templates.py b/hogwarts/magic_templates/gen_templates.py index d1def29..2c0c195 100644 --- a/hogwarts/magic_templates/gen_templates.py +++ b/hogwarts/magic_templates/gen_templates.py @@ -16,12 +16,15 @@ GENERIC_VIEWS = ("CreateView", "UpdateView", "ListView", "DetailView") -SCAFFOLD_FOLDER = os.path.join(apps.get_app_config("hogwarts").path, "scaffold") +CUSTOM_SCAFFOLD_FOLDER = getattr(settings, "HOGWARTS_SCAFFOLD_FOLDER", False) +SCAFFOLD_FOLDER = CUSTOM_SCAFFOLD_FOLDER or os.path.join(apps.get_app_config("hogwarts").path, "scaffold") + TEMPLATES_FOLDER = settings.TEMPLATES[0]["DIRS"][0] env = Environment("[#", "#]", "[[", "]]") console = Console() + class ViewType(Enum): CREATE = "CreateView" UPDATE = "UpdateView" @@ -41,6 +44,10 @@ class Endpoint: def gen_templates(app_name: str): endpoints = get_endpoints(app_name) console.print(f"generating in templates folder [bold]{TEMPLATES_FOLDER}") + if CUSTOM_SCAFFOLD_FOLDER: + console.print(f"using custom scaffold {CUSTOM_SCAFFOLD_FOLDER}", style="yellow") + else: + console.print(f"using default scaffold folder", style="bright_black") for endpoint in endpoints: fields = [field.name for field in endpoint.model._meta.fields] diff --git a/templates/products/product_create.html b/templates/products/product_create.html deleted file mode 100644 index ecc87c0..0000000 --- a/templates/products/product_create.html +++ /dev/null @@ -1,18 +0,0 @@ -{% extends 'base.html' %} - -{% load crispy_forms_tags %} - - -{% block content %} -
-
-
-

Create product

- {% csrf_token %} - {{ form|crispy }} - - -
-
-
-{% endblock %} diff --git a/templates/products/product_detail.html b/templates/products/product_detail.html deleted file mode 100644 index f3d2dff..0000000 --- a/templates/products/product_detail.html +++ /dev/null @@ -1,42 +0,0 @@ -{% extends 'base.html' %} - - -{% block content %} -
- - < back - -

product detail

-
-
- -
id
-
{{ product.id }}
- -
created_at
-
{{ product.created_at }}
- -
name
-
{{ product.name }}
- -
user
-
{{ product.user }}
- -
description
-
{{ product.description }}
- -
cost
-
{{ product.cost }}
- -
category
-
{{ product.category }}
- -
-
- - edit - -
-
-
-{% endblock %} \ No newline at end of file diff --git a/templates/products/product_list.html b/templates/products/product_list.html deleted file mode 100644 index cedbd8d..0000000 --- a/templates/products/product_list.html +++ /dev/null @@ -1,45 +0,0 @@ -{% extends 'base.html' %} - - -{% block content %} -
-
-

products list

- - create - -
- - - - - - - - - - - - - - - - {% for product in products %} - - - - - - - - - - - {% endfor %} - -
idcreated_atnameuserdescriptioncostcategory
{{ product.id }} - {{ product.created_at }} - {{ product.name }}{{ product.user }}{{ product.description }}{{ product.cost }}{{ product.category }}
- -
-{% endblock %} \ No newline at end of file diff --git a/templates/products/product_update.html b/templates/products/product_update.html deleted file mode 100644 index 435e161..0000000 --- a/templates/products/product_update.html +++ /dev/null @@ -1,18 +0,0 @@ -{% extends 'base.html' %} - -{% load crispy_forms_tags %} - - -{% block content %} -
-
-
-

Update product

- {% csrf_token %} - {{ form|crispy }} - - -
-
-
-{% endblock %} \ No newline at end of file