Merge branch 'develop' of github.com:jezdez/django-dbtemplates into develop

This commit is contained in:
Jannis Leidel 2010-11-07 00:03:29 +01:00
commit 5f0471e67f

View file

@ -15,11 +15,17 @@ 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"),
make_option("-a", "--app_first", action="store_true", dest="app_first",
default=False, help="if it is used project templates will be loaded after templates in applications directories"),
)
def handle_noargs(self, **options):
extension = options.get('ext')
force = options.get('force')
overwrite = options.get('overwrite')
app_first = options.get('app_first')
if not extension.startswith("."):
extension = ".%s" % extension
@ -33,9 +39,12 @@ class Command(NoArgsCommand):
if not type(settings.TEMPLATE_DIRS) in (tuple, list):
raise CommandError("Please make sure settings.TEMPLATE_DIRS is a "
"list or tuple.")
templatedirs = [d for d in
settings.TEMPLATE_DIRS + app_template_dirs if os.path.isdir(d)]
if app_first:
tpl_dirs = app_template_dirs + settings.TEMPLATE_DIRS
else:
tpl_dirs = settings.TEMPLATE_DIRS + app_template_dirs
templatedirs = [d for d in tpl_dirs if os.path.isdir(d)]
for templatedir in templatedirs:
for dirpath, subdirs, filenames in os.walk(templatedir):
@ -51,21 +60,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()