mirror of
https://github.com/jazzband/django-dbtemplates.git
synced 2026-05-02 12:44:48 +00:00
add --overwrite option to sync_templates command
This commit is contained in:
parent
8aeaf6f2e6
commit
91bb9e9095
1 changed files with 16 additions and 10 deletions
|
|
@ -15,11 +15,14 @@ class Command(NoArgsCommand):
|
|||
help="extension of the files you want to sync with the database "
|
||||
"[default: %default]"),
|
||||
make_option("-f", "--force", action="store_true", dest="force",
|
||||
default=False, help="overwrite existing database templates")
|
||||
default=False, help="overwrite existing database templates"),
|
||||
make_option("-o", "--overwrite", action="store", dest="overwrite",
|
||||
default='0', help="0 - ask allways, 1 - overwrite database templates from template files, 2 - overwrite template files from database templates"),
|
||||
)
|
||||
def handle_noargs(self, **options):
|
||||
extension = options.get('ext')
|
||||
force = options.get('force')
|
||||
overwrite = options.get('overwrite')
|
||||
|
||||
if not extension.startswith("."):
|
||||
extension = ".%s" % extension
|
||||
|
|
@ -51,21 +54,24 @@ class Command(NoArgsCommand):
|
|||
"\nA '%s' template doesn't exist in the database.\n"
|
||||
"Create it with '%s'?"
|
||||
" (y/[n]): """ % (name, path))
|
||||
if confirm.lower().startswith('y') or force:
|
||||
if force or confirm.lower().startswith('y'):
|
||||
t = Template(name=name,
|
||||
content=open(path, "r").read())
|
||||
t.save()
|
||||
t.sites.add(site)
|
||||
else:
|
||||
while 1:
|
||||
confirm = raw_input(
|
||||
"\n%s exists in the database.\n"
|
||||
"(1) Overwrite %s with '%s'\n"
|
||||
"(2) Overwrite '%s' with %s\n"
|
||||
"Type 1 or 2 or press <Enter> to skip: "
|
||||
% (t.__repr__(),
|
||||
t.__repr__(), path,
|
||||
path, t.__repr__()))
|
||||
if overwrite == '0':
|
||||
confirm = raw_input(
|
||||
"\n%s exists in the database.\n"
|
||||
"(1) Overwrite %s with '%s'\n"
|
||||
"(2) Overwrite '%s' with %s\n"
|
||||
"Type 1 or 2 or press <Enter> to skip: "
|
||||
% (t.__repr__(),
|
||||
t.__repr__(), path,
|
||||
path, t.__repr__()))
|
||||
else:
|
||||
confirm = overwrite
|
||||
if confirm == '' or confirm in ('1', '2'):
|
||||
if confirm == '1':
|
||||
t.content = open(path, 'r').read()
|
||||
|
|
|
|||
Loading…
Reference in a new issue