Merge branch 'develop'

This commit is contained in:
Jannis Leidel 2015-12-17 10:38:29 +01:00
commit 0b4cec538e
15 changed files with 172 additions and 54 deletions

View file

@ -1,20 +1,21 @@
language: python
python:
# - "2.5"
- "2.6"
- "2.7"
before_install:
- export DJANGO_SETTINGS_MODULE=dbtemplates.test_settings
install:
- pip install .
- pip install -e .
- pip install -r requirements/tests.txt Django==$DJANGO
before_script:
- export PIP_USE_MIRRORS=true
- export DJANGO_SETTINGS_MODULE=dbtemplates.test_settings
- flake8 dbtemplates --ignore=E501
script:
- django-admin.py test dbtemplates
- coverage run --branch --source=dbtemplates `which django-admin.py` test dbtemplates
- coverage report --omit="dbtemplates/test*,dbtemplates/migrations*"
env:
- DJANGO=1.3.1
- DJANGO=1.4
- DJANGO=1.3.7
- DJANGO=1.4.5
- DJANGO=1.5.1
branches:
only:
- develop

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
@ -79,6 +80,7 @@ class TemplateAdminForm(forms.ModelForm):
class Meta:
model = Template
fields = ('name', 'content', 'sites', 'creation_date', 'last_changed')
class TemplateAdmin(TemplateModelAdmin):

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

@ -66,7 +66,7 @@ class Loader(BaseLoader):
except (Template.MultipleObjectsReturned, Template.DoesNotExist):
try:
return self.load_and_store_template(template_name, cache_key,
site, sites__in=[])
site, sites__isnull=True)
except (Template.MultipleObjectsReturned, Template.DoesNotExist):
pass

Binary file not shown.

View file

@ -0,0 +1,107 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-07-30 14:03+0600\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
#: admin.py:57
msgid ""
"Leaving this empty causes Django to look for a template with the given name "
"and populate this field with its content."
msgstr "Если вы оставите это поле незаполненным, Django будет искать шаблон с введённым именем и заполнит поле его содержимым."
#: admin.py:92
msgid "Advanced"
msgstr "Дополнительно"
#: admin.py:95
msgid "Date/time"
msgstr "Дата/время"
#: admin.py:112
#, python-format
msgid "Cache of one template successfully invalidated."
msgid_plural "Cache of %(count)d templates successfully invalidated."
msgstr[0] "Кэш для шаблона успешно очищен."
msgstr[1] "Кэш для шаблонов (%(count)d шт.) успешно очищен."
#: admin.py:116
msgid "Invalidate cache of selected templates"
msgstr "Очистить кэш для выделенных шаблонов"
#: admin.py:124
#, python-format
msgid "Cache successfully repopulated with one template."
msgid_plural "Cache successfully repopulated with %(count)d templates."
msgstr[0] "Кэш для шаблона успешно заполнен."
msgstr[1] "Кэш для шаблонов (%(count)d шт.) успешно заполнен."
#: admin.py:128
msgid "Repopulate cache with selected templates"
msgstr "Заполнить кэш для выделенных шаблонов"
#: admin.py:140
#, python-format
msgid "Template syntax check FAILED for %(names)s."
msgid_plural "Template syntax check FAILED for %(count)d templates: %(names)s."
msgstr[0] "Неверный синтаксис у шаблона %(names)s."
msgstr[1] "Неверный синтаксис у следующих шаблонов: %(names)s."
#: admin.py:148
#, python-format
msgid "Template syntax OK."
msgid_plural "Template syntax OK for %(count)d templates."
msgstr[0] "Синтаксис шаблона корректен."
msgstr[1] "Синтаксис шаблонов корректен."
#: admin.py:151
msgid "Check template syntax"
msgstr "Проверить синтаксис шаблона"
#: admin.py:155 models.py:29
msgid "sites"
msgstr "сайты"
#: models.py:26
msgid "name"
msgstr "название"
#: models.py:27
msgid "Example: 'flatpages/default.html'"
msgstr "Например: 'flatpages/default.html'"
#: models.py:28
msgid "content"
msgstr "содержимое"
#: models.py:31
msgid "creation date"
msgstr "дата создания"
#: models.py:33
msgid "last changed"
msgstr "последнее изменение"
#: models.py:41
msgid "template"
msgstr "шаблон"
#: models.py:42
msgid "templates"
msgstr "шаблоны"

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

@ -21,7 +21,6 @@ INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'dbtemplates',
'django_nose',
]
TEMPLATE_LOADERS = (
@ -30,4 +29,4 @@ TEMPLATE_LOADERS = (
'dbtemplates.loader.Loader',
)
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
TEST_RUNNER = 'discover_runner.DiscoverRunner'

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

View file

@ -62,7 +62,7 @@ Short installation howto
4. Set ``DBTEMPLATES_USE_REVERSION`` setting to ``True``
.. _django-reversion: https://github.com/etianen/django-reversion
.. _django-reversion's documentation: https://github.com/etianen/django-reversion/wiki/getting-started
.. _django-reversion's documentation: http://django-reversion.readthedocs.org/en/latest/
.. _commands:

View file

@ -1,6 +1,14 @@
Changelog
=========
v1.3.1 (2012-05-23)
-------------------
* Minor release to move away from nose again and use own
`django-discover-runner`_.
.. _`django-discover-runner`: http://pypi.python.org/pypi/django-discover-runner
v1.3 (2012-05-07)
-----------------

View file

@ -1,3 +1,3 @@
flake8
django-nose
django-discover-runner
coverage

View file

@ -11,7 +11,3 @@ upload-dir = docs/_build/html
[upload_sphinx]
upload-dir = docs/_build/html
[nosetests]
with-coverage=1
cover-package=dbtemplates