Skip to content

Commit

Permalink
add custom scaffold support đź“‚
Browse files Browse the repository at this point in the history
  • Loading branch information
adiletto64 committed Aug 21, 2023
1 parent 17033ff commit 16b425e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 124 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ Arguments
```
python manage.py gentemplates <your-app-name>
```

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 = "<your-folder>"`
9 changes: 8 additions & 1 deletion hogwarts/magic_templates/gen_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]
Expand Down
18 changes: 0 additions & 18 deletions templates/products/product_create.html

This file was deleted.

42 changes: 0 additions & 42 deletions templates/products/product_detail.html

This file was deleted.

45 changes: 0 additions & 45 deletions templates/products/product_list.html

This file was deleted.

18 changes: 0 additions & 18 deletions templates/products/product_update.html

This file was deleted.

0 comments on commit 16b425e

Please sign in to comment.