mirror of
https://github.com/jazzband/django-dbtemplates.git
synced 2026-03-16 22:20:28 +00:00
Merge b86752b931 into 10e7de2eda
This commit is contained in:
commit
40267edcc1
1 changed files with 27 additions and 6 deletions
|
|
@ -63,6 +63,23 @@ class Command(BaseCommand):
|
|||
default=False,
|
||||
help="Delete templates after syncing",
|
||||
)
|
||||
group = parser.add_mutually_exclusive_group()
|
||||
group.add_argument(
|
||||
"-y",
|
||||
"--yes",
|
||||
action="store_true",
|
||||
dest="auto_answer",
|
||||
default=None,
|
||||
help="Answer yes to all template creation questions."
|
||||
)
|
||||
group.add_argument(
|
||||
"-n",
|
||||
"--no",
|
||||
action="store_false",
|
||||
dest="auto_answer",
|
||||
default=None,
|
||||
help="Answer no to all template creation questions."
|
||||
)
|
||||
|
||||
def handle(self, **options):
|
||||
extension = options.get("ext")
|
||||
|
|
@ -70,6 +87,7 @@ class Command(BaseCommand):
|
|||
overwrite = options.get("overwrite")
|
||||
app_first = options.get("app_first")
|
||||
delete = options.get("delete")
|
||||
auto_answer = options.get('auto_answer')
|
||||
|
||||
if not extension.startswith("."):
|
||||
extension = f".{extension}"
|
||||
|
|
@ -103,12 +121,15 @@ class Command(BaseCommand):
|
|||
t = Template.on_site.get(name__exact=name)
|
||||
except Template.DoesNotExist:
|
||||
if not force:
|
||||
confirm = input(
|
||||
"\nA '%s' template doesn't exist in the "
|
||||
"database.\nCreate it with '%s'?"
|
||||
" (y/[n]): "
|
||||
"" % (name, path)
|
||||
)
|
||||
if auto_answer is not None:
|
||||
confirm = "y" if auto_answer else "n"
|
||||
else:
|
||||
confirm = input(
|
||||
"\nA '%s' template doesn't exist in the "
|
||||
"database.\nCreate it with '%s'?"
|
||||
" (y/[n]): "
|
||||
"" % (name, path)
|
||||
)
|
||||
if force or confirm.lower().startswith("y"):
|
||||
with open(path, encoding="utf-8") as f:
|
||||
t = Template(name=name, content=f.read())
|
||||
|
|
|
|||
Loading…
Reference in a new issue