Minor cosmetic changes to please flake8.

This commit is contained in:
Jannis Leidel 2013-04-04 11:33:00 +02:00
parent d2f595ce82
commit 4b024de965
6 changed files with 44 additions and 38 deletions

View file

@ -6,8 +6,8 @@ from django.utils.translation import ungettext, ugettext_lazy as _
from django.utils.safestring import mark_safe
from dbtemplates.conf import settings
from dbtemplates.models import (Template,
remove_cached_template, add_template_to_cache)
from dbtemplates.models import (Template, remove_cached_template,
add_template_to_cache)
from dbtemplates.utils.template import check_template_syntax
# Check if django-reversion is installed and use reversions' VersionAdmin
@ -55,14 +55,15 @@ else:
if settings.DBTEMPLATES_AUTO_POPULATE_CONTENT:
content_help_text = _("Leaving this empty causes Django to look for a "
"template with the given name and populate this field with its "
"content.")
"template with the given name and populate this "
"field with its content.")
else:
content_help_text = ""
if settings.DBTEMPLATES_USE_CODEMIRROR and settings.DBTEMPLATES_USE_TINYMCE:
raise ImproperlyConfigured("You may use either CodeMirror or TinyMCE "
"with dbtemplates, not both. Please disable one of them.")
"with dbtemplates, not both. Please disable "
"one of them.")
if settings.DBTEMPLATES_USE_TINYMCE:
from tinymce.widgets import AdminTinyMCE

View file

@ -39,11 +39,13 @@ class DbTemplatesConf(AppConf):
def configure_use_reversion(self, value):
if value and 'reversion' not in settings.INSTALLED_APPS:
raise ImproperlyConfigured("Please add 'reversion' to your "
"INSTALLED_APPS setting to make use of it in dbtemplates.")
"INSTALLED_APPS setting to make "
"use of it in dbtemplates.")
return value
def configure_use_tinymce(self, value):
if value and 'tinymce' not in settings.INSTALLED_APPS:
raise ImproperlyConfigured("Please add 'tinymce' to your "
"INSTALLED_APPS setting to make use of it in dbtemplates.")
"INSTALLED_APPS setting to make "
"use of it in dbtemplates.")
return value

View file

@ -30,7 +30,8 @@ class Command(NoArgsCommand):
help = "Creates the default error templates as database template objects."
option_list = NoArgsCommand.option_list + (
make_option("-f", "--force", action="store_true", dest="force",
default=False, help="overwrite existing database templates"),)
default=False,
help="overwrite existing database templates"),)
def handle_noargs(self, **options):
force = options.get('force')

View file

@ -15,20 +15,25 @@ ALWAYS_ASK, FILES_TO_DATABASE, DATABASE_TO_FILES = ('0', '1', '2')
class Command(NoArgsCommand):
help = "Syncs file system templates with the database bidirectionally."
option_list = NoArgsCommand.option_list + (
make_option("-e", "--ext", dest="ext", action="store", default="html",
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"),
make_option("-o", "--overwrite", action="store", dest="overwrite",
default='0', help="'0' - ask always, '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="look for templates in applications "
"directories before project templates"),
make_option("-d", "--delete", action="store_true", dest="delete",
default=False, help="Delete templates after syncing"))
make_option("-e", "--ext",
dest="ext", action="store", default="html",
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"),
make_option("-o", "--overwrite",
action="store", dest="overwrite", default='0',
help="'0' - ask always, '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="look for templates in applications "
"directories before project templates"),
make_option("-d", "--delete",
action="store_true", dest="delete", default=False,
help="Delete templates after syncing"))
def handle_noargs(self, **options):
extension = options.get('ext')
@ -71,23 +76,21 @@ class Command(NoArgsCommand):
confirm = raw_input(
"\nA '%s' template doesn't exist in the "
"database.\nCreate it with '%s'?"
" (y/[n]): """ % (name, path))
" (y/[n]): """ % (name, path))
if force or confirm.lower().startswith('y'):
t = Template(name=name,
content=codecs.open(path, "r").read())
content=codecs.open(path, "r").read())
t.save()
t.sites.add(site)
else:
while 1:
if overwrite == ALWAYS_ASK:
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__()))
"\n%(template)s exists in the database.\n"
"(1) Overwrite %(template)s with '%(path)s'\n"
"(2) Overwrite '%(path)s' with %(template)s\n"
"Type 1 or 2 or press <Enter> to skip: " %
{'template': t.__repr__(), 'path': path})
else:
confirm = overwrite
if confirm in ('', FILES_TO_DATABASE,
@ -100,8 +103,7 @@ class Command(NoArgsCommand):
try:
os.remove(path)
except OSError:
raise CommandError(
u"Couldn't delete %s" % path)
raise CommandError(u"Couldn't delete %s" % path)
elif confirm == DATABASE_TO_FILES:
f = codecs.open(path, 'w', 'utf-8')
try:

View file

@ -108,16 +108,16 @@ class DbTemplatesTestCase(TestCase):
settings.TEMPLATE_DIRS = (temp_template_dir,)
self.assertFalse(
Template.objects.filter(name='temp_test.html').exists())
call_command('sync_templates',
force=True, verbosity=0, overwrite=FILES_TO_DATABASE)
call_command('sync_templates', force=True,
verbosity=0, overwrite=FILES_TO_DATABASE)
self.assertTrue(
Template.objects.filter(name='temp_test.html').exists())
t = Template.objects.get(name='temp_test.html')
t.content = 'temp test modified'
t.save()
call_command('sync_templates',
force=True, verbosity=0, overwrite=DATABASE_TO_FILES)
call_command('sync_templates', force=True,
verbosity=0, overwrite=DATABASE_TO_FILES)
self.assertTrue(
'modified' in codecs.open(temp_template_path).read())

View file

@ -1,6 +1,6 @@
from django import VERSION
from django.template import (Template, TemplateDoesNotExist,
TemplateSyntaxError)
TemplateSyntaxError)
from django.utils.importlib import import_module