Skip to content

Commit

Permalink
fix app's path when mgmt cmd creates a component
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdoc authored and adamghill committed Jul 10, 2021
1 parent 9e00358 commit bc55d77
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions django_unicorn/management/commands/startunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.apps import apps

from django_unicorn.components.unicorn_view import (
convert_to_pascal_case,
Expand Down Expand Up @@ -54,22 +55,17 @@ def handle(self, *args, **options):
raise CommandError("At least one component name is required.")

app_name = options["app_name"]
app_directory = base_path / app_name

is_app_directory_correct = input(
f"\nUse '{app_directory}' for the app directory? [Y/n] "
)

if is_app_directory_correct.strip().lower() in ("n", "no"):
return
try:
app_directory = Path(apps.get_app_config(app_name).path)
except LookupError:
# this app does not exist yet
raise CommandError(
f"An app named '{app_name}' does not exist yet. "
"You have to create it first."
)

is_new_app = False
is_first_component = False

if not app_directory.exists():
is_new_app = True
app_directory.mkdir()

(app_directory / "__init__.py").touch(exist_ok=True)

# Create component
Expand Down Expand Up @@ -169,10 +165,3 @@ def handle(self, *args, **options):
"That's a bummer, but I understand. I hope you will star it for me later!"
)
)

if is_new_app:
self.stdout.write(
self.style.WARNING(
f'\nMake sure to add `"{app_name}",` to your INSTALLED_APPS list in your settings file if necessary.'
)
)

0 comments on commit bc55d77

Please sign in to comment.