Skip to content

Commit

Permalink
add gentemplate logs
Browse files Browse the repository at this point in the history
  • Loading branch information
adiletto64 committed Aug 21, 2023
1 parent ce50a58 commit 17033ff
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 67 deletions.
11 changes: 7 additions & 4 deletions hogwarts/magic_templates/gen_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from enum import Enum
from typing import Optional, Type, Union

from rich.console import Console
from jinja2 import Environment
from django.views.generic import DetailView, CreateView
from django.conf import settings
Expand All @@ -19,6 +20,7 @@
TEMPLATES_FOLDER = settings.TEMPLATES[0]["DIRS"][0]
env = Environment("[#", "#]", "[[", "]]")

console = Console()

class ViewType(Enum):
CREATE = "CreateView"
Expand All @@ -38,6 +40,7 @@ class Endpoint:

def gen_templates(app_name: str):
endpoints = get_endpoints(app_name)
console.print(f"generating in templates folder [bold]{TEMPLATES_FOLDER}")

for endpoint in endpoints:
fields = [field.name for field in endpoint.model._meta.fields]
Expand All @@ -49,12 +52,12 @@ def gen_templates(app_name: str):
if endpoint.view_type == ViewType.CREATE:
result = render_template({"model": model_name}, "create")
write_template(endpoint.template_name, result)
print("created template:", endpoint.template_name)
console.print("created template:", endpoint.template_name, style="bright_black")

elif endpoint.view_type == ViewType.UPDATE:
result = render_template({"model": model_name}, "update")
write_template(endpoint.template_name, result)
print("created template:", endpoint.template_name)
console.print("created template:", endpoint.template_name, style="bright_black")

elif endpoint.view_type == ViewType.LIST:
name = endpoint.view.context_object_name
Expand All @@ -71,7 +74,7 @@ def gen_templates(app_name: str):

result = render_template(context_data, "list")
write_template(endpoint.template_name, result)
print("created template:", endpoint.template_name)
console.print("created template:", endpoint.template_name, style="bright_black")

elif endpoint.view_type == ViewType.DETAIL:
name = endpoint.view.context_object_name
Expand All @@ -86,7 +89,7 @@ def gen_templates(app_name: str):

result = render_template(context_data, "detail")
write_template(endpoint.template_name, result)
print("created template:", endpoint.template_name)
console.print("created template:", endpoint.template_name, style="bright_black")


def find_path_name(endpoints: list[Endpoint], model, view_type: ViewType):
Expand Down
5 changes: 1 addition & 4 deletions hogwarts/management/commands/gentemplates.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.core.management.base import BaseCommand

from ...magic_templates.gen_templates import gen_templates

from ...magic_templates.gen_templates import gen_templates

class Command(BaseCommand):
help = "Code generation command"
Expand All @@ -11,7 +11,4 @@ def add_arguments(self, parser):

def handle(self, *args, **options):
app_name: str = options["app"]

gen_templates(app_name)

print("Successfully created")
41 changes: 0 additions & 41 deletions templates/posts/post_list.html

This file was deleted.

18 changes: 0 additions & 18 deletions templates/posts/post_update.html

This file was deleted.

0 comments on commit 17033ff

Please sign in to comment.